use of org.alfresco.rest.api.tests.RepoService.TestSite in project alfresco-remote-api by Alfresco.
the class TestSites method testGetSiteAndListSites.
@Test
public void testGetSiteAndListSites() throws Exception {
Sites sitesProxy = publicApiClient.sites();
// create & get sites (as person 2)
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2Id));
String siteTitle = "site 1 " + System.currentTimeMillis();
Site site = new SiteImpl(siteTitle, SiteVisibility.PRIVATE.toString());
site1 = sitesProxy.createSite(site);
Site ret = sitesProxy.getSite(site1.getSiteId());
site1.expected(ret);
siteTitle = "site 2 " + System.currentTimeMillis();
site = new SiteImpl(siteTitle, SiteVisibility.PUBLIC.toString());
site2 = sitesProxy.createSite(site);
ret = sitesProxy.getSite(site2.getSiteId());
site2.expected(ret);
siteTitle = "site 3 " + System.currentTimeMillis();
site = new SiteImpl(siteTitle, SiteVisibility.MODERATED.toString());
site3 = sitesProxy.createSite(site);
ret = sitesProxy.getSite(site3.getSiteId());
site3.expected(ret);
}
List<TestSite> expectedSites = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<TestSite>>() {
@Override
public List<TestSite> doWork() throws Exception {
List<TestSite> sites = network1.getSites(person1Id);
return sites;
}
}, person1Id, network1.getId());
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
int skipCount = 0;
int maxItems = 2;
Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
ListResponse<Site> resp = sitesProxy.getSites(createParams(paging, null));
checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
{
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1Id));
int skipCount = 2;
int maxItems = Integer.MAX_VALUE;
Paging paging = getPaging(skipCount, maxItems, expectedSites.size(), expectedSites.size());
ListResponse<Site> resp = sitesProxy.getSites(createParams(paging, null));
checkList(expectedSites.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
}
}
use of org.alfresco.rest.api.tests.RepoService.TestSite in project alfresco-remote-api by Alfresco.
the class ProcessWorkflowApiTest method testMNT12382.
@Test
public void testMNT12382() throws Exception {
currentNetwork = getTestFixture().getRandomNetwork();
TestPerson initiator = currentNetwork.getPeople().get(0);
RequestContext requestContext = new RequestContext(currentNetwork.getId(), initiator.getId());
publicApiClient.setRequestContext(requestContext);
ProcessInfo processInfo = startReviewPooledProcess(requestContext);
final List<TestPerson> persons = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<List<TestPerson>>() {
@SuppressWarnings("synthetic-access")
public List<TestPerson> execute() throws Throwable {
ArrayList<TestPerson> persons = new ArrayList<TestPerson>();
persons.add(currentNetwork.createUser(new PersonInfo("Maxim0", "Bobyleu0", "maxim0.bobyleu0", "password", null, "skype", "location", "telephone", "mob", "instant", "google")));
persons.add(currentNetwork.createUser(new PersonInfo("Maxim1", "Bobyleu1", "maxim1.bobyleu1", "password", null, "skype", "location", "telephone", "mob", "instant", "google")));
persons.add(currentNetwork.createUser(new PersonInfo("Maxim2", "Bobyleu2", "maxim2.bobyleu2", "password", null, "skype", "location", "telephone", "mob", "instant", "google")));
return persons;
}
}, false, true);
final MemberOfSite memberOfSite = currentNetwork.getSiteMemberships(initiator.getId()).get(0);
// startReviewPooledProcess() uses initiator's site id and role name for construct bpm_groupAssignee, thus we need appropriate things for created users
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
TestSite initiatorSite = (TestSite) memberOfSite.getSite();
initiatorSite.inviteToSite(persons.get(0).getId(), memberOfSite.getRole());
initiatorSite.inviteToSite(persons.get(1).getId(), memberOfSite.getRole());
// this user wouldn't be in group
initiatorSite.inviteToSite(persons.get(2).getId(), SiteRole.SiteConsumer == memberOfSite.getRole() ? SiteRole.SiteCollaborator : SiteRole.SiteConsumer);
return null;
}
}, AuthenticationUtil.getAdminUserName(), currentNetwork.getId());
return null;
}
}, false, true);
String processId = processInfo.getId();
// getting process items by workflow initiator
ProcessesClient processesClient = publicApiClient.processesClient();
JSONObject initiatorItems = processesClient.findProcessItems(processId);
// getting unclaimed process items by user in group
requestContext = new RequestContext(currentNetwork.getId(), persons.get(0).getId());
publicApiClient.setRequestContext(requestContext);
JSONObject items1 = processesClient.findProcessItems(processId);
assertEquals(initiatorItems.toJSONString(), items1.toJSONString());
// getting unclaimed process items by user not in group
requestContext = new RequestContext(currentNetwork.getId(), persons.get(2).getId());
publicApiClient.setRequestContext(requestContext);
try {
JSONObject items2 = processesClient.findProcessItems(processId);
fail("User not from group should not see items.");
} catch (PublicApiException e) {
// expected
assertEquals(403, e.getHttpResponse().getStatusCode());
}
// claim task
TaskService taskService = activitiProcessEngine.getTaskService();
Task task = taskService.createTaskQuery().processInstanceId(processId).singleResult();
TestPerson assignee = persons.get(1);
taskService.setAssignee(task.getId(), assignee.getId());
// getting claimed process items by assignee
requestContext = new RequestContext(currentNetwork.getId(), assignee.getId());
publicApiClient.setRequestContext(requestContext);
JSONObject items3 = processesClient.findProcessItems(processId);
assertEquals(initiatorItems.toJSONString(), items3.toJSONString());
// getting claimed process items by user in group
requestContext = new RequestContext(currentNetwork.getId(), persons.get(0).getId());
publicApiClient.setRequestContext(requestContext);
try {
JSONObject items4 = processesClient.findProcessItems(processId);
fail("User from group should not see items for claimed task by another user.");
} catch (PublicApiException e) {
// expected
assertEquals(403, e.getHttpResponse().getStatusCode());
} finally {
cleanupProcessInstance(processId);
}
}
Aggregations