Search in sources :

Example 36 with Deployment

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

the class DeploymentResourceResourceTest method testGetDeploymentResource.

/**
  * Test getting a single resource, deployed in a deployment.
  * GET repository/deployments/{deploymentId}/resources/{resourceId}
  */
public void testGetDeploymentResource() throws Exception {
    try {
        String rawResourceName = "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml";
        Deployment deployment = repositoryService.createDeployment().name("Deployment 1").addClasspathResource(rawResourceName).addInputStream("test.txt", new ByteArrayInputStream("Test content".getBytes())).deploy();
        // Build up the URL manually to make sure resource-id gets encoded correctly as one piece
        HttpGet httpGet = new HttpGet(buildUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, deployment.getId(), encode(rawResourceName)));
        httpGet.addHeader(new BasicHeader(HttpHeaders.ACCEPT, "application/json"));
        CloseableHttpResponse response = executeRequest(httpGet, HttpStatus.SC_OK);
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        // Check URL's for the resource
        assertTrue(responseNode.get("url").textValue().equals(buildUrl(RestUrls.URL_DEPLOYMENT_RESOURCE, deployment.getId(), rawResourceName)));
        assertTrue(responseNode.get("contentUrl").textValue().equals(buildUrl(RestUrls.URL_DEPLOYMENT_RESOURCE_CONTENT, deployment.getId(), rawResourceName)));
        assertEquals("text/xml", responseNode.get("mediaType").textValue());
        assertEquals("processDefinition", responseNode.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) BasicHeader(org.apache.http.message.BasicHeader)

Example 37 with Deployment

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

the class DeploymentResourceTest method testPostNewDeploymentBarFile.

/**
   * Test deploying bar-file.
   * POST repository/deployments
   */
public void testPostNewDeploymentBarFile() throws Exception {
    try {
        // Create zip with bpmn-file and resource
        ByteArrayOutputStream zipOutput = new ByteArrayOutputStream();
        ZipOutputStream zipStream = new ZipOutputStream(zipOutput);
        // Add bpmn-xml
        zipStream.putNextEntry(new ZipEntry("oneTaskProcess.bpmn20.xml"));
        IOUtils.copy(ReflectUtil.getResourceAsStream("org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml"), zipStream);
        zipStream.closeEntry();
        // Add text-resource
        zipStream.putNextEntry(new ZipEntry("test.txt"));
        IOUtils.write("Testing REST-deployment with tenant", zipStream);
        zipStream.closeEntry();
        zipStream.close();
        // Upload a bar-file using multipart-data
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_COLLECTION));
        httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("test-deployment.bar", "application/zip", new ByteArrayInputStream(zipOutput.toByteArray()), 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();
        assertTrue(tenantId.equals(""));
        assertNotNull(deploymentId);
        assertEquals(1L, repositoryService.createDeploymentQuery().deploymentId(deploymentId).count());
        assertNotNull(name);
        assertEquals("test-deployment.bar", 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 both resources are deployed and process is actually deployed in the deployment
        List<String> resources = repositoryService.getDeploymentResourceNames(deploymentId);
        assertEquals(2L, resources.size());
        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) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Deployment(org.activiti.engine.repository.Deployment) JsonNode(com.fasterxml.jackson.databind.JsonNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 38 with Deployment

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

the class DeploymentResourceTest method testPostNewDeploymentBarFileWithTenantId.

/** Test deploying bar-file.
  * POST repository/deployments
  */
public void testPostNewDeploymentBarFileWithTenantId() throws Exception {
    try {
        // Create zip with bpmn-file and resource
        ByteArrayOutputStream zipOutput = new ByteArrayOutputStream();
        ZipOutputStream zipStream = new ZipOutputStream(zipOutput);
        // Add bpmn-xml
        zipStream.putNextEntry(new ZipEntry("oneTaskProcess.bpmn20.xml"));
        IOUtils.copy(ReflectUtil.getResourceAsStream("org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml"), zipStream);
        zipStream.closeEntry();
        // Add text-resource
        zipStream.putNextEntry(new ZipEntry("test.txt"));
        IOUtils.write("Testing REST-deployment", zipStream);
        zipStream.closeEntry();
        zipStream.close();
        // Upload a bar-file using multipart-data
        HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT_COLLECTION));
        httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("test-deployment.bar", "application/zip", new ByteArrayInputStream(zipOutput.toByteArray()), Collections.singletonMap("tenantId", "myTenant")));
        CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED);
        // Check deployment
        JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
        closeResponse(response);
        String tenantId = responseNode.get("tenantId").textValue();
        assertEquals("myTenant", tenantId);
        String id = responseNode.get("id").textValue();
        Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(id).singleResult();
        assertNotNull(deployment);
        assertEquals("myTenant", deployment.getTenantId());
    } 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) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Deployment(org.activiti.engine.repository.Deployment) JsonNode(com.fasterxml.jackson.databind.JsonNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 39 with Deployment

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

the class DeploymentResourceTest method testDeleteDeployment.

/**
   * Test deleting a single deployment.
   * DELETE repository/deployments/{deploymentId}
   */
@org.activiti.engine.test.Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testDeleteDeployment() throws Exception {
    Deployment existingDeployment = repositoryService.createDeploymentQuery().singleResult();
    assertNotNull(existingDeployment);
    // Delete the deployment
    HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_DEPLOYMENT, existingDeployment.getId()));
    CloseableHttpResponse response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
    closeResponse(response);
    existingDeployment = repositoryService.createDeploymentQuery().singleResult();
    assertNull(existingDeployment);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Deployment(org.activiti.engine.repository.Deployment)

