Search in sources :

Example 26 with RequestContext

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

the class DeploymentWorkflowApiTest method testGetDeploymentById.

@Test
public void testGetDeploymentById() throws Exception {
    // Use admin-user for tenant
    RequestContext requestContext = initApiClientWithTestUser();
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    publicApiClient.setRequestContext(new RequestContext(TenantUtil.DEFAULT_TENANT, tenantAdmin));
    // Fetch the actual deployment from activiti
    org.activiti.engine.repository.Deployment activitiDeployment = activitiProcessEngine.getRepositoryService().createDeploymentQuery().deploymentName("adhoc.bpmn20.xml").processDefinitionKey("@" + requestContext.getNetworkId() + "@activitiAdhoc").singleResult();
    assertNotNull(activitiDeployment);
    // Do the actual API-call
    DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
    Deployment deployment = deploymentsClient.findDeploymentById(activitiDeployment.getId());
    assertNotNull(deployment);
    assertEquals(activitiDeployment.getId(), deployment.getId());
    assertEquals(activitiDeployment.getCategory(), deployment.getCategory());
    assertEquals(activitiDeployment.getName(), deployment.getName());
    assertEquals(activitiDeployment.getDeploymentTime(), deployment.getDeployedAt());
    try {
        deploymentsClient.findDeploymentById("fakeid");
        fail("Expected exception");
    } catch (PublicApiException e) {
        assertEquals(404, e.getHttpResponse().getStatusCode());
    }
    // get deployment with default user
    try {
        publicApiClient.setRequestContext(requestContext);
        deploymentsClient.findDeploymentById(activitiDeployment.getId());
        fail("Expected exception");
    } catch (PublicApiException e) {
        assertEquals(403, e.getHttpResponse().getStatusCode());
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) DeploymentsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.DeploymentsClient) Deployment(org.alfresco.rest.workflow.api.model.Deployment) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 27 with RequestContext

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

the class DeploymentWorkflowApiTest method testGetDeploymentsEmpty.

@Test
public void testGetDeploymentsEmpty() throws Exception {
    // Create a new test-network, not added to the test-fixture to prevent being used
    // in other tests
    String networkName = AbstractTestFixture.TEST_DOMAIN_PREFIX + "999";
    final TestNetwork testNetwork = repoService.createNetworkWithAlias(networkName, true);
    transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        @SuppressWarnings("synthetic-access")
        public Void execute() throws Throwable {
            AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
            testNetwork.create();
            return null;
        }
    }, false, true);
    // Delete all deployments in the network
    List<org.activiti.engine.repository.Deployment> deployments = activitiProcessEngine.getRepositoryService().createDeploymentQuery().processDefinitionKeyLike("@" + testNetwork.getId() + "@%").list();
    for (org.activiti.engine.repository.Deployment deployment : deployments) {
        activitiProcessEngine.getRepositoryService().deleteDeployment(deployment.getId(), true);
    }
    // Fetch deployments using tenant-admin
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + testNetwork.getId();
    publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(), tenantAdmin));
    DeploymentsClient deploymentsClient = publicApiClient.deploymentsClient();
    ListResponse<Deployment> deploymentResponse = deploymentsClient.getDeployments();
    assertEquals(0, deploymentResponse.getList().size());
}
Also used : RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) Deployment(org.alfresco.rest.workflow.api.model.Deployment) DeploymentsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.DeploymentsClient) TestNetwork(org.alfresco.rest.api.tests.RepoService.TestNetwork) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 28 with RequestContext

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

the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionById.

@Test
public void testGetProcessDefinitionById() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    String tenantAdmin = AuthenticationUtil.getAdminUserName() + "@" + requestContext.getNetworkId();
    RequestContext adminContext = new RequestContext(requestContext.getNetworkId(), tenantAdmin);
    String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
    org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
    assertNotNull(activitiDefinition);
    // Get a single process definitions
    ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
    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());
    // get process definition with admin
    publicApiClient.setRequestContext(adminContext);
    adhocDefinition = processDefinitionsClient.findProcessDefinitionById(activitiDefinition.getId());
    assertNotNull(adhocDefinition);
    // Check fields of a resulting process-definition
    assertEquals(activitiDefinition.getId(), adhocDefinition.getId());
    assertEquals("activitiAdhoc", adhocDefinition.getKey());
}
Also used : ProcessDefinitionsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient) ProcessDefinition(org.alfresco.rest.workflow.api.model.ProcessDefinition) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 29 with RequestContext

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

the class ProcessDefinitionWorkflowApiTest method testGetProcessDefinitionsImage.

@Test
public void testGetProcessDefinitionsImage() throws Exception {
    RequestContext requestContext = initApiClientWithTestUser();
    ProcessDefinitionsClient processDefinitionsClient = publicApiClient.processDefinitionsClient();
    String adhocKey = createProcessDefinitionKey("activitiAdhoc", requestContext);
    org.activiti.engine.repository.ProcessDefinition activitiDefinition = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(adhocKey).singleResult();
    assertNotNull(activitiDefinition);
    try {
        HttpResponse response = processDefinitionsClient.findImageById(activitiDefinition.getId());
        fail("Exception expected");
    } catch (PublicApiException expected) {
        assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), expected.getHttpResponse().getStatusCode());
        assertTrue(expected.getMessage().contains("No image available"));
    }
}
Also used : PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) ProcessDefinitionsClient(org.alfresco.rest.workflow.api.tests.WorkflowApiClient.ProcessDefinitionsClient) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Test(org.junit.Test)

Example 30 with RequestContext

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

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