Search in sources :

Example 46 with Deployment

use of org.activiti.engine.test.Deployment 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());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) Execution(org.activiti.engine.runtime.Execution) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Example 47 with Deployment

use of org.activiti.engine.test.Deployment 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())));
}
Also used : Execution(org.activiti.engine.runtime.Execution) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Example 48 with Deployment

use of org.activiti.engine.test.Deployment 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"));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) Execution(org.activiti.engine.runtime.Execution) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Example 49 with Deployment

use of org.activiti.engine.test.Deployment 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);
}
Also used : StringEntity(org.apache.http.entity.StringEntity) Execution(org.activiti.engine.runtime.Execution) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Example 50 with Deployment

use of org.activiti.engine.test.Deployment in project Activiti by Activiti.

the class ProcessInstanceCollectionResourceTest method testGetProcessInstancesByBusinessKeyAndIncludeVariables.

// check if process instance query with business key with and without includeProcess Variables
// related to https://activiti.atlassian.net/browse/ACT-1992
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testGetProcessInstancesByBusinessKeyAndIncludeVariables() throws Exception {
    HashMap<String, Object> variables = new HashMap<String, Object>();
    variables.put("myVar1", "myVar1");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey", variables);
    String processId = processInstance.getId();
    // check that the right process is returned with no variables
    String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?businessKey=myBusinessKey";
    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);
    JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertTrue(rootNode.size() > 0);
    assertEquals(1, rootNode.get("data").size());
    JsonNode dataNode = rootNode.get("data").get(0);
    assertEquals(processId, dataNode.get("id").asText());
    assertEquals(processInstance.getProcessDefinitionId(), dataNode.get("processDefinitionId").asText());
    assertTrue(dataNode.get("processDefinitionUrl").asText().contains(processInstance.getProcessDefinitionId()));
    JsonNode variableNodes = dataNode.get("variables");
    assertEquals(0, variableNodes.size());
    // check that the right process is returned along with the variables when includeProcessvariable is set
    url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?businessKey=myBusinessKey&includeProcessVariables=true";
    response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);
    rootNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertTrue(rootNode.size() > 0);
    assertEquals(1, rootNode.get("data").size());
    dataNode = rootNode.get("data").get(0);
    assertEquals(processId, dataNode.get("id").textValue());
    assertEquals(processInstance.getProcessDefinitionId(), dataNode.get("processDefinitionId").asText());
    assertTrue(dataNode.get("processDefinitionUrl").asText().contains(processInstance.getProcessDefinitionId()));
    variableNodes = dataNode.get("variables");
    assertEquals(1, variableNodes.size());
    variableNodes = dataNode.get("variables");
    assertEquals(1, variableNodes.size());
    assertNotNull(variableNodes.get(0).get("name"));
    assertNotNull(variableNodes.get(0).get("value"));
    assertEquals("myVar1", variableNodes.get(0).get("name").asText());
    assertEquals("myVar1", variableNodes.get(0).get("value").asText());
}
Also used : HashMap(java.util.HashMap) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JsonNode(com.fasterxml.jackson.databind.JsonNode) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Deployment (org.activiti.engine.test.Deployment)1178 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)846 Task (org.activiti.engine.task.Task)549 HashMap (java.util.HashMap)277 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)218 Execution (org.activiti.engine.runtime.Execution)151 Date (java.util.Date)94 Job (org.activiti.engine.runtime.Job)91 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)87 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)87 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)85 JsonNode (com.fasterxml.jackson.databind.JsonNode)66 Calendar (java.util.Calendar)63 DelegateTask (org.activiti.engine.delegate.DelegateTask)52 StringEntity (org.apache.http.entity.StringEntity)50 ArrayList (java.util.ArrayList)49 HttpGet (org.apache.http.client.methods.HttpGet)49 HistoricActivityInstance (org.activiti.engine.history.HistoricActivityInstance)41 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)34 ActivitiException (org.activiti.engine.ActivitiException)31