Search in sources :

Example 31 with RequestContext

use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.

the class ProcessDefinitionWorkflowApiTest method testMethodNotAllowedURIs.

@Test
public void testMethodNotAllowedURIs() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    HttpResponse response = publicApiClient.get("public", "process-definitions", null, null, null, null);
    assertEquals(200, response.getStatusCode());
    response = publicApiClient.post("public", "process-definitions", null, null, null, null);
    assertEquals(405, response.getStatusCode());
    response = publicApiClient.delete("public", "process-definitions", null, null, null);
    assertEquals(405, response.getStatusCode());
    response = publicApiClient.put("public", "process-definitions", null, null, null, null, null);
    assertEquals(405, response.getStatusCode());
    String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
    org.activiti.engine.repository.ProcessDefinition processDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
    assertNotNull(processDefinition);
    response = publicApiClient.get("public", "process-definitions", processDefinition.getId(), null, null, null);
    assertEquals(200, response.getStatusCode());
    response = publicApiClient.post("public", "process-definitions", processDefinition.getId(), null, null, null);
    assertEquals(405, response.getStatusCode());
    response = publicApiClient.delete("public", "process-definitions", processDefinition.getId(), null, null);
    assertEquals(405, response.getStatusCode());
    response = publicApiClient.put("public", "process-definitions", processDefinition.getId(), null, null, null, null);
    assertEquals(405, response.getStatusCode());
    response = publicApiClient.get("public", "process-definitions", processDefinition.getId(), "start-form-model", null, null);
    assertEquals(200, response.getStatusCode());
    response = publicApiClient.post("public", "process-definitions", processDefinition.getId(), "start-form-model", null, null);
    assertEquals(405, response.getStatusCode());
    response = publicApiClient.delete("public", "process-definitions", processDefinition.getId(), "start-form-model", null);
    assertEquals(405, response.getStatusCode());
    response = publicApiClient.put("public", "process-definitions", processDefinition.getId(), "start-form-model", null, null, null);
    assertEquals(405, response.getStatusCode());
}
Also used : HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 32 with RequestContext

use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.

the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitions.

@Test
public void testGetProcessDefinitions() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    // Get all process definitions
    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());
    // Check fields of a resulting process-definition
    String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
    org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
    assertNotNull(activitiDefinition);
    ProcessDefinition adhocDefinitionRest = processDefinitionMap.get("activitiAdhoc");
    assertEquals(activitiDefinition.getId(), adhocDefinitionRest.getId());
    assertEquals("activitiAdhoc", adhocDefinitionRest.getKey());
    assertEquals(activitiDefinition.getDeploymentId(), adhocDefinitionRest.getDeploymentId());
    assertEquals(activitiDefinition.getCategory(), adhocDefinitionRest.getCategory());
    assertEquals(activitiDefinition.getName(), adhocDefinitionRest.getName());
    assertEquals(activitiDefinition.getVersion(), adhocDefinitionRest.getVersion());
    assertEquals(((ProcessDefinitionEntity) activitiDefinition).isGraphicalNotationDefined(), adhocDefinitionRest.isGraphicNotationDefined());
    assertEquals("wf:submitAdhocTask", adhocDefinitionRest.getStartFormResourceKey());
    assertEquals("New Task", adhocDefinitionRest.getTitle());
    assertEquals("Assign a new task to yourself or a colleague", adhocDefinitionRest.getDescription());
    Map<String, String> params = new HashMap<String, String>();
    params.put("maxItems", "2");
    JSONObject definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
    assertNotNull(definitionListObject);
    JSONObject paginationJSON = (JSONObject) definitionListObject.get("pagination");
    assertEquals(2l, paginationJSON.get("count"));
    assertEquals(5l, paginationJSON.get("totalItems"));
    assertEquals(0l, paginationJSON.get("skipCount"));
    assertEquals(true, paginationJSON.get("hasMoreItems"));
    params = new HashMap<String, String>();
    definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
    assertNotNull(definitionListObject);
    paginationJSON = (JSONObject) definitionListObject.get("pagination");
    assertEquals(5l, paginationJSON.get("count"));
    assertEquals(5l, paginationJSON.get("totalItems"));
    assertEquals(0l, paginationJSON.get("skipCount"));
    assertEquals(false, paginationJSON.get("hasMoreItems"));
    params = new HashMap<String, String>();
    params.put("skipCount", "2");
    params.put("maxItems", "2");
    definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
    assertNotNull(definitionListObject);
    paginationJSON = (JSONObject) definitionListObject.get("pagination");
    assertEquals(2l, paginationJSON.get("count"));
    assertEquals(5l, paginationJSON.get("totalItems"));
    assertEquals(2l, paginationJSON.get("skipCount"));
    assertEquals(true, paginationJSON.get("hasMoreItems"));
    params = new HashMap<String, String>();
    params.put("skipCount", "2");
    params.put("maxItems", "5");
    definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
    assertNotNull(definitionListObject);
    paginationJSON = (JSONObject) definitionListObject.get("pagination");
    assertEquals(3l, paginationJSON.get("count"));
    assertEquals(5l, paginationJSON.get("totalItems"));
    assertEquals(2l, paginationJSON.get("skipCount"));
    assertEquals(false, paginationJSON.get("hasMoreItems"));
    params = new HashMap<String, String>();
    params.put("skipCount", "0");
    params.put("maxItems", "7");
    definitionListObject = processDefinitionsClient.getProcessDefinitionsWithRawResponse(params);
    assertNotNull(definitionListObject);
    paginationJSON = (JSONObject) definitionListObject.get("pagination");
    assertEquals(5l, paginationJSON.get("count"));
    assertEquals(5l, paginationJSON.get("totalItems"));
    assertEquals(0l, paginationJSON.get("skipCount"));
    assertEquals(false, paginationJSON.get("hasMoreItems"));
}
Also used : HashMap(java.util.HashMap) ProcessDefinition(org.alfresco.rest.workflow.api.model.ProcessDefinition) ProcessDefinitionsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient) JSONObject(org.json.simple.JSONObject) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 33 with RequestContext

