Search in sources :

Example 21 with TestNetwork

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

the class ProcessDefinitionWorkflowApiTest method testAuthenticationAndAuthorization.

@Test
public void testAuthenticationAndAuthorization() throws Exception {
    // Fetching process definitions as admin should be possible
    RequestContext requestContext = initApiClientWithTestUser();
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    publicApiClient.setRequestContext(new RequestContext(requestContext.getNetworkId(), tenantAdmin));
    ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
    ListResponse<ProcessDefinition> processDefinitionsResponse = processDefinitionsClient.getProcessDefinitions(null);
    Map<String, ProcessDefinition> processDefinitionMap = getProcessDefinitionMapByKey(processDefinitionsResponse.getList());
    assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
    assertTrue(processDefinitionMap.containsKey("activitiReview"));
    assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
    assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
    assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
    assertEquals(5, processDefinitionMap.size());
    // Fetching process definitions as admin from another tenant shouldn't be possible
    TestNetwork anotherNetwork = getOtherNetwork(requestContext.getNetworkId());
    tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + anotherNetwork.getId();
    RequestContext otherContext = new RequestContext(anotherNetwork.getId(), tenantAdmin);
    publicApiClient.setRequestContext(otherContext);
    processDefinitionsResponse = processDefinitionsClient.getProcessDefinitions(null);
    processDefinitionMap = getProcessDefinitionMapByKey(processDefinitionsResponse.getList());
    // the response should contain process definitions from the new tenant
    assertTrue(processDefinitionMap.containsKey("activitiReviewPooled"));
    assertTrue(processDefinitionMap.containsKey("activitiReview"));
    assertTrue(processDefinitionMap.containsKey("activitiParallelGroupReview"));
    assertTrue(processDefinitionMap.containsKey("activitiParallelReview"));
    assertTrue(processDefinitionMap.containsKey("activitiAdhoc"));
    assertEquals(5, processDefinitionMap.size());
    // Fetching a specific process definitions as admin should be possible
    publicApiClient.setRequestContext(requestContext);
    String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
    org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
    assertNotNull(activitiDefinition);
    // Get a single process definitions
    ProcessDefinition adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
    assertNotNull(adhocDefinition);
    // Check fields of a resulting process-definition
    assertEquals(activitiDefinition.getId(), adhocDefinition.getId());
    assertEquals("activitiAdhoc", adhocDefinition.getKey());
    assertEquals(activitiDefinition.getDeploymentId(), adhocDefinition.getDeploymentId());
    assertEquals(activitiDefinition.getCategory(), adhocDefinition.getCategory());
    assertEquals(activitiDefinition.getName(), adhocDefinition.getName());
    assertEquals(activitiDefinition.getVersion(), adhocDefinition.getVersion());
    assertEquals(((ProcessDefinitionEntity) activitiDefinition).isGraphicalNotationDefined(), adhocDefinition.isGraphicNotationDefined());
    assertEquals("wf:submitAdhocTask", adhocDefinition.getStartFormResourceKey());
    // Fetching a specific process definitions as admin from another tenant should not be possible
    publicApiClient.setRequestContext(otherContext);
    try {
        adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
        fail("not found expected");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
    }
    // Fetching the start form model of a process definition as admin should be possible
    publicApiClient.setRequestContext(requestContext);
    JSONObject model = processDefinitionsClient.findStartFormModel(activitiDefinition.getId());
    assertNotNull(model);
    JSONArray entries = (JSONArray) model.get("entries");
    assertNotNull(entries);
    // Add all entries to a map, to make lookup easier
    Map<String, JSONObject> modelFieldsByName = new HashMap<String, JSONObject>();
    JSONObject entry = null;
    for (int i = 0; i < entries.size(); i++) {
        entry = (JSONObject) entries.get(i);
        assertNotNull(entry);
        entry = (JSONObject) entry.get("entry");
        assertNotNull(entry);
        modelFieldsByName.put((String) entry.get("name"), entry);
    }
    // Check well-known properties and their types
    // Validate bpm:description
    JSONObject modelEntry = modelFieldsByName.get("bpm_workflowDescription");
    assertNotNull(modelEntry);
    assertEquals("Description", modelEntry.get("title"));
    assertEquals("{http://www.alfresco.org/model/bpm/1.0}workflowDescription", modelEntry.get("qualifiedName"));
    assertEquals("d:text", modelEntry.get("dataType"));
    assertFalse((Boolean) modelEntry.get("required"));
    // Fetching a specific process definitions as admin from another tenant should not be possible
    publicApiClient.setRequestContext(otherContext);
    try {
        model = processDefinitionsClient.findStartFormModel(activitiDefinition.getId());
        fail("not found expected");
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
    }
}
Also used : HashMap(java.util.HashMap) JSONArray(org.json.simple.JSONArray) ProcessDefinition(org.alfresco.rest.workflow.api.model.ProcessDefinition) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessDefinitionsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient) 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 22 with TestNetwork

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

