use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testSortingAndPagingByTitleDesc.
/**
* Tests the capability to sort and paginate the site memberships associated
* to a user orderBy = title DESC skip = 1, count = 2
*
* @throws Exception
*/
public void testSortingAndPagingByTitleDesc() throws Exception {
// paging
int skipCount = 1;
int maxItems = 2;
int totalResults = 3;
Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// get memberships
ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson32(paging, "title", false);
// check results
List<MemberOfSite> expectedList = new LinkedList<>();
expectedList.add(new MemberOfSite(site3, site3_role));
expectedList.add(new MemberOfSite(site2, site2_role));
checkList(expectedList, paging.getExpectedPaging(), resp);
}
use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testSortingAndPagingByTitleAsc.
/**
* Tests the capability to sort and paginate the site memberships associated
* to a user orderBy = title ASC skip = 1, count = 2
*
* @throws Exception
*/
public void testSortingAndPagingByTitleAsc() throws Exception {
// paging
int skipCount = 1;
int maxItems = 2;
int totalResults = 3;
Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// get memberships
ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson32(paging, "title", true);
// check results
List<MemberOfSite> expectedList = new LinkedList<>();
expectedList.add(new MemberOfSite(site3, site3_role));
expectedList.add(new MemberOfSite(site1, site1_role));
checkList(expectedList, paging.getExpectedPaging(), resp);
}
use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TestPersonSites method testSortingAndPagingByRoleAsc.
/**
* Tests the capability to sort and paginate the site memberships associated
* to a user orderBy = role ASC skip = 1, count = 2
*
* @throws Exception
*/
public void testSortingAndPagingByRoleAsc() throws Exception {
// paging
int skipCount = 1;
int maxItems = 2;
int totalResults = 3;
Paging paging = getPaging(skipCount, maxItems, totalResults, totalResults);
// get memberships
ListResponse<MemberOfSite> resp = getSiteMembershipsForPerson32(paging, "role", true);
// check results
List<MemberOfSite> expectedList = new LinkedList<>();
expectedList.add(new MemberOfSite(site1, site1_role));
expectedList.add(new MemberOfSite(site2, site2_role));
checkList(expectedList, paging.getExpectedPaging(), resp);
}
use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TestPersonSites method getPersonSites.
private List<MemberOfSite> getPersonSites(TestPerson person, TestSite... sites) throws PublicApiException {
Sites sitesProxy = publicApiClient.sites();
List<MemberOfSite> memberOfSiteList = new ArrayList<>();
for (TestSite site : sites) {
memberOfSiteList.add(sitesProxy.getPersonSite(person.getId(), site.getSiteId()));
}
return memberOfSiteList;
}
use of org.alfresco.rest.api.tests.client.data.MemberOfSite in project alfresco-remote-api by Alfresco.
the class TaskWorkflowApiTest method testDeleteTaskItem.
@Test
@SuppressWarnings("unchecked")
public void testDeleteTaskItem() throws Exception {
final RequestContext requestContext = initApiClientWithTestUser();
String otherPerson = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId()).getId();
RequestContext otherContext = new RequestContext(requestContext.getNetworkId(), otherPerson);
String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
// Create test-document and add to package
NodeRef[] docNodeRefs = createTestDocuments(requestContext);
ProcessInfo processInfo = startAdhocProcess(requestContext, docNodeRefs);
final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInfo.getId()).singleResult();
assertNotNull(task);
activitiProcessEngine.getTaskService().setAssignee(task.getId(), null);
try {
TasksClient tasksClient = publicApiClient.tasksClient();
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item as admin
JSONObject createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
JSONObject result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
JSONObject itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
publicApiClient.setRequestContext(adminContext);
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item with candidate user
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
activitiProcessEngine.getTaskService().addCandidateUser(task.getId(), otherPerson);
publicApiClient.setRequestContext(otherContext);
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item with not involved user
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
activitiProcessEngine.getTaskService().deleteCandidateUser(task.getId(), otherPerson);
publicApiClient.setRequestContext(otherContext);
try {
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(403, e.getHttpResponse().getStatusCode());
}
// delete item with user from candidate group with no assignee
List<MemberOfSite> memberships = getTestFixture().getNetwork(otherContext.getNetworkId()).getSiteMemberships(otherContext.getRunAsUser());
assertTrue(memberships.size() > 0);
MemberOfSite memberOfSite = memberships.get(0);
String group = "GROUP_site_" + memberOfSite.getSiteId() + "_" + memberOfSite.getRole().name();
activitiProcessEngine.getTaskService().deleteCandidateUser(task.getId(), otherContext.getRunAsUser());
activitiProcessEngine.getTaskService().addCandidateGroup(task.getId(), group);
publicApiClient.setRequestContext(otherContext);
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item with user from candidate group with assignee
activitiProcessEngine.getTaskService().setAssignee(task.getId(), requestContext.getRunAsUser());
publicApiClient.setRequestContext(requestContext);
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
publicApiClient.setRequestContext(otherContext);
try {
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(403, e.getHttpResponse().getStatusCode());
}
publicApiClient.setRequestContext(requestContext);
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
try {
tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// invalid task id
publicApiClient.setRequestContext(requestContext);
try {
tasksClient.deleteTaskItem("fakeid", docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// invalid item id
try {
tasksClient.deleteTaskItem(task.getId(), "fakeid");
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
// delete item from completed task
createItemObject = new JSONObject();
createItemObject.put("id", docNodeRefs[0].getId());
result = tasksClient.addTaskItem(task.getId(), createItemObject.toJSONString());
assertNotNull(result);
assertEquals(docNodeRefs[0].getId(), result.get("id"));
itemJSON = tasksClient.findTaskItem(task.getId(), docNodeRefs[0].getId());
assertEquals(docNodeRefs[0].getId(), itemJSON.get("id"));
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
activitiProcessEngine.getTaskService().complete(task.getId());
return null;
}
}, requestContext.getRunAsUser(), requestContext.getNetworkId());
try {
tasksClient.deleteTaskItem(task.getId(), docNodeRefs[0].getId());
fail("Expected exception");
} catch (PublicApiException e) {
assertEquals(404, e.getHttpResponse().getStatusCode());
}
} finally {
cleanupProcessInstance(processInfo.getId());
}
}
Aggregations