use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class HistoricDetailQueryResourceTest method assertResultsPresentInDataResponse.
protected void assertResultsPresentInDataResponse(String url, ObjectNode body, int numberOfResultsExpected, String variableName, Object variableValue) throws JsonProcessingException, IOException {
// Do the actual call
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url);
httpPost.setEntity(new StringEntity(body.toString()));
CloseableHttpResponse response = executeRequest(httpPost, 200);
// Check status and size
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
closeResponse(response);
assertEquals(numberOfResultsExpected, dataNode.size());
// Check presence of ID's
if (variableName != null) {
boolean variableFound = false;
Iterator<JsonNode> it = dataNode.iterator();
while (it.hasNext()) {
JsonNode variableNode = it.next().get("variable");
String name = variableNode.get("name").textValue();
if (variableName.equals(name)) {
variableFound = true;
if (variableValue instanceof Boolean) {
assertTrue("Variable value is not equal", variableNode.get("value").asBoolean() == (Boolean) variableValue);
} else if (variableValue instanceof Integer) {
assertTrue("Variable value is not equal", variableNode.get("value").asInt() == (Integer) variableValue);
} else {
assertTrue("Variable value is not equal", variableNode.get("value").asText().equals((String) variableValue));
}
}
}
assertTrue("Variable " + variableName + " is missing", variableFound);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class HistoricProcessInstanceCollectionResourceTest method testQueryProcessInstances.
/**
* Test querying historic process instance based on variables.
* GET history/historic-process-instances
*/
@Deployment
public void testQueryProcessInstances() throws Exception {
Calendar startTime = Calendar.getInstance();
processEngineConfiguration.getClock().setCurrentTime(startTime.getTime());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.complete(task.getId());
startTime.add(Calendar.DAY_OF_YEAR, 1);
processEngineConfiguration.getClock().setCurrentTime(startTime.getTime());
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess");
String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCES);
assertResultsPresentInDataResponse(url + "?finished=true", processInstance.getId());
assertResultsPresentInDataResponse(url + "?finished=false", processInstance2.getId());
assertResultsPresentInDataResponse(url + "?processDefinitionId=" + processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance2.getId());
assertResultsPresentInDataResponse(url + "?processDefinitionId=" + processInstance.getProcessDefinitionId() + "&finished=true", processInstance.getId());
assertResultsPresentInDataResponse(url + "?processDefinitionKey=oneTaskProcess", processInstance.getId(), processInstance2.getId());
// Without tenant ID, before setting tenant
assertResultsPresentInDataResponse(url + "?withoutTenantId=true", processInstance.getId(), processInstance2.getId());
// Set tenant on deployment
managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
startTime.add(Calendar.DAY_OF_YEAR, 1);
processEngineConfiguration.getClock().setCurrentTime(startTime.getTime());
ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKeyAndTenantId("oneTaskProcess", "myTenant");
// Without tenant ID, after setting tenant
assertResultsPresentInDataResponse(url + "?withoutTenantId=true", processInstance.getId(), processInstance2.getId());
// Tenant id
assertResultsPresentInDataResponse(url + "?tenantId=myTenant", processInstance3.getId());
assertResultsPresentInDataResponse(url + "?tenantId=anotherTenant");
// Tenant id like
assertResultsPresentInDataResponse(url + "?tenantIdLike=" + encode("%enant"), processInstance3.getId());
assertResultsPresentInDataResponse(url + "?tenantIdLike=anotherTenant");
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url + "?processDefinitionKey=oneTaskProcess&sort=startTime"), 200);
// Check status and size
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
closeResponse(response);
assertEquals(3, dataNode.size());
assertEquals(processInstance.getId(), dataNode.get(0).get("id").asText());
assertEquals(processInstance2.getId(), dataNode.get(1).get("id").asText());
assertEquals(processInstance3.getId(), dataNode.get(2).get("id").asText());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class HistoricProcessInstanceCollectionResourceTest method assertResultsPresentInDataResponse.
protected void assertResultsPresentInDataResponse(String url, String... expectedResourceIds) throws JsonProcessingException, IOException {
int numberOfResultsExpected = expectedResourceIds.length;
// Do the actual call
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), 200);
// Check status and size
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
closeResponse(response);
assertEquals(numberOfResultsExpected, dataNode.size());
// Check presence of ID's
List<String> toBeFound = new ArrayList<String>(Arrays.asList(expectedResourceIds));
Iterator<JsonNode> it = dataNode.iterator();
while (it.hasNext()) {
String id = it.next().get("id").textValue();
toBeFound.remove(id);
}
assertTrue("Not all process instances have been found in result, missing: " + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class HistoricProcessInstanceCommentResourceTest method testGetComment.
/**
* Test getting a comment for a historic process instance.
* GET history/historic-process-instances/{processInstanceId}/comments/{commentId}
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetComment() throws Exception {
ProcessInstance pi = null;
try {
pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");
// Add a comment as "kermit"
identityService.setAuthenticatedUserId("kermit");
Comment comment = taskService.addComment(null, pi.getId(), "This is a comment...");
identityService.setAuthenticatedUserId(null);
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), comment.getId())), 200);
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("kermit", responseNode.get("author").textValue());
assertEquals("This is a comment...", responseNode.get("message").textValue());
assertEquals(comment.getId(), responseNode.get("id").textValue());
assertTrue(responseNode.get("processInstanceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), comment.getId())));
assertEquals(pi.getProcessInstanceId(), responseNode.get("processInstanceId").asText());
assertTrue(responseNode.get("taskUrl").isNull());
assertTrue(responseNode.get("taskId").isNull());
// Test with unexisting process-instance
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, "unexistinginstance", "123")), HttpStatus.SC_NOT_FOUND));
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), "unexistingcomment")), HttpStatus.SC_NOT_FOUND));
} finally {
if (pi != null) {
List<Comment> comments = taskService.getProcessInstanceComments(pi.getId());
for (Comment c : comments) {
taskService.deleteComment(c.getId());
}
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class HistoricProcessInstanceCommentResourceTest method testCreateComment.
/**
* Test creating a comment for a process instance.
* POST history/historic-process-instances/{processInstanceId}/comments
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testCreateComment() throws Exception {
ProcessInstance pi = null;
try {
pi = runtimeService.startProcessInstanceByKey("oneTaskProcess");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT_COLLECTION, pi.getId()));
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("message", "This is a comment...");
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode());
List<Comment> commentsOnProcess = taskService.getProcessInstanceComments(pi.getId());
assertNotNull(commentsOnProcess);
assertEquals(1, commentsOnProcess.size());
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("kermit", responseNode.get("author").textValue());
assertEquals("This is a comment...", responseNode.get("message").textValue());
assertEquals(commentsOnProcess.get(0).getId(), responseNode.get("id").textValue());
assertTrue(responseNode.get("processInstanceUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_COMMENT, pi.getId(), commentsOnProcess.get(0).getId())));
assertEquals(pi.getProcessInstanceId(), responseNode.get("processInstanceId").asText());
assertTrue(responseNode.get("taskUrl").isNull());
assertTrue(responseNode.get("taskId").isNull());
} finally {
if (pi != null) {
List<Comment> comments = taskService.getProcessInstanceComments(pi.getId());
for (Comment c : comments) {
taskService.deleteComment(c.getId());
}
}
}
}
Aggregations