use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class TaskVariableResourceTest method testGetTaskVariableDataForIllegalVariables.
/**
* Test getting a task variable. GET
* runtime/tasks/{taskId}/variables/{variableName}/data
*/
public void testGetTaskVariableDataForIllegalVariables() throws Exception {
try {
// Test variable behaviour on standalone tasks
Task task = taskService.newTask();
taskService.saveTask(task);
taskService.setVariableLocal(task.getId(), "localTaskVariable", "this is a plain string variable");
// Try getting data for non-binary variable
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE_DATA, task.getId(), "localTaskVariable")), HttpStatus.SC_NOT_FOUND));
// Try getting data for unexisting property
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE_DATA, task.getId(), "unexistingVariable")), HttpStatus.SC_NOT_FOUND));
} 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.activiti.engine.task.Task in project Activiti by Activiti.
the class TaskVariableResourceTest method testDeleteTaskVariable.
/**
* Test deleting a single task variable in all scopes, including "not found" check.
*
* DELETE runtime/tasks/{taskId}/variables/{variableName}
*/
@Deployment
public void testDeleteTaskVariable() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("overlappingVariable", (Object) "processValue"));
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
taskService.setVariableLocal(task.getId(), "overlappingVariable", "taskValue");
taskService.setVariableLocal(task.getId(), "anotherTaskVariable", "taskValue");
// Delete variable without scope, local should be presumed -> local removed and global should be retained
HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE, task.getId(), "overlappingVariable"));
closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
assertFalse(taskService.hasVariableLocal(task.getId(), "overlappingVariable"));
assertTrue(taskService.hasVariable(task.getId(), "overlappingVariable"));
// Delete local scope variable
httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE, task.getId(), "anotherTaskVariable") + "?scope=local");
closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
assertFalse(taskService.hasVariableLocal(task.getId(), "anotherTaskVariable"));
// Delete global scope variable
assertTrue(taskService.hasVariable(task.getId(), "overlappingVariable"));
httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE, task.getId(), "overlappingVariable") + "?scope=global");
closeResponse(executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
assertFalse(taskService.hasVariable(task.getId(), "overlappingVariable"));
// Run the same delete again, variable is not there so 404 should be returned
closeResponse(executeRequest(httpDelete, HttpStatus.SC_NOT_FOUND));
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class TaskVariablesCollectionResourceTest method testDeleteAllLocalVariables.
/**
* Test deleting all local task variables.
* DELETE runtime/tasks/{taskId}/variables
*/
@Deployment
public void testDeleteAllLocalVariables() throws Exception {
// Start process with all types of variables
Map<String, Object> processVariables = new HashMap<String, Object>();
processVariables.put("var1", "This is a ProcVariable");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
// Set local task variables
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
Map<String, Object> taskVariables = new HashMap<String, Object>();
taskVariables.put("var1", "This is a TaskVariable");
taskVariables.put("var2", 123);
taskService.setVariablesLocal(task.getId(), taskVariables);
assertEquals(2, taskService.getVariablesLocal(task.getId()).size());
HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
closeResponse(executeBinaryRequest(httpDelete, HttpStatus.SC_NO_CONTENT));
// Check if local variables are gone and global remain unchanged
assertEquals(0, taskService.getVariablesLocal(task.getId()).size());
assertEquals(1, taskService.getVariables(task.getId()).size());
}
use of org.activiti.engine.task.Task in project Activiti by Activiti.
the class TaskVariablesCollectionResourceTest method testCreateSingleSerializableTaskVariable.
/**
* Test creating a single task variable using a binary stream.
* POST runtime/tasks/{taskId}/variables
*/
public void testCreateSingleSerializableTaskVariable() throws Exception {
try {
Task task = taskService.newTask();
taskService.saveTask(task);
TestSerializableVariable serializable = new TestSerializableVariable();
serializable.setSomeField("some value");
// Serialize object to readable stream for representation
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream output = new ObjectOutputStream(buffer);
output.writeObject(serializable);
output.close();
InputStream binaryContent = new ByteArrayInputStream(buffer.toByteArray());
// Add name, type and scope
Map<String, String> additionalFields = new HashMap<String, String>();
additionalFields.put("name", "serializableVariable");
additionalFields.put("type", "serializable");
additionalFields.put("scope", "local");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
httpPost.setEntity(HttpMultipartHelper.getMultiPartEntity("value", "application/x-java-serialized-object", binaryContent, additionalFields));
CloseableHttpResponse response = executeBinaryRequest(httpPost, HttpStatus.SC_CREATED);
// Check "CREATED" status
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("serializableVariable", responseNode.get("name").asText());
assertTrue(responseNode.get("value").isNull());
assertEquals("local", responseNode.get("scope").asText());
assertEquals("serializable", responseNode.get("type").asText());
assertNotNull(responseNode.get("valueUrl").isNull());
assertTrue(responseNode.get("valueUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLE_DATA, task.getId(), "serializableVariable")));
// Check actual value of variable in engine
Object variableValue = taskService.getVariableLocal(task.getId(), "serializableVariable");
assertNotNull(variableValue);
assertTrue(variableValue instanceof TestSerializableVariable);
assertEquals("some value", ((TestSerializableVariable) variableValue).getSomeField());
} 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.activiti.engine.task.Task in project Activiti by Activiti.
the class TaskVariablesCollectionResourceTest method testCreateSingleTaskVariableDefaultTypes.
/**
* Test creating a single task variable, testing default types when omitted.
* POST runtime/tasks/{taskId}/variables
*/
public void testCreateSingleTaskVariableDefaultTypes() throws Exception {
try {
Task task = taskService.newTask();
taskService.saveTask(task);
// String type detection
ArrayNode requestNode = objectMapper.createArrayNode();
ObjectNode varNode = requestNode.addObject();
varNode.put("name", "stringVar");
varNode.put("value", "String value");
varNode.put("scope", "local");
HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED));
assertEquals("String value", taskService.getVariable(task.getId(), "stringVar"));
// Integer type detection
varNode.put("name", "integerVar");
varNode.put("value", 123);
varNode.put("scope", "local");
httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED));
assertEquals(123, taskService.getVariable(task.getId(), "integerVar"));
// Double type detection
varNode.put("name", "doubleVar");
varNode.put("value", 123.456);
varNode.put("scope", "local");
httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED));
assertEquals(123.456, taskService.getVariable(task.getId(), "doubleVar"));
// Boolean type detection
varNode.put("name", "booleanVar");
varNode.put("value", Boolean.TRUE);
varNode.put("scope", "local");
httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_VARIABLES_COLLECTION, task.getId()));
httpPost.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeBinaryRequest(httpPost, HttpStatus.SC_CREATED));
assertEquals(Boolean.TRUE, taskService.getVariable(task.getId(), "booleanVar"));
} finally {
// Clean adhoc-tasks even if test fails
List<Task> tasks = taskService.createTaskQuery().list();
for (Task task : tasks) {
taskService.deleteTask(task.getId(), true);
}
}
}
Aggregations