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