Search in sources :

Example 61 with TestNetwork

use of org.alfresco.rest.api.tests.RepoService.TestNetwork in project alfresco-remote-api by Alfresco.

the class TestUserPreferences method testUserPreferences.

@Test
public void testUserPreferences() throws Exception {
    Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
    assertTrue(networksIt.hasNext());
    final TestNetwork network1 = networksIt.next();
    assertTrue(networksIt.hasNext());
    final TestNetwork network2 = networksIt.next();
    final List<TestPerson> people = new ArrayList<TestPerson>(3);
    // create users and some preferences
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            TestPerson person = network1.createUser();
            people.add(person);
            person = network1.createUser();
            people.add(person);
            return null;
        }
    }, network1.getId());
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            TestPerson person = network2.createUser();
            people.add(person);
            return null;
        }
    }, network2.getId());
    final TestPerson person1 = people.get(0);
    final TestPerson person2 = people.get(1);
    final TestPerson person3 = people.get(2);
    final List<Preference> expectedPreferences = new ArrayList<Preference>();
    expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference2", String.valueOf(true)));
    expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference1", String.valueOf(true)));
    expectedPreferences.add(new Preference("org.alfresco.share.documentList.sortAscending", String.valueOf(true)));
    expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference3", String.valueOf(true)));
    // new preference name for issue REPO-855
    expectedPreferences.add(new Preference("org.alfresco.ext.folders.favourites.workspace://SpacesStore/4e3d0779-388a-4b94-91e1-eab588a7da3d.createdAt", String.valueOf(true)));
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            for (Preference pref : expectedPreferences) {
                // TODO add preferences thru api
                repoService.addPreference(person1.getId(), pref.getId(), pref.getValue());
            }
            return null;
        }
    }, person1.getId(), network1.getId());
    Collections.sort(expectedPreferences);
    People peopleProxy = publicApiClient.people();
    // unknown user
    try {
        int skipCount = 0;
        int maxItems = 2;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        peopleProxy.getPreferences(GUID.generate(), createParams(paging, null));
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // test paging
    {
        int skipCount = 0;
        int maxItems = 2;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
        checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    {
        int skipCount = 2;
        int maxItems = 10;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
        checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    // "-me-" user
    {
        int skipCount = 0;
        int maxItems = 2;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        ListResponse<Preference> resp = peopleProxy.getPreferences(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
        checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
    }
    // invalid user - 404
    try {
        int skipCount = 2;
        int maxItems = 10;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        peopleProxy.getPreferences("invalid.user", createParams(paging, null));
        fail("");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // user from another account - 401
    try {
        int skipCount = 0;
        int maxItems = 2;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        // ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
        // checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
        fail();
    } catch (PublicApiException e) {
        assertEquals(e.getHttpResponse().getStatusCode(), HttpStatus.SC_UNAUTHORIZED);
    }
    // another user from the same account - 403
    try {
        int skipCount = 0;
        int maxItems = 2;
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
        Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
        peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
    }
    // get a single preference
    // Test Case: cloud-1493
    {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        Preference pref = expectedPreferences.get(0);
        Preference ret = peopleProxy.getPreference(person1.getId(), pref.getId());
        pref.expected(ret);
    }
    // unknown person id
    try {
        Preference pref = expectedPreferences.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
        peopleProxy.getPreference(GUID.generate(), pref.getId());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // unknown preference id
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.getPreference(person1.getId(), GUID.generate());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // Test case: cloud-1968
    try {
        Preference pref = expectedPreferences.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.create("people", person1.getId(), "preferences", pref.getId(), pref.toJSON().toString(), "Unable to POST to a preference");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        Preference pref = expectedPreferences.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.update("people", person1.getId(), "preferences", pref.getId(), pref.toJSON().toString(), "Unable to PUT a preference");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        Preference pref = expectedPreferences.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.remove("people", person1.getId(), "preferences", pref.getId(), "Unable to DELETE a preference");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        Preference pref = expectedPreferences.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.create("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to POST to preferences");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        Preference pref = expectedPreferences.get(0);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.update("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to PUT preferences");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
        peopleProxy.remove("people", person1.getId(), "preferences", null, "Unable to DELETE preferences");
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
    }
    {
        // REPO-1061, REPO-890
        try {
            String skipCount = "a";
            String maxItems = "hi";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("skipCount", skipCount);
            params.put("maxItems", maxItems);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            peopleProxy.getPreferences(person1.getId(), params);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        try {
            String skipCount = "a";
            String maxItems = "null";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("skipCount", skipCount);
            params.put("maxItems", maxItems);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            peopleProxy.getPreferences(person1.getId(), params);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        try {
            String maxItems = "Red";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("maxItems", maxItems);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            peopleProxy.getPreferences(person1.getId(), params);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        try {
            String skipCount = "yuck";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("skipCount", skipCount);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            peopleProxy.getPreferences(person1.getId(), params);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        try {
            String skipCount = "-1";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("skipCount", skipCount);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            peopleProxy.getPreferences(person1.getId(), params);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
        try {
            String maxItems = "0";
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("maxItems", maxItems);
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
            peopleProxy.getPreferences(person1.getId(), params);
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
        }
    }
}
Also used : ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) People(org.alfresco.rest.api.tests.client.PublicApiClient.People) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) Preference(org.alfresco.rest.api.tests.client.data.Preference) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson) Test(org.junit.Test)

Example 62 with TestNetwork

use of org.alfresco.rest.api.tests.RepoService.TestNetwork in project alfresco-remote-api by Alfresco.

the class EnterpriseWorkflowTestApi method getOtherPersonInNetwork.

protected TestPerson getOtherPersonInNetwork(String usedPerson, String networkId) throws Exception {
    TestNetwork usedNetwork = getTestFixture().getNetwork(networkId);
    for (TestPerson person : usedNetwork.getPeople()) {
        if (!person.getId().equals(usedPerson)) {
            return person;
        }
    }
    fail("Network doesn't have additonal users, cannot perform test");
    return null;
}
Also used : TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) TestPerson(org.alfresco.rest.api.tests.RepoService.TestPerson)

Example 63 with TestNetwork

use of org.alfresco.rest.api.tests.RepoService.TestNetwork in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method testDeleteProcessInstanceById.

@Test
public void testDeleteProcessInstanceById() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    final RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
    TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
    tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
    final RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
    ProcessesClient processesClient = publicApiClient.processesClient();
    // delete with user starting the process instance
    ProcessInfo process = startAdhocProcess(requestContext, null);
    try {
        processesClient.deleteProcessById(process.getId());
        // Check if the process was actually deleted
        assertNull(activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(process.getId()).singleResult());
        HistoricProcessInstance deletedInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(process.getId()).singleResult();
        assertNotNull(deletedInstance);
        assertNotNull(deletedInstance.getEndTime());
        assertEquals("deleted through REST API call", deletedInstance.getDeleteReason());
        try {
            processesClient.deleteProcessById(process.getId());
            fail("expected exeception");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
        }
    } finally {
        cleanupProcessInstance(process.getId());
    }
    // delete with admin in same network as the user starting the process instance
    process = startAdhocProcess(requestContext, null);
    try {
        publicApiClient.setRequestContext(adminContext);
        processesClient.deleteProcessById(process.getId());
        // Check if the process was actually deleted
        assertNull(activitiProcessEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(process.getId()).singleResult());
        HistoricProcessInstance deletedInstance = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(process.getId()).singleResult();
        assertNotNull(deletedInstance);
        assertNotNull(deletedInstance.getEndTime());
        assertEquals("deleted through REST API call", deletedInstance.getDeleteReason());
    } finally {
        cleanupProcessInstance(process.getId());
    }
    // delete with admin from other network as the user starting the process instance
    process = startAdhocProcess(requestContext, null);
    try {
        publicApiClient.setRequestContext(otherContext);
        processesClient.deleteProcessById(process.getId());
        fail("Expect permission exception");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
    } finally {
        cleanupProcessInstance(process.getId());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Example 64 with TestNetwork

use of org.alfresco.rest.api.tests.RepoService.TestNetwork in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method testCreateProcessInstanceFromOtherNetwork.

@Test
@SuppressWarnings("unchecked")
public void testCreateProcessInstanceFromOtherNetwork() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
    TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
    RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
    publicApiClient.setRequestContext(otherContext);
    ProcessesClient processesClient = publicApiClient.processesClient();
    JSONObject createProcessObject = new JSONObject();
    createProcessObject.put("processDefinitionId", processDefinition.getId());
    final JSONObject variablesObject = new JSONObject();
    variablesObject.put("bpm_dueDate", ISO8601DateFormat.format(new Date()));
    variablesObject.put("bpm_priority", 1);
    variablesObject.put("bpm_description", "test description");
    TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            variablesObject.put("bpm_assignee", requestContext.getRunAsUser());
            return null;
        }
    }, requestContext.getRunAsUser(), requestContext.getNetworkId());
    createProcessObject.put("variables", variablesObject);
    try {
        processesClient.createProcess(createProcessObject.toJSONString());
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.BAD_REQUEST.value(), e.getHttpResponse().getStatusCode());
    }
}
Also used : ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) Date(java.util.Date) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 65 with TestNetwork

use of org.alfresco.rest.api.tests.RepoService.TestNetwork in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method testGetProcessActivities.

@Test
public void testGetProcessActivities() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    final RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
    TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
    tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
    final RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
    final ProcessInfo process1 = startAdhocProcess(requestContext, null);
    try {
        ProcessesClient processesClient = publicApiClient.processesClient();
        Map<String, String> paramMap = new HashMap<String, String>();
        JSONObject activitiesJSON = processesClient.getActivities(process1.getId(), paramMap);
        assertNotNull(activitiesJSON);
        JSONArray entriesJSON = (JSONArray) activitiesJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 2);
        Map<String, JSONObject> activitiesMap = new HashMap<String, JSONObject>();
        for (Object entry : entriesJSON) {
            JSONObject jsonEntry = (JSONObject) entry;
            JSONObject activityJSONObject = (JSONObject) jsonEntry.get("entry");
            activitiesMap.put((String) activityJSONObject.get("activityDefinitionId"), activityJSONObject);
        }
        JSONObject activityJSONObject = activitiesMap.get("start");
        assertNotNull(activityJSONObject);
        assertNotNull(activityJSONObject.get("id"));
        assertEquals("start", activityJSONObject.get("activityDefinitionId"));
        assertNull(activityJSONObject.get("activityDefinitionName"));
        assertEquals("startEvent", activityJSONObject.get("activityDefinitionType"));
        assertNotNull(activityJSONObject.get("startedAt"));
        assertNotNull(activityJSONObject.get("endedAt"));
        assertNotNull(activityJSONObject.get("durationInMs"));
        activityJSONObject = activitiesMap.get("adhocTask");
        assertNotNull(activityJSONObject);
        assertNotNull(activityJSONObject.get("id"));
        assertEquals("adhocTask", activityJSONObject.get("activityDefinitionId"));
        assertEquals("Adhoc Task", activityJSONObject.get("activityDefinitionName"));
        assertEquals("userTask", activityJSONObject.get("activityDefinitionType"));
        assertNotNull(activityJSONObject.get("startedAt"));
        assertNull(activityJSONObject.get("endedAt"));
        assertNull(activityJSONObject.get("durationInMs"));
        paramMap = new HashMap<String, String>();
        paramMap.put("status", "active");
        activitiesJSON = processesClient.getActivities(process1.getId(), paramMap);
        assertNotNull(activitiesJSON);
        entriesJSON = (JSONArray) activitiesJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 1);
        paramMap = new HashMap<String, String>();
        paramMap.put("status", "completed");
        activitiesJSON = processesClient.getActivities(process1.getId(), paramMap);
        assertNotNull(activitiesJSON);
        entriesJSON = (JSONArray) activitiesJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 1);
        paramMap = new HashMap<String, String>();
        try {
            processesClient.getActivities("fakeid", paramMap);
            fail("Exception expected");
        } catch (PublicApiException expected) {
            assertEquals(HttpStatus.NOT_FOUND.value(), expected.getHttpResponse().getStatusCode());
            assertErrorSummary("The entity with id: fakeid was not found", expected.getHttpResponse());
        }
        // get activities with admin from the same tenant as the process initiator
        publicApiClient.setRequestContext(adminContext);
        paramMap = new HashMap<String, String>();
        activitiesJSON = processesClient.getActivities(process1.getId(), paramMap);
        assertNotNull(activitiesJSON);
        entriesJSON = (JSONArray) activitiesJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 2);
        // get tasks with admin from another tenant as the process initiator
        publicApiClient.setRequestContext(otherContext);
        paramMap = new HashMap<String, String>();
        try {
            processesClient.getActivities(process1.getId(), paramMap);
            fail("forbidden expected");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
        }
    } finally {
        cleanupProcessInstance(process1.getId());
    }
}
Also used : ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) JSONObject(org.json.simple.JSONObject) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Aggregations

TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)65 Test (org.junit.Test)51 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)50 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)47 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)38 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)33 HashMap (java.util.HashMap)29 NodeRef (org.alfresco.service.cmr.repository.NodeRef)28 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)26 SiteInformation (org.alfresco.rest.api.tests.RepoService.SiteInformation)25 CmisSession (org.alfresco.rest.api.tests.client.PublicApiClient.CmisSession)23 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)22 CmisUpdateConflictException (org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException)22 CmisConstraintException (org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException)21 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)21 CmisPermissionDeniedException (org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException)21 ArrayList (java.util.ArrayList)18 AlfrescoDocument (org.alfresco.cmis.client.AlfrescoDocument)18 AlfrescoFolder (org.alfresco.cmis.client.AlfrescoFolder)15 Document (org.apache.chemistry.opencmis.client.api.Document)15