Search in sources :

Example 11 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class TransactionSubProcessTest method testSimpleCaseTxSuccessful.

@Deployment(resources = { "org/activiti/engine/test/bpmn/subprocess/transaction/TransactionSubProcessTest.testSimpleCase.bpmn20.xml" })
public void testSimpleCaseTxSuccessful() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transactionProcess");
    // after the process is started, we have compensate event subscriptions:
    assertEquals(5, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").count());
    assertEquals(1, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").count());
    // the task is present:
    Task task = taskService.createTaskQuery().singleResult();
    assertNotNull(task);
    // making the tx succeed:
    taskService.setVariable(task.getId(), "confirmed", true);
    taskService.complete(task.getId());
    // now the process instance execution is sitting in the 'afterSuccess' task 
    // -> has left the transaction using the "normal" sequence flow
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(processInstance.getId());
    assertTrue(activeActivityIds.contains("afterSuccess"));
    // there is a compensate event subscription for the transaction under the process instance
    EventSubscriptionEntity eventSubscriptionEntity = createEventSubscriptionQuery().eventType("compensate").activityId("tx").executionId(processInstance.getId()).singleResult();
    // there is an event-scope execution associated with the event-subscription:
    assertNotNull(eventSubscriptionEntity.getConfiguration());
    Execution eventScopeExecution = runtimeService.createExecutionQuery().executionId(eventSubscriptionEntity.getConfiguration()).singleResult();
    assertNotNull(eventScopeExecution);
    // we still have compensate event subscriptions for the compensation handlers, only now they are part of the event scope
    assertEquals(5, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookHotel").executionId(eventScopeExecution.getId()).count());
    assertEquals(1, createEventSubscriptionQuery().eventType("compensate").activityId("undoBookFlight").executionId(eventScopeExecution.getId()).count());
    assertEquals(1, createEventSubscriptionQuery().eventType("compensate").activityId("undoChargeCard").executionId(eventScopeExecution.getId()).count());
    // assert that the compensation handlers have not been invoked:
    assertNull(runtimeService.getVariable(processInstance.getId(), "undoBookHotel"));
    assertNull(runtimeService.getVariable(processInstance.getId(), "undoBookFlight"));
    assertNull(runtimeService.getVariable(processInstance.getId(), "undoChargeCard"));
    // end the process instance
    runtimeService.signal(processInstance.getId());
    assertProcessEnded(processInstance.getId());
    assertEquals(0, runtimeService.createExecutionQuery().count());
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity) Deployment(org.activiti.engine.test.Deployment)

Example 12 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ExecutionQueryTest method testClashingValues.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testClashingValues() throws Exception {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("var", 1234L);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    Map<String, Object> vars2 = new HashMap<String, Object>();
    vars2.put("var", 1234);
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars2);
    List<Execution> executions = runtimeService.createExecutionQuery().processDefinitionKey("oneTaskProcess").variableValueEquals("var", 1234L).list();
    assertEquals(1, executions.size());
    assertEquals(processInstance.getId(), executions.get(0).getProcessInstanceId());
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 13 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ExecutionQueryTest method testQueryNullVariable.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryNullVariable() throws Exception {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("nullVar", null);
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("nullVar", "notnull");
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("nullVarLong", "notnull");
    ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("nullVarDouble", "notnull");
    ProcessInstance processInstance4 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("nullVarByte", "testbytes".getBytes());
    ProcessInstance processInstance5 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    // Query on null value, should return one value
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("nullVar", null);
    List<Execution> executions = query.list();
    assertNotNull(executions);
    assertEquals(1, executions.size());
    assertEquals(processInstance1.getId(), executions.get(0).getId());
    // Test NOT_EQUALS null
    assertEquals(1, runtimeService.createExecutionQuery().variableValueNotEquals("nullVar", null).count());
    assertEquals(1, runtimeService.createExecutionQuery().variableValueNotEquals("nullVarLong", null).count());
    assertEquals(1, runtimeService.createExecutionQuery().variableValueNotEquals("nullVarDouble", null).count());
    // When a byte-array refrence is present, the variable is not considered null
    assertEquals(1, runtimeService.createExecutionQuery().variableValueNotEquals("nullVarByte", null).count());
    // Test value-only matching
    Execution execution = runtimeService.createExecutionQuery().variableValueEquals(null).singleResult();
    assertNotNull(execution);
    assertEquals(processInstance1.getId(), execution.getId());
    // All other variable queries with null should throw exception
    try {
        runtimeService.createExecutionQuery().variableValueGreaterThan("nullVar", null);
        fail("Excetion expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertTextPresent("Booleans and null cannot be used in 'greater than' condition", ae.getMessage());
    }
    try {
        runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("nullVar", null);
        fail("Excetion expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertTextPresent("Booleans and null cannot be used in 'greater than or equal' condition", ae.getMessage());
    }
    try {
        runtimeService.createExecutionQuery().variableValueLessThan("nullVar", null);
        fail("Excetion expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertTextPresent("Booleans and null cannot be used in 'less than' condition", ae.getMessage());
    }
    try {
        runtimeService.createExecutionQuery().variableValueLessThanOrEqual("nullVar", null);
        fail("Excetion expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertTextPresent("Booleans and null cannot be used in 'less than or equal' condition", ae.getMessage());
    }
    try {
        runtimeService.createExecutionQuery().variableValueLike("nullVar", null);
        fail("Excetion expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertTextPresent("Only string values can be used with 'like' condition", ae.getMessage());
    }
    runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance3.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance4.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance5.getId(), "test");
    // Test value-only matching, non-null processes exist
    execution = runtimeService.createExecutionQuery().variableValueEquals(null).singleResult();
    assertNull(execution);
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Deployment(org.activiti.engine.test.Deployment)

Example 14 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ExecutionQueryTest method testQueryVariablesUpdatedToNullValue.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryVariablesUpdatedToNullValue() {
    // Start process instance with different types of variables
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("longVar", 928374L);
    variables.put("shortVar", (short) 123);
    variables.put("integerVar", 1234);
    variables.put("stringVar", "coca-cola");
    variables.put("booleanVar", true);
    variables.put("dateVar", new Date());
    variables.put("nullVar", null);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("longVar", null).variableValueEquals("shortVar", null).variableValueEquals("integerVar", null).variableValueEquals("stringVar", null).variableValueEquals("booleanVar", null).variableValueEquals("dateVar", null);
    ExecutionQuery notQuery = runtimeService.createExecutionQuery().variableValueNotEquals("longVar", null).variableValueNotEquals("shortVar", null).variableValueNotEquals("integerVar", null).variableValueNotEquals("stringVar", null).variableValueNotEquals("booleanVar", null).variableValueNotEquals("dateVar", null);
    assertNull(query.singleResult());
    assertNotNull(notQuery.singleResult());
    // Set all existing variables values to null
    runtimeService.setVariable(processInstance.getId(), "longVar", null);
    runtimeService.setVariable(processInstance.getId(), "shortVar", null);
    runtimeService.setVariable(processInstance.getId(), "integerVar", null);
    runtimeService.setVariable(processInstance.getId(), "stringVar", null);
    runtimeService.setVariable(processInstance.getId(), "booleanVar", null);
    runtimeService.setVariable(processInstance.getId(), "dateVar", null);
    runtimeService.setVariable(processInstance.getId(), "nullVar", null);
    Execution queryResult = query.singleResult();
    assertNotNull(queryResult);
    assertEquals(processInstance.getId(), queryResult.getId());
    assertNull(notQuery.singleResult());
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 15 with Execution

use of org.activiti.engine.runtime.Execution in project Activiti by Activiti.

the class ExecutionQueryTest method testQueryBySignalSubscriptionNameBoundary.

@Deployment
public void testQueryBySignalSubscriptionNameBoundary() {
    runtimeService.startProcessInstanceByKey("signalProces");
    // it finds subscribed instances
    Execution execution = runtimeService.createExecutionQuery().signalEventSubscription("Test signal").singleResult();
    assertNotNull(execution);
    // test query for nonexisting subscription
    execution = runtimeService.createExecutionQuery().signalEventSubscription("nonExisitng").singleResult();
    assertNull(execution);
    // it finds more than one
    runtimeService.startProcessInstanceByKey("signalProces");
    assertEquals(2, runtimeService.createExecutionQuery().signalEventSubscription("Test signal").count());
}
Also used : Execution(org.activiti.engine.runtime.Execution) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Execution (org.activiti.engine.runtime.Execution)131 Deployment (org.activiti.engine.test.Deployment)105 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)75 Task (org.activiti.engine.task.Task)33 HashMap (java.util.HashMap)30 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 DelegateExecution (org.activiti.engine.delegate.DelegateExecution)12 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)12 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)10 ExecutionQuery (org.activiti.engine.runtime.ExecutionQuery)10 HttpPut (org.apache.http.client.methods.HttpPut)10 StringEntity (org.apache.http.entity.StringEntity)9 ArrayList (java.util.ArrayList)8 ActivitiException (org.activiti.engine.ActivitiException)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 Date (java.util.Date)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)5