the class ProcessWorkflowApiTest method testGetProcessVariables.

@Test
public void testGetProcessVariables() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    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);
    ProcessInfo processRest = startAdhocProcess(requestContext, null);
    try {
        assertNotNull(processRest);
        String processInstanceId = processRest.getId();
        JSONObject processvariables = publicApiClient.processesClient().getProcessvariables(processInstanceId);
        assertNotNull(processvariables);
        validateVariablesResponse(processvariables, requestContext.getRunAsUser());
        // get variables with admin from same network
        publicApiClient.setRequestContext(adminContext);
        processvariables = publicApiClient.processesClient().getProcessvariables(processInstanceId);
        assertNotNull(processvariables);
        validateVariablesResponse(processvariables, requestContext.getRunAsUser());
        // get variables with admin from other network
        publicApiClient.setRequestContext(otherContext);
        try {
            processvariables = publicApiClient.processesClient().getProcessvariables(processInstanceId);
            fail("forbidden expected");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
        }
        // get variables with non existing process id
        try {
            processvariables = publicApiClient.processesClient().getProcessvariables("fakeid");
            fail("not found expected");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.NOT_FOUND.value(), e.getHttpResponse().getStatusCode());
        }
    } finally {
        cleanupProcessInstance(processRest.getId());
    }
}
Also used : 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) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Example 23 with TestNetwork

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

the class ProcessWorkflowApiTest method testGetProcessTasks.

@Test
public void testGetProcessTasks() 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);
    String otherPerson = getOtherPersonInNetwork(requestContext.getRunAsUser(), requestContext.getNetworkId()).getId();
    RequestContext otherPersonContext = new RequestContext(requestContext.getNetworkId(), otherPerson);
    final ProcessInfo process1 = startAdhocProcess(requestContext, null);
    try {
        ProcessesClient processesClient = publicApiClient.processesClient();
        Map<String, String> paramMap = new HashMap<String, String>();
        JSONObject tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        JSONArray entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 1);
        JSONObject taskJSONObject = (JSONObject) ((JSONObject) entriesJSON.get(0)).get("entry");
        assertNotNull(taskJSONObject.get("id"));
        assertEquals(process1.getId(), taskJSONObject.get("processId"));
        assertEquals(process1.getProcessDefinitionId(), taskJSONObject.get("processDefinitionId"));
        assertEquals("adhocTask", taskJSONObject.get("activityDefinitionId"));
        assertEquals("Adhoc Task", taskJSONObject.get("name"));
        assertEquals(requestContext.getRunAsUser(), taskJSONObject.get("assignee"));
        assertEquals(2l, taskJSONObject.get("priority"));
        assertEquals("wf:adhocTask", taskJSONObject.get("formResourceKey"));
        assertNull(taskJSONObject.get("endedAt"));
        assertNull(taskJSONObject.get("durationInMs"));
        paramMap = new HashMap<String, String>();
        paramMap.put("status", "active");
        tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 1);
        paramMap = new HashMap<String, String>();
        paramMap.put("status", "completed");
        tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 0);
        paramMap = new HashMap<String, String>();
        try {
            processesClient.getTasks("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 tasks with admin from the same tenant as the process initiator
        publicApiClient.setRequestContext(adminContext);
        paramMap = new HashMap<String, String>();
        tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 1);
        // get tasks with admin from another tenant as the process initiator
        publicApiClient.setRequestContext(otherContext);
        paramMap = new HashMap<String, String>();
        try {
            tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
            fail("forbidden expected");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
        }
        // get task with other not-involved person
        publicApiClient.setRequestContext(otherPersonContext);
        paramMap = new HashMap<String, String>();
        try {
            tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
            fail("forbidden expected");
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.FORBIDDEN.value(), e.getHttpResponse().getStatusCode());
        }
        // involve other person and get task
        final Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(process1.getId()).singleResult();
        activitiProcessEngine.getTaskService().addCandidateUser(task.getId(), otherPersonContext.getRunAsUser());
        publicApiClient.setRequestContext(otherPersonContext);
        paramMap = new HashMap<String, String>();
        tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 1);
        // complete task and get tasks
        TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {

            @Override
            public Void doWork() throws Exception {
                activitiProcessEngine.getTaskService().complete(task.getId());
                return null;
            }
        }, requestContext.getRunAsUser(), requestContext.getNetworkId());
        publicApiClient.setRequestContext(requestContext);
        paramMap = new HashMap<String, String>();
        paramMap.put("status", "any");
        tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 2);
        publicApiClient.setRequestContext(otherPersonContext);
        paramMap = new HashMap<String, String>();
        paramMap.put("status", "any");
        tasksJSON = processesClient.getTasks(process1.getId(), paramMap);
        assertNotNull(tasksJSON);
        entriesJSON = (JSONArray) tasksJSON.get("entries");
        assertNotNull(entriesJSON);
        assertTrue(entriesJSON.size() == 2);
    } finally {
        cleanupProcessInstance(process1.getId());
    }
}
Also used : ProcessesClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessesClient) Task(org.activiti.engine.task.Task) 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) 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 24 with TestNetwork

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

