use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.
the class ProcessInstanceIdentityLinkResourceTest method testGetSingleIdentityLink.
/**
* Test getting a single identity link for a process instance.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceIdentityLinkResourceTest.process.bpmn20.xml" })
public void testGetSingleIdentityLink() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
runtimeService.addUserIdentityLink(processInstance.getId(), "kermit", "myType");
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK, processInstance.getId(), "kermit", "myType")), HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("kermit", responseNode.get("user").textValue());
assertEquals("myType", responseNode.get("type").textValue());
assertTrue(responseNode.get("group").isNull());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK, processInstance.getId(), "kermit", "myType")));
// Test with unexisting process
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK, RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS, "kermit", "myType")), HttpStatus.SC_NOT_FOUND));
}
use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.
the class ProcessInstanceResourceTest method testGetProcessInstance.
/**
* Test getting a single process instance.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testGetProcessInstance() throws Exception {
ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder().processDefinitionKey("processOne").businessKey("myBusinessKey").processInstanceName("myProcessName").start();
String url = buildUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId());
CloseableHttpResponse response = executeRequest(new HttpGet(url), HttpStatus.SC_OK);
// Check resulting instance
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals(processInstance.getId(), responseNode.get("id").textValue());
assertEquals("myBusinessKey", responseNode.get("businessKey").textValue());
assertEquals("myProcessName", responseNode.get("name").textValue());
assertEquals("processTask", responseNode.get("activityId").textValue());
assertFalse(responseNode.get("suspended").booleanValue());
assertEquals("", responseNode.get("tenantId").textValue());
assertTrue(responseNode.get("url").asText().equals(url));
assertTrue(responseNode.get("processDefinitionUrl").asText().equals(buildUrl(RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId())));
// Check result after tenant has been changed
managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId())), HttpStatus.SC_OK);
// Check resulting instance tenant id
responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("myTenant", responseNode.get("tenantId").textValue());
}
use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.
the class ProcessInstanceResourceTest method testSuspendProcessInstance.
/**
* Test suspending a single process instance.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testSuspendProcessInstance() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "suspend");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
// Check engine id instance is suspended
assertEquals(1, runtimeService.createProcessInstanceQuery().suspended().processInstanceId(processInstance.getId()).count());
// Check resulting instance is suspended
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals(processInstance.getId(), responseNode.get("id").textValue());
assertTrue(responseNode.get("suspended").booleanValue());
// Suspending again should result in conflict
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}
use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.
the class ProcessInstanceResourceTest method testActivateProcessInstance.
/**
* Test suspending a single process instance.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testActivateProcessInstance() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
runtimeService.suspendProcessInstanceById(processInstance.getId());
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "activate");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, processInstance.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
// Check engine id instance is suspended
assertEquals(1, runtimeService.createProcessInstanceQuery().active().processInstanceId(processInstance.getId()).count());
// Check resulting instance is suspended
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals(processInstance.getId(), responseNode.get("id").textValue());
assertFalse(responseNode.get("suspended").booleanValue());
// Activating again should result in conflict
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_CONFLICT));
}
use of org.apache.http.client.methods.CloseableHttpResponse in project Activiti by Activiti.
the class TaskAttachmentResourceTest method testCreateAttachment.
/**
* Test creating a single attachments for a task
* POST runtime/tasks/{taskId}/attachments/{attachmentId}
*/
public void testCreateAttachment() throws Exception {
try {
Task task = taskService.newTask();
taskService.saveTask(task);
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("name", "Simple attachment");
requestNode.put("description", "Simple attachment description");
requestNode.put("type", "simpleType");
requestNode.put("externalUrl", "http://activiti.org");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_COLLECTION, task.getId()));
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
// Check if attachment is created
List<Attachment> attachments = taskService.getTaskAttachments(task.getId());
assertEquals(1, attachments.size());
Attachment urlAttachment = attachments.get(0);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertEquals(urlAttachment.getId(), responseNode.get("id").textValue());
assertEquals("simpleType", responseNode.get("type").textValue());
assertEquals("Simple attachment", responseNode.get("name").textValue());
assertEquals("Simple attachment description", responseNode.get("description").textValue());
assertEquals("http://activiti.org", responseNode.get("externalUrl").textValue());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), urlAttachment.getId())));
assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));
assertTrue(responseNode.get("contentUrl").isNull());
assertTrue(responseNode.get("processInstanceUrl").isNull());
assertFalse(responseNode.get("time").isNull());
} finally {
// Clean adhoc-tasks even if test fails
List<Task> tasks = taskService.createTaskQuery().list();
for (Task task : tasks) {
taskService.deleteTask(task.getId(), true);
}
}
}
Aggregations