use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionResourceTest method testIllegalExecutionAction.
/**
* Test executing an illegal action on an execution.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testIllegalExecutionAction() throws Exception {
Execution execution = runtimeService.startProcessInstanceByKey("processOne");
assertNotNull(execution);
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "badaction");
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, execution.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_BAD_REQUEST);
closeResponse(response);
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionVariableResourceTest method testGetExecutionVariable.
/**
* Test getting an execution variable. GET
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecutionVariable() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne");
runtimeService.setVariable(processInstance.getId(), "variable", "processValue");
Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
assertNotNull(childExecution);
runtimeService.setVariableLocal(childExecution.getId(), "variable", "childValue");
// Get local scope variable
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "variable")), HttpStatus.SC_OK);
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("local", responseNode.get("scope").asText());
assertEquals("childValue", responseNode.get("value").asText());
assertEquals("variable", responseNode.get("name").asText());
assertEquals("string", responseNode.get("type").asText());
// Get global scope variable
response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "variable") + "?scope=global"), HttpStatus.SC_OK);
responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals("global", responseNode.get("scope").asText());
assertEquals("processValue", responseNode.get("value").asText());
assertEquals("variable", responseNode.get("name").asText());
assertEquals("string", responseNode.get("type").asText());
// Illegal scope
response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, processInstance.getId(), "variable") + "?scope=illegal"), HttpStatus.SC_BAD_REQUEST);
closeResponse(response);
// Unexisting process
response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, "unexisting", "variable")), HttpStatus.SC_NOT_FOUND);
closeResponse(response);
// Unexisting variable
response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, processInstance.getId(), "unexistingVariable")), HttpStatus.SC_NOT_FOUND);
closeResponse(response);
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionVariableResourceTest method testGetExecutionVariableData.
/**
* Test getting execution variable data.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecutionVariableData() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne");
runtimeService.setVariableLocal(processInstance.getId(), "var", "This is a binary piece of text".getBytes());
Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
assertNotNull(childExecution);
runtimeService.setVariableLocal(childExecution.getId(), "var", "This is a binary piece of text in the child execution".getBytes());
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, childExecution.getId(), "var")), HttpStatus.SC_OK);
String actualResponseBytesAsText = IOUtils.toString(response.getEntity().getContent());
closeResponse(response);
assertEquals("This is a binary piece of text in the child execution", actualResponseBytesAsText);
assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());
// Test global scope
response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE_DATA, childExecution.getId(), "var") + "?scope=global"), HttpStatus.SC_OK);
actualResponseBytesAsText = IOUtils.toString(response.getEntity().getContent());
closeResponse(response);
assertEquals("This is a binary piece of text", actualResponseBytesAsText);
assertEquals("application/octet-stream", response.getEntity().getContentType().getValue());
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionVariableResourceTest method testDeleteExecutionVariable.
/**
* Test deleting a single execution variable, including "not found" check.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testDeleteExecutionVariable() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", Collections.singletonMap("myVariable", (Object) "processValue"));
Execution childExecution = runtimeService.createExecutionQuery().parentId(processInstance.getId()).singleResult();
assertNotNull(childExecution);
runtimeService.setVariableLocal(childExecution.getId(), "myVariable", "childValue");
// Delete variable local
HttpDelete httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "myVariable"));
CloseableHttpResponse response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
closeResponse(response);
assertFalse(runtimeService.hasVariableLocal(childExecution.getId(), "myVariable"));
// Global variable should remain unaffected
assertTrue(runtimeService.hasVariable(childExecution.getId(), "myVariable"));
// Delete variable global
httpDelete = new HttpDelete(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_VARIABLE, childExecution.getId(), "myVariable") + "?scope=global");
response = executeRequest(httpDelete, HttpStatus.SC_NO_CONTENT);
closeResponse(response);
assertFalse(runtimeService.hasVariableLocal(childExecution.getId(), "myVariable"));
assertFalse(runtimeService.hasVariable(childExecution.getId(), "myVariable"));
// Run the same delete again, variable is not there so 404 should be returned
response = executeRequest(httpDelete, HttpStatus.SC_NOT_FOUND);
closeResponse(response);
}
use of org.activiti.engine.runtime.Execution in project midpoint by Evolveum.
the class DumpVariables method dumpExecutionVariables.
private void dumpExecutionVariables(String executionId, DelegateExecution delegateExecution, Execution execution, Set<String> variablesSeen, RuntimeService runtimeService) {
Map<String, Object> variablesLocal = runtimeService.getVariablesLocal(executionId);
LOGGER.trace("Execution id={} ({} variables); class={}/{}", executionId, variablesLocal.size(), delegateExecution != null ? delegateExecution.getClass().getName() : null, execution != null ? execution.getClass().getName() : null);
TreeSet<String> names = new TreeSet<>(variablesLocal.keySet());
names.forEach(n -> LOGGER.trace(" - {} = {} {}", n, variablesLocal.get(n), variablesSeen.contains(n) ? "(dup)" : ""));
variablesSeen.addAll(variablesLocal.keySet());
if (delegateExecution instanceof ExecutionEntity) {
ExecutionEntity executionEntity = (ExecutionEntity) delegateExecution;
if (executionEntity.getParent() != null) {
dumpExecutionVariables(executionEntity.getParentId(), executionEntity.getParent(), null, variablesSeen, runtimeService);
}
} else if (delegateExecution instanceof ExecutionImpl) {
ExecutionImpl executionImpl = (ExecutionImpl) delegateExecution;
if (executionImpl.getParent() != null) {
dumpExecutionVariables(executionImpl.getParentId(), executionImpl.getParent(), null, variablesSeen, runtimeService);
}
} else {
Execution execution1 = runtimeService.createExecutionQuery().executionId(executionId).singleResult();
if (execution1 == null) {
LOGGER.trace("Execution with id {} was not found.", executionId);
} else if (execution1.getParentId() != null) {
Execution execution2 = runtimeService.createExecutionQuery().executionId(execution1.getParentId()).singleResult();
dumpExecutionVariables(execution.getParentId(), null, execution2, variablesSeen, runtimeService);
}
}
}
Aggregations