use of org.apache.http.entity.StringEntity in project Activiti by Activiti.
the class TaskCollectionResourceTest method testCreateTask.
/**
* Test creating a task.
* POST runtime/tasks
*/
public void testCreateTask() throws Exception {
try {
Task parentTask = taskService.newTask();
taskService.saveTask(parentTask);
ObjectNode requestNode = objectMapper.createObjectNode();
Calendar dueDate = Calendar.getInstance();
String dueDateString = getISODateString(dueDate.getTime());
requestNode.put("name", "New task name");
requestNode.put("description", "New task description");
requestNode.put("assignee", "assignee");
requestNode.put("owner", "owner");
requestNode.put("priority", 20);
requestNode.put("delegationState", "resolved");
requestNode.put("dueDate", dueDateString);
requestNode.put("parentTaskId", parentTask.getId());
requestNode.put("formKey", "testKey");
requestNode.put("tenantId", "test");
// Execute the request
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION));
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
String createdTaskId = responseNode.get("id").asText();
// Check if task is created with right arguments
Task task = taskService.createTaskQuery().taskId(createdTaskId).singleResult();
assertEquals("New task name", task.getName());
assertEquals("New task description", task.getDescription());
assertEquals("assignee", task.getAssignee());
assertEquals("owner", task.getOwner());
assertEquals(20, task.getPriority());
assertEquals(DelegationState.RESOLVED, task.getDelegationState());
assertEquals(dateFormat.parse(dueDateString), task.getDueDate());
assertEquals(parentTask.getId(), task.getParentTaskId());
assertEquals("testKey", task.getFormKey());
assertEquals("test", task.getTenantId());
} 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.http.entity.StringEntity in project Activiti by Activiti.
the class ProcessInstanceVariableResourceTest method testUpdateProcessVariable.
/**
* Test updating a single process variable, including "not found" check.
*
* PUT runtime/process-instances/{processInstanceId}/variables/{variableName}
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testUpdateProcessVariable() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("overlappingVariable", (Object) "processValue"));
runtimeService.setVariable(processInstance.getId(), "myVar", "value");
// Update variable
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("name", "myVar");
requestNode.put("value", "updatedValue");
requestNode.put("type", "string");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "myVar"));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("updatedValue", responseNode.get("value").asText());
// Try updating with mismatch between URL and body variableName
requestNode.put("name", "unexistingVariable");
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST));
// Try updating unexisting property
requestNode.put("name", "unexistingVariable");
httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "unexistingVariable"));
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_NOT_FOUND));
}
use of org.apache.http.entity.StringEntity in project Activiti by Activiti.
the class ProcessInstanceVariablesCollectionResourceTest method testCreateSingleProcessInstanceVariable.
/**
* Test creating a single process variable.
* POST runtime/process-instance/{processInstanceId}/variables
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" })
public void testCreateSingleProcessInstanceVariable() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
ArrayNode requestNode = objectMapper.createArrayNode();
ObjectNode variableNode = requestNode.addObject();
variableNode.put("name", "myVariable");
variableNode.put("value", "simple string value");
variableNode.put("type", "string");
// Create a new local variable
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()).get(0);
closeResponse(response);
assertNotNull(responseNode);
assertEquals("myVariable", responseNode.get("name").asText());
assertEquals("simple string value", responseNode.get("value").asText());
assertEquals("local", responseNode.get("scope").asText());
assertEquals("string", responseNode.get("type").asText());
assertNull(responseNode.get("valueUrl"));
assertTrue(runtimeService.hasVariableLocal(processInstance.getId(), "myVariable"));
assertEquals("simple string value", runtimeService.getVariableLocal(processInstance.getId(), "myVariable"));
}
use of org.apache.http.entity.StringEntity in project Activiti by Activiti.
the class ProcessInstanceVariablesCollectionResourceTest method testCreateMultipleProcessVariables.
/**
* Test creating multiple process variables in a single call.
* POST runtime/process-instance/{processInstanceId}/variables
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" })
public void testCreateMultipleProcessVariables() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
ArrayNode requestNode = objectMapper.createArrayNode();
// String variable
ObjectNode stringVarNode = requestNode.addObject();
stringVarNode.put("name", "stringVariable");
stringVarNode.put("value", "simple string value");
stringVarNode.put("type", "string");
// Integer
ObjectNode integerVarNode = requestNode.addObject();
integerVarNode.put("name", "integerVariable");
integerVarNode.put("value", 1234);
integerVarNode.put("type", "integer");
// Short
ObjectNode shortVarNode = requestNode.addObject();
shortVarNode.put("name", "shortVariable");
shortVarNode.put("value", 123);
shortVarNode.put("type", "short");
// Long
ObjectNode longVarNode = requestNode.addObject();
longVarNode.put("name", "longVariable");
longVarNode.put("value", 4567890L);
longVarNode.put("type", "long");
// Double
ObjectNode doubleVarNode = requestNode.addObject();
doubleVarNode.put("name", "doubleVariable");
doubleVarNode.put("value", 123.456);
doubleVarNode.put("type", "double");
// Boolean
ObjectNode booleanVarNode = requestNode.addObject();
booleanVarNode.put("name", "booleanVariable");
booleanVarNode.put("value", Boolean.TRUE);
booleanVarNode.put("type", "boolean");
// Date
Calendar varCal = Calendar.getInstance();
String isoString = getISODateString(varCal.getTime());
ObjectNode dateVarNode = requestNode.addObject();
dateVarNode.put("name", "dateVariable");
dateVarNode.put("value", isoString);
dateVarNode.put("type", "date");
// Create local variables with a single request
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_CREATED);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertTrue(responseNode.isArray());
assertEquals(7, responseNode.size());
// Check if engine has correct variables set
Map<String, Object> variables = runtimeService.getVariablesLocal(processInstance.getId());
assertEquals(7, variables.size());
assertEquals("simple string value", variables.get("stringVariable"));
assertEquals(1234, variables.get("integerVariable"));
assertEquals((short) 123, variables.get("shortVariable"));
assertEquals(4567890L, variables.get("longVariable"));
assertEquals(123.456, variables.get("doubleVariable"));
assertEquals(Boolean.TRUE, variables.get("booleanVariable"));
assertEquals(dateFormat.parse(isoString), variables.get("dateVariable"));
}
use of org.apache.http.entity.StringEntity in project Activiti by Activiti.
the class ProcessDefinitionIdentityLinksResourceTest method testAddCandidateStarterToUnexistingProcessDefinition.
public void testAddCandidateStarterToUnexistingProcessDefinition() throws Exception {
// Create user candidate
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("user", "kermit");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION_IDENTITYLINKS_COLLECTION, "unexisting"));
httpPost.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPost, HttpStatus.SC_NOT_FOUND);
closeResponse(response);
}
Aggregations