the class EnterpriseTestFixture method populateTestData.

@Override
protected void populateTestData() {
    for (int i = 1; i <= 2; i++) {
        TestNetwork network = repoService.createNetworkWithAlias(TEST_DOMAIN_PREFIX + "00" + i, true);
        addNetwork(network);
    }
    // 5 public sites
    for (int i = 0; i < 5; i++) {
        SiteInformation siteInfo = new SiteInformation("testSite" + i, "Public Test Site" + i, "Public Test Site" + i, SiteVisibility.PUBLIC);
        addSite(siteInfo);
    }
    // 5 private sites
    for (int i = 5; i < 10; i++) {
        SiteInformation siteInfo = new SiteInformation("testSite" + i, "Private Test Site" + i, "Private Test Site" + i, SiteVisibility.PRIVATE);
        addSite(siteInfo);
    }
    addPerson(new PersonInfo("David", "Smith", "david.smith", "password", null, "skype", "location", "telephone", "mob", "instant", "google"));
    addPerson(new PersonInfo("Bob", "Jones", "bob.jones", "password", null, "skype", "location", "telephone", "mob", "instant", "google"));
    addPerson(new PersonInfo("Bill", "Grainger", "bill.grainger", "password", null, "skype", "location", "telephone", "mob", WITH_AVATAR, "google"));
    addPerson(new PersonInfo("Jill", "Fry", "jill.fry", "password", null, "skype", "location", "telephone", "mob", "instant", "google"));
    addPerson(new PersonInfo("Elvis", "Presley", "elvis.presley", "password", null, "skype", "location", "telephone", "mob", WITH_AVATAR, "google"));
    addPerson(new PersonInfo("John", "Lennon", "john.lennon", "password", null, "skype", "location", "telephone", "mob", WITH_AVATAR, "google"));
    addPerson(new PersonInfo("George", "Harrison", "george.harrison", "password", null, "skype", "location", "telephone", "mob", "instant", "google"));
    addPerson(new PersonInfo("David", "Bowie", "david.bowie", "password", null, "skype", "location", "telephone", "mob", "instant", "google"));
    addPerson(new PersonInfo("Ford", "Prefect", "ford.prefect", "password", null, "skype", "location", "telephone", "mob", "instant", "google"));
}
Also used : SiteInformation(org.alfresco.rest.api.tests.RepoService.SiteInformation) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork)

Example 25 with TestNetwork

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

the class TestPeople method createNetwork.

private TestNetwork createNetwork(String networkPrefix) {
    TestNetwork network = getRepoService().createNetwork(networkPrefix + GUID.generate(), true);
    network.create();
    return network;
}
Also used : TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork)

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