Search in sources :

Example 16 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class DeploymentResourceResourceTest method testGetDeploymentResourceUnexistingResource.

/**
    * Test getting an unexisting resource for an existing deployment.
    * GET repository/deployments/{deploymentId}/resources/{resourceId}
    */
public void testGetDeploymentResourceUnexistingResource() throws Exception {
    try {
        Deployment deployment = repositoryService.createDeployment().name("Deployment 1").addInputStream("test.txt", new ByteArrayInputStream("Test content".getBytes())).deploy();
        HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, deployment.getId(), "unexisting-resource.png"));
        httpGet.addHeader(new BasicHeader(HttpHeaders.ACCEPT, "image/png,application/json"));
        closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));
    } finally {
        // Always cleanup any created deployments, even if the test failed
        List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
        for (Deployment deployment : deployments) {
            repositoryService.deleteDeployment(deployment.getId(), true);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HttpGet(org.apache.http.client.methods.HttpGet) Deployment(org.activiti.engine.repository.Deployment) BasicHeader(org.apache.http.message.BasicHeader)

Example 17 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class DeploymentResourceResourceTest method testGetDeploymentResourceContent.

/**
    * Test getting a deployment resource content.
    * GET repository/deployments/{deploymentId}/resources/{resourceId}
    */
public void testGetDeploymentResourceContent() throws Exception {
    try {
        Deployment deployment = repositoryService.createDeployment().name("Deployment 1").addInputStream("test.txt", new ByteArrayInputStream("Test content".getBytes())).deploy();
        HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCE_CONTENT, deployment.getId(), "test.txt"));
        httpGet.addHeader(new BasicHeader(HttpHeaders.ACCEPT, "text/plain"));
        CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
        String responseAsString = IOUtils.toString(response.getEntity().getContent());
        closeResponse(response);
        assertNotNull(responseAsString);
        assertEquals("Test content", responseAsString);
    } finally {
        // Always cleanup any created deployments, even if the test failed
        List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
        for (Deployment deployment : deployments) {
            repositoryService.deleteDeployment(deployment.getId(), true);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Deployment(org.activiti.engine.repository.Deployment) BasicHeader(org.apache.http.message.BasicHeader)

Example 18 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class DeploymentResourceTest method testPostNewDeploymentBPMNFile.

/**
   * Test deploying singe bpmn-file.
   * POST repository/deployments
   */
public void testPostNewDeploymentBPMNFile() throws Exception {
    try {
        // Upload a valid BPMN-file using multipart-data
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_COLLECTION));
        httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("oneTaskProcess.bpmn20.xml", "application/xml", ReflectUtil.getResourceAsStream("org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml"), null));
        CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED);
        // Check deployment
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        String deploymentId = responseNode.get("id").textValue();
        String name = responseNode.get("name").textValue();
        String category = responseNode.get("category").textValue();
        String deployTime = responseNode.get("deploymentTime").textValue();
        String url = responseNode.get("url").textValue();
        String tenantId = responseNode.get("tenantId").textValue();
        assertEquals("", tenantId);
        assertNotNull(deploymentId);
        assertEquals(1L, repositoryService.createDeploymentQuery().deploymentId(deploymentId).count());
        assertNotNull(name);
        assertEquals("oneTaskProcess.bpmn20.xml", name);
        assertNotNull(url);
        assertTrue(url.endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId)));
        // No deployment-category should have been set
        assertNull(category);
        assertNotNull(deployTime);
        // Check if process is actually deployed in the deployment
        List<String> resources = repositoryService.getDeploymentResourceNames(deploymentId);
        assertEquals(1L, resources.size());
        assertEquals("oneTaskProcess.bpmn20.xml", resources.get(0));
        assertEquals(1L, repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).count());
    } finally {
        // Always cleanup any created deployments, even if the test failed
        List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
        for (Deployment deployment : deployments) {
            repositoryService.deleteDeployment(deployment.getId(), true);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Deployment(org.activiti.engine.repository.Deployment) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 19 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class DeploymentResourceTest method testGetDeployment.

/**
  * Test getting a single deployment.
  * GET repository/deployments/{deploymentId}
  */
@org.activiti.engine.test.Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetDeployment() throws Exception {
    Deployment existingDeployment = repositoryService.createDeploymentQuery().singleResult();
    HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, existingDeployment.getId()));
    CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
    closeResponse(response);
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    String deploymentId = responseNode.get("id").textValue();
    String name = responseNode.get("name").textValue();
    String category = responseNode.get("category").textValue();
    String deployTime = responseNode.get("deploymentTime").textValue();
    String url = responseNode.get("url").textValue();
    String tenantId = responseNode.get("tenantId").textValue();
    assertEquals("", tenantId);
    assertNotNull(deploymentId);
    assertEquals(existingDeployment.getId(), deploymentId);
    assertNotNull(name);
    assertEquals(existingDeployment.getName(), name);
    assertEquals(existingDeployment.getCategory(), category);
    assertNotNull(deployTime);
    assertNotNull(url);
    assertTrue(url.endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, deploymentId)));
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Deployment(org.activiti.engine.repository.Deployment) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 20 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class DeploymentResourcesResourceTest method testGetDeploymentResources.

/**
  * Test getting all resources for a single deployment.
  * GET repository/deployments/{deploymentId}/resources
  */
public void testGetDeploymentResources() throws Exception {
    try {
        Deployment deployment = repositoryService.createDeployment().name("Deployment 1").addClasspathResource("org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml").addInputStream("test.txt", new ByteArrayInputStream("Test content".getBytes())).deploy();
        HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCES, deployment.getId()));
        CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        assertTrue(responseNode.isArray());
        assertEquals(2, responseNode.size());
        // Since resources can be returned in any arbitrary order, find the right one to check
        JsonNode txtNode = null;
        for (int i = 0; i < responseNode.size(); i++) {
            if ("test.txt".equals(responseNode.get(i).get("id").textValue())) {
                txtNode = responseNode.get(i);
                break;
            }
        }
        // Check URL's for the resource
        assertNotNull(txtNode);
        assertTrue(txtNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, deployment.getId(), "test.txt")));
        assertTrue(txtNode.get("contentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_RESOURCE_CONTENT, deployment.getId(), "test.txt")));
        assertTrue(txtNode.get("mediaType").isNull());
        assertEquals("resource", txtNode.get("type").textValue());
    } finally {
        // Always cleanup any created deployments, even if the test failed
        List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
        for (Deployment deployment : deployments) {
            repositoryService.deleteDeployment(deployment.getId(), true);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Deployment(org.activiti.engine.repository.Deployment) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

Deployment (org.activiti.engine.repository.Deployment)66 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)12 BpmnModel (org.activiti.bpmn.model.BpmnModel)10 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ActivitiException (org.activiti.engine.ActivitiException)7 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)6 HttpGet (org.apache.http.client.methods.HttpGet)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 InputStream (java.io.InputStream)3 HashSet (java.util.HashSet)3 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)3 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)3 ProcessEngine (org.activiti.engine.ProcessEngine)3 RuntimeService (org.activiti.engine.RuntimeService)3 DeploymentBuilder (org.activiti.engine.repository.DeploymentBuilder)3 Task (org.activiti.engine.task.Task)3