Example 40 with Deployment

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

the class DeploymentEventsTest method testDeploymentEvents.

/**
	 * Test create, update and delete events of deployment entities.
	 */
public void testDeploymentEvents() throws Exception {
    Deployment deployment = null;
    try {
        listener.clearEventsReceived();
        deployment = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml").deploy();
        assertNotNull(deployment);
        // Check create-event
        assertEquals(2, listener.getEventsReceived().size());
        assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiEntityEvent);
        ActivitiEntityEvent event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_CREATED, event.getType());
        assertEquals(deployment.getId(), ((Deployment) event.getEntity()).getId());
        assertTrue(listener.getEventsReceived().get(1) instanceof ActivitiEntityEvent);
        event = (ActivitiEntityEvent) listener.getEventsReceived().get(1);
        assertEquals(ActivitiEventType.ENTITY_INITIALIZED, event.getType());
        assertEquals(deployment.getId(), ((Deployment) event.getEntity()).getId());
        listener.clearEventsReceived();
        // Check update event when category is updated
        repositoryService.setDeploymentCategory(deployment.getId(), "test");
        assertEquals(1, listener.getEventsReceived().size());
        assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiEntityEvent);
        event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_UPDATED, event.getType());
        assertEquals(deployment.getId(), ((Deployment) event.getEntity()).getId());
        assertEquals("test", ((Deployment) event.getEntity()).getCategory());
        listener.clearEventsReceived();
        // Check delete event when category is updated
        repositoryService.deleteDeployment(deployment.getId(), true);
        assertEquals(1, listener.getEventsReceived().size());
        assertTrue(listener.getEventsReceived().get(0) instanceof ActivitiEntityEvent);
        event = (ActivitiEntityEvent) listener.getEventsReceived().get(0);
        assertEquals(ActivitiEventType.ENTITY_DELETED, event.getType());
        assertEquals(deployment.getId(), ((Deployment) event.getEntity()).getId());
        listener.clearEventsReceived();
    } finally {
        if (deployment != null && repositoryService.createDeploymentQuery().deploymentId(deployment.getId()).count() > 0) {
            repositoryService.deleteDeployment(deployment.getId(), true);
        }
    }
}
Also used : Deployment(org.activiti.engine.repository.Deployment) ActivitiEntityEvent(org.activiti.engine.delegate.event.ActivitiEntityEvent)

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