use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class HistoricProcessInstanceQueryResourceTest method testQueryProcessInstancesWithVariables.
/**
* Test querying historic process instance based on variables.
* POST query/historic-process-instances
*/
@Deployment
public void testQueryProcessInstancesWithVariables() throws Exception {
HashMap<String, Object> processVariables = new HashMap<String, Object>();
processVariables.put("stringVar", "Azerty");
processVariables.put("intVar", 67890);
processVariables.put("booleanVar", false);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.complete(task.getId());
ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE_QUERY);
// Process variables
ObjectNode requestNode = objectMapper.createObjectNode();
ArrayNode variableArray = objectMapper.createArrayNode();
ObjectNode variableNode = objectMapper.createObjectNode();
variableArray.add(variableNode);
requestNode.put("variables", variableArray);
// String equals
variableNode.put("name", "stringVar");
variableNode.put("value", "Azerty");
variableNode.put("operation", "equals");
assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
// Integer equals
variableNode.removeAll();
variableNode.put("name", "intVar");
variableNode.put("value", 67890);
variableNode.put("operation", "equals");
assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
// Boolean equals
variableNode.removeAll();
variableNode.put("name", "booleanVar");
variableNode.put("value", false);
variableNode.put("operation", "equals");
assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
// String not equals
variableNode.removeAll();
variableNode.put("name", "stringVar");
variableNode.put("value", "ghijkl");
variableNode.put("operation", "notEquals");
assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
// Integer not equals
variableNode.removeAll();
variableNode.put("name", "intVar");
variableNode.put("value", 45678);
variableNode.put("operation", "notEquals");
assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
// Boolean not equals
variableNode.removeAll();
variableNode.put("name", "booleanVar");
variableNode.put("value", true);
variableNode.put("operation", "notEquals");
assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
// String equals ignore case
variableNode.removeAll();
variableNode.put("name", "stringVar");
variableNode.put("value", "azeRTY");
variableNode.put("operation", "equalsIgnoreCase");
assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
// String not equals ignore case (not supported)
variableNode.removeAll();
variableNode.put("name", "stringVar");
variableNode.put("value", "HIJKLm");
variableNode.put("operation", "notEqualsIgnoreCase");
assertErrorResult(url, requestNode, HttpStatus.SC_BAD_REQUEST);
// String equals without value
variableNode.removeAll();
variableNode.put("value", "Azerty");
variableNode.put("operation", "equals");
assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
// String equals with non existing value
variableNode.removeAll();
variableNode.put("value", "Azerty2");
variableNode.put("operation", "equals");
assertResultsPresentInPostDataResponse(url, requestNode);
// String like ignore case
variableNode.removeAll();
variableNode.put("name", "stringVar");
variableNode.put("value", "azerty");
variableNode.put("operation", "likeIgnoreCase");
assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
variableNode.removeAll();
variableNode.put("name", "stringVar");
variableNode.put("value", "azerty2");
variableNode.put("operation", "likeIgnoreCase");
assertResultsPresentInPostDataResponse(url, requestNode);
requestNode = objectMapper.createObjectNode();
requestNode.put("finished", true);
assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId());
requestNode = objectMapper.createObjectNode();
requestNode.put("finished", false);
assertResultsPresentInPostDataResponse(url, requestNode, processInstance2.getId());
requestNode = objectMapper.createObjectNode();
requestNode.put("processDefinitionId", processInstance.getProcessDefinitionId());
assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
requestNode = objectMapper.createObjectNode();
requestNode.put("processDefinitionKey", "oneTaskProcess");
assertResultsPresentInPostDataResponse(url, requestNode, processInstance.getId(), processInstance2.getId());
requestNode = objectMapper.createObjectNode();
requestNode.put("processDefinitionKey", "oneTaskProcess");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + url + "?sort=startTime");
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK);
// Check status and size
JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
closeResponse(response);
assertEquals(2, dataNode.size());
assertEquals(processInstance.getId(), dataNode.get(0).get("id").asText());
assertEquals(processInstance2.getId(), dataNode.get(1).get("id").asText());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class HistoricProcessInstanceResourceTest method testGetProcessInstance.
/**
* Test retrieval of historic process instance.
* GET history/historic-process-instances/{processInstanceId}
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testGetProcessInstance() throws Exception {
ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder().processDefinitionKey("oneTaskProcess").processInstanceName("processName").start();
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE, processInstance.getId())), HttpStatus.SC_OK);
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals(processInstance.getId(), responseNode.get("id").textValue());
assertEquals("processName", responseNode.get("name").textValue());
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(task);
taskService.complete(task.getId());
response = executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_PROCESS_INSTANCE, processInstance.getId())), HttpStatus.SC_NO_CONTENT);
assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatusLine().getStatusCode());
closeResponse(response);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class HistoricVariableInstanceCollectionResourceTest method assertResultsPresentInDataResponse.
protected void assertResultsPresentInDataResponse(String url, int numberOfResultsExpected, String variableName, Object variableValue) throws JsonProcessingException, IOException {
// Do the actual call
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);
// Check status and size
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 dataElementNode = it.next();
JsonNode variableNode = dataElementNode.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 HistoricVariableInstanceQueryResourceTest 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, HttpStatus.SC_OK);
// Check status and size
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 dataElementNode = it.next();
JsonNode variableNode = dataElementNode.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 TableColumnsResourceTest method testGetTableColumns.
/**
* Test getting a single table's columns.
* GET management/tables/{tableName}/columns
*/
public void testGetTableColumns() throws Exception {
String tableName = managementService.getTableCount().keySet().iterator().next();
TableMetaData metaData = managementService.getTableMetaData(tableName);
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TABLE_COLUMNS, tableName)), HttpStatus.SC_OK);
// Check table
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals(tableName, responseNode.get("tableName").textValue());
ArrayNode names = (ArrayNode) responseNode.get("columnNames");
ArrayNode types = (ArrayNode) responseNode.get("columnTypes");
assertNotNull(names);
assertNotNull(types);
assertEquals(metaData.getColumnNames().size(), names.size());
assertEquals(metaData.getColumnTypes().size(), types.size());
for (int i = 0; i < names.size(); i++) {
assertEquals(names.get(i).textValue(), metaData.getColumnNames().get(i));
assertEquals(types.get(i).textValue(), metaData.getColumnTypes().get(i));
}
}
Aggregations