use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionCollectionResourceTest method testGetExecutions.
/**
* Test getting a list of executions, using all possible filters.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecutions() throws Exception {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
String id = processInstance.getId();
runtimeService.addUserIdentityLink(id, "kermit", "whatever");
Execution childExecution = runtimeService.createExecutionQuery().activityId("processTask").singleResult();
assertNotNull(childExecution);
// Test without any parameters
String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION);
assertResultsPresentInDataResponse(url, id, childExecution.getId());
// Process instance id
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?id=" + id;
assertResultsPresentInDataResponse(url, id);
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?id=anotherId";
assertResultsPresentInDataResponse(url);
// Process instance business key
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processInstanceBusinessKey=myBusinessKey";
assertResultsPresentInDataResponse(url, id);
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processInstanceBusinessKey=anotherBusinessKey";
assertResultsPresentInDataResponse(url);
// Process definition key
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionKey=processOne";
assertResultsPresentInDataResponse(url, id, childExecution.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionKey=processTwo";
assertResultsPresentInDataResponse(url);
// Process definition id
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionId=" + processInstance.getProcessDefinitionId();
assertResultsPresentInDataResponse(url, id, childExecution.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionId=anotherId";
assertResultsPresentInDataResponse(url);
// Parent id
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?parentId=" + id;
assertResultsPresentInDataResponse(url, childExecution.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?parentId=anotherId";
assertResultsPresentInDataResponse(url);
// Activity id
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?activityId=processTask";
assertResultsPresentInDataResponse(url, childExecution.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?activityId=anotherId";
assertResultsPresentInDataResponse(url);
// Without tenant ID, before tenant is set
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?withoutTenantId=true";
assertResultsPresentInDataResponse(url, id, childExecution.getId());
// Update the tenant for the deployment
managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));
// Without tenant ID, after tenant is set
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?withoutTenantId=true";
assertResultsPresentInDataResponse(url);
// Tenant id
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantId=myTenant";
assertResultsPresentInDataResponse(url, id, childExecution.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantId=myTenant2";
assertResultsPresentInDataResponse(url);
// Tenant id like
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantIdLike=" + encode("%enant");
assertResultsPresentInDataResponse(url, id, childExecution.getId());
url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantIdLike=" + encode("%whatever");
assertResultsPresentInDataResponse(url);
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionCollectionResourceTest method testSignalEventExecutionsWithvariables.
/**
* Test signalling all executions with variables
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" })
public void testSignalEventExecutionsWithvariables() throws Exception {
Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne");
assertNotNull(signalExecution);
ArrayNode variables = objectMapper.createArrayNode();
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "signalEventReceived");
requestNode.put("signalName", "alert");
requestNode.put("variables", variables);
ObjectNode varNode = objectMapper.createObjectNode();
variables.add(varNode);
varNode.put("name", "myVar");
varNode.put("value", "Variable set when signal event is receieved");
Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
assertNotNull(waitingExecution);
// Sending signal event causes the execution to end (scope-execution for the catching event)
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION));
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_NO_CONTENT));
// Check if process is moved on to the other wait-state
waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult();
assertNotNull(waitingExecution);
assertEquals(signalExecution.getId(), waitingExecution.getId());
Map<String, Object> vars = runtimeService.getVariables(waitingExecution.getId());
assertEquals(1, vars.size());
assertEquals("Variable set when signal event is receieved", vars.get("myVar"));
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionCollectionResourceTest method testSignalEventExecutions.
/**
* Test signalling all executions
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" })
public void testSignalEventExecutions() throws Exception {
Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne");
assertNotNull(signalExecution);
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "signalEventReceived");
requestNode.put("signalName", "alert");
Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
assertNotNull(waitingExecution);
// Sending signal event causes the execution to end (scope-execution for the catching event)
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION));
httpPut.setEntity(new StringEntity(requestNode.toString()));
closeResponse(executeRequest(httpPut, HttpStatus.SC_NO_CONTENT));
// Check if process is moved on to the other wait-state
waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult();
assertNotNull(waitingExecution);
assertEquals(signalExecution.getId(), waitingExecution.getId());
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionResourceTest method testGetExecution.
/**
* Test getting a single execution.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecution() throws Exception {
Execution parentExecution = runtimeService.startProcessInstanceByKey("processOne");
Execution childExecution = runtimeService.createExecutionQuery().activityId("processTask").singleResult();
assertNotNull(childExecution);
CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, parentExecution.getId())), HttpStatus.SC_OK);
// Check resulting parent execution
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals(parentExecution.getId(), responseNode.get("id").textValue());
assertTrue(responseNode.get("activityId").isNull());
assertFalse(responseNode.get("suspended").booleanValue());
assertTrue(responseNode.get("parentUrl").isNull());
assertFalse(responseNode.get("suspended").booleanValue());
assertTrue(responseNode.get("url").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, parentExecution.getId())));
assertTrue(responseNode.get("processInstanceUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, parentExecution.getId())));
// Check resulting child execution
response = executeRequest(new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, childExecution.getId())), HttpStatus.SC_OK);
responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertNotNull(responseNode);
assertEquals(childExecution.getId(), responseNode.get("id").textValue());
assertEquals("processTask", responseNode.get("activityId").textValue());
assertFalse(responseNode.get("suspended").booleanValue());
assertFalse(responseNode.get("suspended").booleanValue());
assertTrue(responseNode.get("url").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, childExecution.getId())));
assertTrue(responseNode.get("parentUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, parentExecution.getId())));
assertTrue(responseNode.get("processInstanceUrl").asText().endsWith(RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE, parentExecution.getId())));
}
use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.
the class ExecutionResourceTest method testSignalEventExecutionWithvariables.
/**
* Test signalling a single execution, with signal event.
*/
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-signal-event.bpmn20.xml" })
public void testSignalEventExecutionWithvariables() throws Exception {
Execution signalExecution = runtimeService.startProcessInstanceByKey("processOne");
assertNotNull(signalExecution);
ArrayNode variables = objectMapper.createArrayNode();
ObjectNode requestNode = objectMapper.createObjectNode();
requestNode.put("action", "signalEventReceived");
requestNode.put("signalName", "alert");
requestNode.put("variables", variables);
ObjectNode varNode = objectMapper.createObjectNode();
variables.add(varNode);
varNode.put("name", "myVar");
varNode.put("value", "Variable set when signal event is receieved");
Execution waitingExecution = runtimeService.createExecutionQuery().activityId("waitState").singleResult();
assertNotNull(waitingExecution);
// Sending signal event causes the execution to end (scope-execution for the catching event)
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION, waitingExecution.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_NO_CONTENT);
closeResponse(response);
// Check if process is moved on to the other wait-state
waitingExecution = runtimeService.createExecutionQuery().activityId("anotherWaitState").singleResult();
assertNotNull(waitingExecution);
assertEquals(signalExecution.getId(), waitingExecution.getId());
Map<String, Object> vars = runtimeService.getVariables(waitingExecution.getId());
assertEquals(1, vars.size());
assertEquals("Variable set when signal event is receieved", vars.get("myVar"));
}
Aggregations