use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method testMethodNotAllowedURIs.

@Test
public void testMethodNotAllowedURIs() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    HttpResponse response = publicApiClient.get("public", "processes", null, null, null, null);
    assertEquals(200, response.getStatusCode());
    response = publicApiClient.put("public", "processes", null, null, null, null, null);
    assertEquals(405, response.getStatusCode());
    final ProcessInfo processInfo = startAdhocProcess(requestContext, null);
    try {
        response = publicApiClient.get("public", "processes", processInfo.getId(), null, null, null);
        assertEquals(200, response.getStatusCode());
        response = publicApiClient.post("public", "processes", processInfo.getId(), null, null, null);
        assertEquals(405, response.getStatusCode());
        response = publicApiClient.put("public", "processes", processInfo.getId(), null, null, null, null);
        assertEquals(405, response.getStatusCode());
        response = publicApiClient.get("public", "processes", processInfo.getId(), "activities", null, null);
        assertEquals(200, response.getStatusCode());
        response = publicApiClient.post("public", "processes", processInfo.getId(), "activities", null, null);
        assertEquals(405, response.getStatusCode());
        response = publicApiClient.delete("public", "processes", processInfo.getId(), "activities", null);
        assertEquals(405, response.getStatusCode());
        response = publicApiClient.put("public", "processes", processInfo.getId(), "activities", null, null, null);
        assertEquals(405, response.getStatusCode());
        response = publicApiClient.get("public", "processes", processInfo.getId(), "tasks", null, null);
        assertEquals(200, response.getStatusCode());
        response = publicApiClient.post("public", "processes", processInfo.getId(), "tasks", null, null);
        assertEquals(405, response.getStatusCode());
        response = publicApiClient.delete("public", "processes", processInfo.getId(), "tasks", null);
        assertEquals(405, response.getStatusCode());
        response = publicApiClient.put("public", "processes", processInfo.getId(), "tasks", null, null, null);
        assertEquals(405, response.getStatusCode());
    } finally {
        cleanupProcessInstance(processInfo.getId());
    }
}
Also used : HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Example 34 with RequestContext

use of org.alfresco.rest.api.tests.client.RequestContext 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 35 with RequestContext

use of org.alfresco.rest.api.tests.client.RequestContext in project alfresco-remote-api by Alfresco.

the class ProcessWorkflowApiTest method getProcessImage.

@Test
public void getProcessImage() throws Exception {
    final RequestContext requestContext = initApiClientWithTestUser();
    final ProcessInfo processRest = startAdhocProcess(requestContext, null);
    HttpResponse response = publicApiClient.processesClient().getImage(processRest.getId());
    assertEquals(200, response.getStatusCode());
    cleanupProcessInstance(processRest.getId());
    try {
        response = publicApiClient.processesClient().getImage("fakeId");
        fail("Exception expected");
    } catch (PublicApiException e) {
        assertEquals(404, e.getHttpResponse().getStatusCode());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) ProcessInfo(org.alfresco.rest.workflow.api.model.ProcessInfo) Test(org.junit.Test)

Aggregations

RequestContext (org.alfresco.rest.api.tests.client.RequestContext)185 Test (org.junit.Test)174 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)102 JSONObject (org.json.simple.JSONObject)67 HashMap (java.util.HashMap)58 TestNetwork (org.alfresco.rest.api.tests.RepoService.TestNetwork)52 ArrayList (java.util.ArrayList)46 NodeRef (org.alfresco.service.cmr.repository.NodeRef)45 Task (org.activiti.engine.task.Task)44 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)39 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)38 TestPerson (org.alfresco.rest.api.tests.RepoService.TestPerson)36 ProcessInfo (org.alfresco.rest.workflow.api.model.ProcessInfo)36 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)33 VersionableAspectTest (org.alfresco.repo.version.VersionableAspectTest)26 Person (org.alfresco.rest.api.tests.client.data.Person)25 JSONArray (org.json.simple.JSONArray)25 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)24 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)24 List (java.util.List)23