use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class ProcessInstanceVariableResourceTest method testGetProcessInstanceVariable.
/**
* Test getting a process instance variable. GET
* runtime/process-instances/{processInstanceId}/variables/{variableName}
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testGetProcessInstanceVariable() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
runtimeService.setVariable(processInstance.getId(), "variable", "processValue");
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "variable")), HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("processValue", responseNode.get("value").asText());
assertEquals("variable", responseNode.get("name").asText());
assertEquals("string", responseNode.get("type").asText());
// Illegal scope
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "variable") + "?scope=illegal"), HttpStatus.SC_BAD_REQUEST));
// Unexisting process
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, "unexisting", "variable")), HttpStatus.SC_NOT_FOUND));
// Unexisting variable
closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "unexistingVariable")), HttpStatus.SC_NOT_FOUND));
}
use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class ProcessInstanceVariableResourceTest method testDeleteProcessVariable.
/**
* Test deleting a single process variable in, including "not found" check.
*
* DELETE runtime/process-instances/{processInstanceId}/variables/{variableName}
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testDeleteProcessVariable() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Collections.singletonMap("myVariable", (Object) "processValue"));
// Delete variable
closeResponse(executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "myVariable")), HttpStatus.SC_NO_CONTENT));
assertFalse(runtimeService.hasVariable(processInstance.getId(), "myVariable"));
// Run the same delete again, variable is not there so 404 should be returned
closeResponse(executeRequest(new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE, processInstance.getId(), "myVariable")), HttpStatus.SC_NOT_FOUND));
}
use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class ProcessInstanceVariableResourceTest method testGetProcessInstanceVariableDataSerializable.
/**
* Test getting a process instance variable data.
* GET runtime/process-instances/{processInstanceId}/variables/{variableName}
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariableResourceTest.testProcess.bpmn20.xml" })
public void testGetProcessInstanceVariableDataSerializable() throws Exception {
TestSerializableVariable originalSerializable = new TestSerializableVariable();
originalSerializable.setSomeField("This is some field");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
runtimeService.setVariableLocal(processInstance.getId(), "var", originalSerializable);
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_DATA, processInstance.getId(), "var")), HttpStatus.SC_OK);
// Read the serializable from the stream
ObjectInputStream stream = new ObjectInputStream(response.getEntity().getContent());
Object readSerializable = stream.readObject();
assertNotNull(readSerializable);
assertTrue(readSerializable instanceof TestSerializableVariable);
assertEquals("This is some field", ((TestSerializableVariable) readSerializable).getSomeField());
assertEquals("application/x-java-serialized-object", response.getEntity().getContentType().getValue());
closeResponse(response);
}
use of org.activiti.engine.test.Deployment in project Activiti by Activiti.
the class ProcessInstanceVariablesCollectionResourceTest method testGetProcessVariables.
/**
* Test getting all process variables.
* GET runtime/process-instances/{processInstanceId}/variables
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" })
public void testGetProcessVariables() throws Exception {
Calendar cal = Calendar.getInstance();
// Start process with all types of variables
Map<String, Object> processVariables = new HashMap<String, Object>();
processVariables.put("stringProcVar", "This is a ProcVariable");
processVariables.put("intProcVar", 123);
processVariables.put("longProcVar", 1234L);
processVariables.put("shortProcVar", (short) 123);
processVariables.put("doubleProcVar", 99.99);
processVariables.put("booleanProcVar", Boolean.TRUE);
processVariables.put("dateProcVar", cal.getTime());
processVariables.put("byteArrayProcVar", "Some raw bytes".getBytes());
processVariables.put("overlappingVariable", "process-value");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables);
// Request all variables (no scope provides) which include global an local
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId())), HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertTrue(responseNode.isArray());
assertEquals(9, responseNode.size());
}
use of org.activiti.engine.test.Deployment 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"));
}
Aggregations