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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
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);
}
}
}
Aggregations