mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Activating disabled tests
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@50279 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -28,12 +28,13 @@ import org.alfresco.module.org_alfresco_module_rm.test.webscript.EventRestApiTes
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RMCaveatConfigScriptTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RMConstraintScriptTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RmChildrenRestApiTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RmClassesRestApiTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RmPropertiesRestApiTest;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RoleRestApiTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
|
||||
/**
|
||||
* RM WebScript test suite
|
||||
*
|
||||
@@ -53,8 +54,8 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
EmailMapKeysRestApiTest.class,
|
||||
CapabilitiesRestApiTest.class,
|
||||
ActionDefinitionsRestApiTest.class,
|
||||
//RmClassesRestApiTest.class,
|
||||
//RmPropertiesRestApiTest.class,
|
||||
RmClassesRestApiTest.class,
|
||||
RmPropertiesRestApiTest.class,
|
||||
RmChildrenRestApiTest.class
|
||||
})
|
||||
public class WebScriptTestSuite
|
||||
|
@@ -39,168 +39,168 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
|
||||
/**
|
||||
* This class tests the Rest API for disposition related operations
|
||||
*
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class RoleRestApiTest extends BaseRMWebScriptTestCase
|
||||
public class RoleRestApiTest extends BaseRMWebScriptTestCase
|
||||
implements RecordsManagementModel
|
||||
{
|
||||
protected static final String GET_ROLES_URL_BY_SITE = "/api/rma/admin/{0}/rmroles";
|
||||
protected static final String GET_ROLES_URL_BY_FILEPLAN = "/api/rma/admin/{0}/{1}/{2}/rmroles";
|
||||
protected static final String SERVICE_URL_PREFIX = "/alfresco/service";
|
||||
protected static final String APPLICATION_JSON = "application/json";
|
||||
|
||||
protected static final String APPLICATION_JSON = "application/json";
|
||||
|
||||
private String getRolesUrlBySite()
|
||||
{
|
||||
return MessageFormat.format(GET_ROLES_URL_BY_SITE, SITE_ID);
|
||||
}
|
||||
|
||||
|
||||
private String getRoleUrlByFilePlan()
|
||||
{
|
||||
return MessageFormat.format(GET_ROLES_URL_BY_FILEPLAN, filePlan.getStoreRef().getProtocol(), filePlan.getStoreRef().getIdentifier(), filePlan.getId());
|
||||
return MessageFormat.format(GET_ROLES_URL_BY_FILEPLAN, filePlan.getStoreRef().getProtocol(), filePlan.getStoreRef().getIdentifier(), filePlan.getId());
|
||||
}
|
||||
|
||||
public void testGetRoles() throws Exception
|
||||
{
|
||||
String role1 = GUID.generate();
|
||||
String role2 = GUID.generate();
|
||||
|
||||
|
||||
// Create a couple or roles by hand
|
||||
filePlanRoleService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5));
|
||||
filePlanRoleService.createRole(filePlan, role2, "My Test Role Too", getListOfCapabilities(5));
|
||||
|
||||
|
||||
// create test group
|
||||
String groupName = GUID.generate();
|
||||
String group = authorityService.createAuthority(AuthorityType.GROUP, groupName, "monkey", null);
|
||||
|
||||
String group = authorityService.createAuthority(AuthorityType.GROUP, groupName, "monkey", null);
|
||||
|
||||
// Add the admin user to one of the roles
|
||||
filePlanRoleService.assignRoleToAuthority(filePlan, role1, "admin");
|
||||
filePlanRoleService.assignRoleToAuthority(filePlan, role1, group);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// Get the roles (for the default file plan)
|
||||
Response rsp = sendRequest(new GetRequest(getRolesUrlBySite()),200);
|
||||
String rspContent = rsp.getContentAsString();
|
||||
|
||||
|
||||
JSONObject obj = new JSONObject(rspContent);
|
||||
JSONObject roles = obj.getJSONObject("data");
|
||||
assertNotNull(roles);
|
||||
|
||||
|
||||
JSONObject roleObj = roles.getJSONObject(role1);
|
||||
assertNotNull(roleObj);
|
||||
assertEquals(role1, roleObj.get("name"));
|
||||
assertEquals("My Test Role", roleObj.get("displayLabel"));
|
||||
checkCapabilities(roleObj, 5);
|
||||
|
||||
|
||||
roleObj = roles.getJSONObject(role2);
|
||||
assertNotNull(roleObj);
|
||||
assertEquals(role2, roleObj.get("name"));
|
||||
assertEquals("My Test Role Too", roleObj.get("displayLabel"));
|
||||
checkCapabilities(roleObj, 5);
|
||||
|
||||
checkCapabilities(roleObj, 5);
|
||||
|
||||
// Get the roles, specifying the file plan
|
||||
rsp = sendRequest(new GetRequest(getRoleUrlByFilePlan()),200);
|
||||
rspContent = rsp.getContentAsString();
|
||||
|
||||
|
||||
obj = new JSONObject(rspContent);
|
||||
roles = obj.getJSONObject("data");
|
||||
assertNotNull(roles);
|
||||
|
||||
|
||||
roleObj = roles.getJSONObject(role1);
|
||||
assertNotNull(roleObj);
|
||||
assertEquals(role1, roleObj.get("name"));
|
||||
assertEquals("My Test Role", roleObj.get("displayLabel"));
|
||||
checkCapabilities(roleObj, 5);
|
||||
|
||||
|
||||
roleObj = roles.getJSONObject(role2);
|
||||
assertNotNull(roleObj);
|
||||
assertEquals(role2, roleObj.get("name"));
|
||||
assertEquals("My Test Role Too", roleObj.get("displayLabel"));
|
||||
checkCapabilities(roleObj, 5);
|
||||
|
||||
checkCapabilities(roleObj, 5);
|
||||
|
||||
// Get the roles for "admin"
|
||||
rsp = sendRequest(new GetRequest(getRolesUrlBySite() + "?user=admin"),200);
|
||||
rspContent = rsp.getContentAsString();
|
||||
|
||||
|
||||
obj = new JSONObject(rspContent);
|
||||
roles = obj.getJSONObject("data");
|
||||
assertNotNull(roles);
|
||||
|
||||
|
||||
roleObj = roles.getJSONObject(role1);
|
||||
assertNotNull(roleObj);
|
||||
assertEquals(role1, roleObj.get("name"));
|
||||
assertEquals("My Test Role", roleObj.get("displayLabel"));
|
||||
checkCapabilities(roleObj, 5);
|
||||
|
||||
|
||||
assertFalse(roles.has(role2));
|
||||
|
||||
|
||||
// Get the roles including assigned authorities
|
||||
rsp = sendRequest(new GetRequest(getRoleUrlByFilePlan() + "?auths=true"),200);
|
||||
rspContent = rsp.getContentAsString();
|
||||
|
||||
|
||||
System.out.println(rspContent);
|
||||
|
||||
|
||||
obj = new JSONObject(rspContent);
|
||||
roles = obj.getJSONObject("data");
|
||||
assertNotNull(roles);
|
||||
|
||||
|
||||
roleObj = roles.getJSONObject(role1);
|
||||
assertNotNull(roleObj);
|
||||
assertEquals(role1, roleObj.get("name"));
|
||||
assertEquals("My Test Role", roleObj.get("displayLabel"));
|
||||
checkCapabilities(roleObj, 5);
|
||||
|
||||
|
||||
JSONArray users = roleObj.getJSONArray("assignedUsers");
|
||||
assertNotNull(users);
|
||||
assertEquals(1, users.length());
|
||||
|
||||
|
||||
JSONArray groups = roleObj.getJSONArray("assignedGroups");
|
||||
assertNotNull(groups);
|
||||
assertEquals(1, groups.length());
|
||||
|
||||
assertEquals(1, groups.length());
|
||||
|
||||
roleObj = roles.getJSONObject(role2);
|
||||
assertNotNull(roleObj);
|
||||
assertEquals(role2, roleObj.get("name"));
|
||||
assertEquals("My Test Role Too", roleObj.get("displayLabel"));
|
||||
checkCapabilities(roleObj, 5);
|
||||
|
||||
checkCapabilities(roleObj, 5);
|
||||
|
||||
users = roleObj.getJSONArray("assignedUsers");
|
||||
assertNotNull(users);
|
||||
assertEquals(0, users.length());
|
||||
|
||||
|
||||
groups = roleObj.getJSONArray("assignedGroups");
|
||||
assertNotNull(groups);
|
||||
assertEquals(0, groups.length());
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Clean up
|
||||
// Clean up
|
||||
filePlanRoleService.deleteRole(filePlan, role1);
|
||||
filePlanRoleService.deleteRole(filePlan, role2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void checkCapabilities(JSONObject role, int expectedCount) throws JSONException
|
||||
{
|
||||
JSONObject capabilities = role.getJSONObject("capabilities");
|
||||
assertNotNull(capabilities);
|
||||
|
||||
|
||||
int count = 0;
|
||||
Iterator it = capabilities.keys();
|
||||
Iterator<String> it = capabilities.keys();
|
||||
while (it.hasNext())
|
||||
{
|
||||
String key = (String)it.next();
|
||||
String key = it.next();
|
||||
assertNotNull(key);
|
||||
assertNotNull(capabilities.getString(key));
|
||||
count ++;
|
||||
count ++;
|
||||
}
|
||||
|
||||
assertEquals(expectedCount, count);
|
||||
|
||||
assertEquals(expectedCount, count);
|
||||
}
|
||||
|
||||
|
||||
public void testPostRoles() throws Exception
|
||||
{
|
||||
Set<Capability> caps = getListOfCapabilities(5);
|
||||
@@ -209,23 +209,23 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
|
||||
{
|
||||
arrCaps.put(cap.getName());
|
||||
}
|
||||
|
||||
|
||||
String roleName = GUID.generate();
|
||||
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("name", roleName);
|
||||
obj.put("displayLabel", "Display Label");
|
||||
obj.put("capabilities", arrCaps);
|
||||
|
||||
|
||||
Response rsp = sendRequest(new PostRequest(getRolesUrlBySite(), obj.toString(), APPLICATION_JSON),200);
|
||||
try
|
||||
{
|
||||
String rspContent = rsp.getContentAsString();
|
||||
|
||||
|
||||
JSONObject resultObj = new JSONObject(rspContent);
|
||||
JSONObject roleObj = resultObj.getJSONObject("data");
|
||||
assertNotNull(roleObj);
|
||||
|
||||
|
||||
assertNotNull(roleObj);
|
||||
assertEquals(roleName, roleObj.get("name"));
|
||||
assertEquals("Display Label", roleObj.get("displayLabel"));
|
||||
@@ -235,14 +235,14 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
|
||||
{
|
||||
filePlanRoleService.deleteRole(filePlan, roleName);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testPutRole() throws Exception
|
||||
{
|
||||
String role1 = GUID.generate();
|
||||
String role1 = GUID.generate();
|
||||
filePlanRoleService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5));
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Set<Capability> caps = getListOfCapabilities(4,8);
|
||||
@@ -252,85 +252,85 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
|
||||
System.out.println(cap.getName());
|
||||
arrCaps.put(cap.getName());
|
||||
}
|
||||
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("name", role1);
|
||||
obj.put("displayLabel", "Changed");
|
||||
obj.put("capabilities", arrCaps);
|
||||
|
||||
|
||||
// Get the roles
|
||||
Response rsp = sendRequest(new PutRequest(getRolesUrlBySite() + "/" + role1, obj.toString(), APPLICATION_JSON),200);
|
||||
String rspContent = rsp.getContentAsString();
|
||||
|
||||
|
||||
JSONObject result = new JSONObject(rspContent);
|
||||
JSONObject roleObj = result.getJSONObject("data");
|
||||
assertNotNull(roleObj);
|
||||
|
||||
|
||||
assertNotNull(roleObj);
|
||||
assertEquals(role1, roleObj.get("name"));
|
||||
assertEquals("Changed", roleObj.get("displayLabel"));
|
||||
checkCapabilities(roleObj, 4);
|
||||
|
||||
checkCapabilities(roleObj, 4);
|
||||
|
||||
// Bad requests
|
||||
sendRequest(new PutRequest(getRolesUrlBySite() + "/cheese", obj.toString(), APPLICATION_JSON), 404);
|
||||
sendRequest(new PutRequest(getRolesUrlBySite() + "/cheese", obj.toString(), APPLICATION_JSON), 404);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Clean up
|
||||
// Clean up
|
||||
filePlanRoleService.deleteRole(filePlan, role1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testGetRole() throws Exception
|
||||
{
|
||||
String role1 = GUID.generate();
|
||||
String role1 = GUID.generate();
|
||||
filePlanRoleService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5));
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// Get the roles
|
||||
Response rsp = sendRequest(new GetRequest(getRolesUrlBySite() + "/" + role1),200);
|
||||
String rspContent = rsp.getContentAsString();
|
||||
|
||||
|
||||
JSONObject obj = new JSONObject(rspContent);
|
||||
JSONObject roleObj = obj.getJSONObject("data");
|
||||
assertNotNull(roleObj);
|
||||
|
||||
|
||||
assertNotNull(roleObj);
|
||||
assertEquals(role1, roleObj.get("name"));
|
||||
assertEquals("My Test Role", roleObj.get("displayLabel"));
|
||||
checkCapabilities(roleObj, 5);
|
||||
|
||||
checkCapabilities(roleObj, 5);
|
||||
|
||||
// Bad requests
|
||||
sendRequest(new GetRequest(getRolesUrlBySite() + "/cheese"), 404);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Clean up
|
||||
// Clean up
|
||||
filePlanRoleService.deleteRole(filePlan, role1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testDeleteRole() throws Exception
|
||||
{
|
||||
String role1 = GUID.generate();
|
||||
assertFalse(filePlanRoleService.existsRole(filePlan, role1));
|
||||
filePlanRoleService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5));
|
||||
assertTrue(filePlanRoleService.existsRole(filePlan, role1));
|
||||
sendRequest(new DeleteRequest(getRolesUrlBySite() + "/" + role1),200);
|
||||
assertFalse(filePlanRoleService.existsRole(filePlan, role1));
|
||||
|
||||
assertFalse(filePlanRoleService.existsRole(filePlan, role1));
|
||||
filePlanRoleService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5));
|
||||
assertTrue(filePlanRoleService.existsRole(filePlan, role1));
|
||||
sendRequest(new DeleteRequest(getRolesUrlBySite() + "/" + role1),200);
|
||||
assertFalse(filePlanRoleService.existsRole(filePlan, role1));
|
||||
|
||||
// Bad request
|
||||
sendRequest(new DeleteRequest(getRolesUrlBySite() + "/cheese"), 404);
|
||||
sendRequest(new DeleteRequest(getRolesUrlBySite() + "/cheese"), 404);
|
||||
}
|
||||
|
||||
|
||||
private Set<Capability> getListOfCapabilities(int size)
|
||||
{
|
||||
return getListOfCapabilities(size, 0);
|
||||
}
|
||||
|
||||
|
||||
private Set<Capability> getListOfCapabilities(int size, int offset)
|
||||
{
|
||||
Set<Capability> result = new HashSet<Capability>(size);
|
||||
@@ -353,5 +353,5 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user