use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class TaskAttachmentResourceTest method testCreateAttachmentWithContent.
/**
* Test creating a single attachments for a task, using multipart-request to supply content
* POST runtime/tasks/{taskId}/attachments/{attachmentId}
*/
public void testCreateAttachmentWithContent() throws Exception {
try {
Task task = taskService.newTask();
taskService.saveTask(task);
InputStream binaryContent = new ByteArrayInputStream("This is binary content".getBytes());
// Add name, type and scope
Map<String, String> additionalFields = new HashMap<String, String>();
additionalFields.put("name", "An attachment");
additionalFields.put("description", "An attachment description");
additionalFields.put("type", "myType");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_COLLECTION, task.getId()));
httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/octet-stream", binaryContent, additionalFields));
CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED);
// Check if attachment is created
List<Attachment> attachments = taskService.getTaskAttachments(task.getId());
assertEquals(1, attachments.size());
Attachment binaryAttachment = attachments.get(0);
assertEquals("This is binary content", IOUtils.toString(taskService.getAttachmentContent(binaryAttachment.getId())));
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertEquals(binaryAttachment.getId(), responseNode.get("id").textValue());
assertEquals("myType", responseNode.get("type").textValue());
assertEquals("An attachment", responseNode.get("name").textValue());
assertEquals("An attachment description", responseNode.get("description").textValue());
assertTrue(responseNode.get("url").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT, task.getId(), binaryAttachment.getId())));
assertTrue(responseNode.get("contentUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_ATTACHMENT_DATA, task.getId(), binaryAttachment.getId())));
assertTrue(responseNode.get("taskUrl").textValue().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK, task.getId())));
assertTrue(responseNode.get("externalUrl").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);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class ProcessDefinitionCollectionResourceTest method testGetProcessDefinitions.
/**
* Test getting process definitions.
* GET repository/process-definitions
*/
public void testGetProcessDefinitions() throws Exception {
try {
Deployment firstDeployment = repositoryService.createDeployment().name("Deployment 1").addClasspathResource("org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml").deploy();
Deployment secondDeployment = repositoryService.createDeployment().name("Deployment 2").addClasspathResource("org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml").addClasspathResource("org/activiti/rest/service/api/repository/twoTaskProcess.bpmn20.xml").deploy();
Deployment thirdDeployment = repositoryService.createDeployment().name("Deployment 3").addClasspathResource("org/activiti/rest/service/api/repository/oneTaskProcessWithDi.bpmn20.xml").deploy();
ProcessDefinition oneTaskProcess = repositoryService.createProcessDefinitionQuery().processDefinitionKey("oneTaskProcess").deploymentId(firstDeployment.getId()).singleResult();
ProcessDefinition latestOneTaskProcess = repositoryService.createProcessDefinitionQuery().processDefinitionKey("oneTaskProcess").deploymentId(secondDeployment.getId()).singleResult();
ProcessDefinition twoTaskprocess = repositoryService.createProcessDefinitionQuery().processDefinitionKey("twoTaskProcess").deploymentId(secondDeployment.getId()).singleResult();
ProcessDefinition oneTaskWithDiProcess = repositoryService.createProcessDefinitionQuery().processDefinitionKey("oneTaskProcessWithDi").deploymentId(thirdDeployment.getId()).singleResult();
// Test parameterless call
String baseUrl = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION_COLLECTION);
assertResultsPresentInDataResponse(baseUrl, oneTaskProcess.getId(), twoTaskprocess.getId(), latestOneTaskProcess.getId(), oneTaskWithDiProcess.getId());
// Verify ACT-2141 Persistent isGraphicalNotation flag for process definitions
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + baseUrl), HttpStatus.SC_OK);
JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
closeResponse(response);
for (int i = 0; i < dataNode.size(); i++) {
JsonNode processDefinitionJson = dataNode.get(i);
String key = processDefinitionJson.get("key").asText();
JsonNode graphicalNotationNode = processDefinitionJson.get("graphicalNotationDefined");
if (key.equals("oneTaskProcessWithDi")) {
assertTrue(graphicalNotationNode.asBoolean());
} else {
assertFalse(graphicalNotationNode.asBoolean());
}
}
// Verify
// Test name filtering
String url = baseUrl + "?name=" + encode("The Two Task Process");
assertResultsPresentInDataResponse(url, twoTaskprocess.getId());
// Test nameLike filtering
url = baseUrl + "?nameLike=" + encode("The Two%");
assertResultsPresentInDataResponse(url, twoTaskprocess.getId());
// Test key filtering
url = baseUrl + "?key=twoTaskProcess";
assertResultsPresentInDataResponse(url, twoTaskprocess.getId());
// Test returning multiple versions for the same key
url = baseUrl + "?key=oneTaskProcess";
assertResultsPresentInDataResponse(url, oneTaskProcess.getId(), latestOneTaskProcess.getId());
// Test keyLike filtering
url = baseUrl + "?keyLike=" + encode("two%");
assertResultsPresentInDataResponse(url, twoTaskprocess.getId());
// Test category filtering
url = baseUrl + "?category=TwoTaskCategory";
assertResultsPresentInDataResponse(url, twoTaskprocess.getId());
// Test categoryLike filtering
url = baseUrl + "?categoryLike=" + encode("Two%");
assertResultsPresentInDataResponse(url, twoTaskprocess.getId());
// Test categoryNotEquals filtering
url = baseUrl + "?categoryNotEquals=OneTaskCategory";
assertResultsPresentInDataResponse(url, twoTaskprocess.getId(), oneTaskWithDiProcess.getId());
// Test resourceName filtering
url = baseUrl + "?resourceName=org/activiti/rest/service/api/repository/twoTaskProcess.bpmn20.xml";
assertResultsPresentInDataResponse(url, twoTaskprocess.getId());
// Test resourceNameLike filtering
url = baseUrl + "?resourceNameLike=" + encode("%twoTaskProcess%");
assertResultsPresentInDataResponse(url, twoTaskprocess.getId());
// Test version filtering
url = baseUrl + "?version=2";
assertResultsPresentInDataResponse(url, latestOneTaskProcess.getId());
// Test latest filtering
url = baseUrl + "?latest=true";
assertResultsPresentInDataResponse(url, latestOneTaskProcess.getId(), twoTaskprocess.getId(), oneTaskWithDiProcess.getId());
url = baseUrl + "?latest=false";
assertResultsPresentInDataResponse(baseUrl, oneTaskProcess.getId(), twoTaskprocess.getId(), latestOneTaskProcess.getId(), oneTaskWithDiProcess.getId());
// Test deploymentId
url = baseUrl + "?deploymentId=" + secondDeployment.getId();
assertResultsPresentInDataResponse(url, twoTaskprocess.getId(), latestOneTaskProcess.getId());
// Test startableByUser
url = baseUrl + "?startableByUser=kermit";
assertResultsPresentInDataResponse(url, twoTaskprocess.getId());
// Test suspended
repositoryService.suspendProcessDefinitionById(twoTaskprocess.getId());
url = baseUrl + "?suspended=true";
assertResultsPresentInDataResponse(url, twoTaskprocess.getId());
url = baseUrl + "?suspended=false";
assertResultsPresentInDataResponse(url, latestOneTaskProcess.getId(), oneTaskProcess.getId(), oneTaskWithDiProcess.getId());
} 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.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class BaseSpringRestTestCase method assertResultsPresentInDataResponse.
/**
* Checks if the returned "data" array (child-node of root-json node returned by invoking a GET on the given url)
* contains entries with the given ID's.
*/
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), 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
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-definitions 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 BaseSpringRestTestCase method assertResultsPresentInPostDataResponseWithStatusCheck.
protected void assertResultsPresentInPostDataResponseWithStatusCheck(String url, ObjectNode body, int expectedStatusCode, String... expectedResourceIds) throws JsonProcessingException, IOException {
int numberOfResultsExpected = 0;
if (expectedResourceIds != null) {
numberOfResultsExpected = expectedResourceIds.length;
}
// Do the actual call
HttpPost post = new HttpPost(SERVER_URL_PREFIX + url);
post.setEntity(new StringEntity(body.toString()));
CloseableHttpResponse response = executeRequest(post, expectedStatusCode);
if (expectedStatusCode == HttpStatus.SC_OK) {
// Check status and size
JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
JsonNode dataNode = rootNode.get("data");
assertEquals(numberOfResultsExpected, dataNode.size());
// Check presence of ID's
if (expectedResourceIds != null) {
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 entries have been found in result, missing: " + StringUtils.join(toBeFound, ", "), toBeFound.isEmpty());
}
}
closeResponse(response);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project Activiti by Activiti.
the class FormDataResourceTest method testSubmitFormData.
@Deployment
public void testSubmitFormData() throws Exception {
Map<String, Object> variableMap = new HashMap<String, Object>();
variableMap.put("SpeakerName", "John Doe");
Address address = new Address();
variableMap.put("address", address);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap);
String processInstanceId = processInstance.getId();
String processDefinitionId = processInstance.getProcessDefinitionId();
Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("taskId", task.getId());
ArrayNode propertyArray = objectMapper.createArrayNode();
requestNode.put("properties", propertyArray);
ObjectNode propNode = objectMapper.createObjectNode();
propNode.put("id", "room");
propNode.put("value", 123l);
propertyArray.add(propNode);
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA));
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_INTERNAL_SERVER_ERROR));
propNode = objectMapper.createObjectNode();
propNode.put("id", "street");
propNode.put("value", "test");
propertyArray.add(propNode);
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT));
task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
assertNull(task);
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertNull(processInstance);
List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
Map<String, HistoricVariableInstance> historyMap = new HashMap<String, HistoricVariableInstance>();
for (HistoricVariableInstance historicVariableInstance : variables) {
historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance);
}
assertEquals("123", historyMap.get("room").getValue());
assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId());
processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap);
processInstanceId = processInstance.getId();
task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
requestNode.put("taskId", task.getId());
propNode = objectMapper.createObjectNode();
propNode.put("id", "direction");
propNode.put("value", "nowhere");
propertyArray.add(propNode);
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
propNode.put("value", "up");
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPost, HttpStatus.SC_NO_CONTENT));
task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
assertNull(task);
processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
assertNull(processInstance);
variables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
historyMap.clear();
for (HistoricVariableInstance historicVariableInstance : variables) {
historyMap.put(historicVariableInstance.getVariableName(), historicVariableInstance);
}
assertEquals("123", historyMap.get("room").getValue());
assertEquals(processInstanceId, historyMap.get("room").getProcessInstanceId());
assertEquals("up", historyMap.get("direction").getValue());
requestNode = objectMapper.createObjectNode();
requestNode.put("processDefinitionId", processDefinitionId);
propertyArray = objectMapper.createArrayNode();
requestNode.put("properties", propertyArray);
propNode = objectMapper.createObjectNode();
propNode.put("id", "number");
propNode.put("value", 123);
propertyArray.add(propNode);
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode.get("id").asText());
assertEquals(processDefinitionId, responseNode.get("processDefinitionId").asText());
task = taskService.createTaskQuery().processInstanceId(responseNode.get("id").asText()).singleResult();
assertNotNull(task);
}
Aggregations