Search in sources :

Example 81 with Execution

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

the class ExecutionQueryTest method testQueryAllVariableTypes.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryAllVariableTypes() throws Exception {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("nullVar", null);
    vars.put("stringVar", "string");
    vars.put("longVar", 10L);
    vars.put("doubleVar", 1.2);
    vars.put("integerVar", 1234);
    vars.put("booleanVar", true);
    vars.put("shortVar", (short) 123);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("nullVar", null).variableValueEquals("stringVar", "string").variableValueEquals("longVar", 10L).variableValueEquals("doubleVar", 1.2).variableValueEquals("integerVar", 1234).variableValueEquals("booleanVar", true).variableValueEquals("shortVar", (short) 123);
    List<Execution> executions = query.list();
    assertNotNull(executions);
    assertEquals(1, executions.size());
    assertEquals(processInstance.getId(), executions.get(0).getId());
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery) Deployment(org.activiti.engine.test.Deployment)

Example 82 with Execution

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

the class ExecutionQueryTest method testQueryByActivityIdAndBusinessKeyWithChildren.

/**
   * Validate fix for ACT-1896
   */
public void testQueryByActivityIdAndBusinessKeyWithChildren() {
    ExecutionQuery query = runtimeService.createExecutionQuery().activityId("receivePayment").processInstanceBusinessKey("BUSINESS-KEY-1", true);
    assertEquals(1, query.list().size());
    assertEquals(1, query.count());
    Execution execution = query.singleResult();
    assertNotNull(execution);
    assertEquals("receivePayment", execution.getActivityId());
}
Also used : Execution(org.activiti.engine.runtime.Execution) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery)

Example 83 with Execution

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

the class ExecutionQueryTest method testBooleanVariable.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testBooleanVariable() throws Exception {
    // TEST EQUALS
    HashMap<String, Object> vars = new HashMap<String, Object>();
    vars.put("booleanVar", true);
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    vars = new HashMap<String, Object>();
    vars.put("booleanVar", false);
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    List<ProcessInstance> instances = runtimeService.createProcessInstanceQuery().variableValueEquals("booleanVar", true).list();
    assertNotNull(instances);
    assertEquals(1, instances.size());
    assertEquals(processInstance1.getId(), instances.get(0).getId());
    instances = runtimeService.createProcessInstanceQuery().variableValueEquals("booleanVar", false).list();
    assertNotNull(instances);
    assertEquals(1, instances.size());
    assertEquals(processInstance2.getId(), instances.get(0).getId());
    // TEST NOT_EQUALS
    instances = runtimeService.createProcessInstanceQuery().variableValueNotEquals("booleanVar", true).list();
    assertNotNull(instances);
    assertEquals(1, instances.size());
    assertEquals(processInstance2.getId(), instances.get(0).getId());
    instances = runtimeService.createProcessInstanceQuery().variableValueNotEquals("booleanVar", false).list();
    assertNotNull(instances);
    assertEquals(1, instances.size());
    assertEquals(processInstance1.getId(), instances.get(0).getId());
    // Test value-only matching
    Execution execution = runtimeService.createExecutionQuery().variableValueEquals(true).singleResult();
    assertNotNull(execution);
    assertEquals(processInstance1.getId(), execution.getId());
    // Test unsupported operations
    try {
        runtimeService.createProcessInstanceQuery().variableValueGreaterThan("booleanVar", true);
        fail("Excetion expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertTextPresent("Booleans and null cannot be used in 'greater than' condition", ae.getMessage());
    }
    try {
        runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("booleanVar", true);
        fail("Excetion expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertTextPresent("Booleans and null cannot be used in 'greater than or equal' condition", ae.getMessage());
    }
    try {
        runtimeService.createProcessInstanceQuery().variableValueLessThan("booleanVar", true);
        fail("Excetion expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertTextPresent("Booleans and null cannot be used in 'less than' condition", ae.getMessage());
    }
    try {
        runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("booleanVar", true);
        fail("Excetion expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertTextPresent("Booleans and null cannot be used in 'less than or equal' condition", ae.getMessage());
    }
    runtimeService.deleteProcessInstance(processInstance1.getId(), "test");
    runtimeService.deleteProcessInstance(processInstance2.getId(), "test");
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 84 with Execution

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

the class ExecutionQueryTest method testQueryLike.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryLike() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("var1", "aaaaa");
    vars.put("var2", "bbbbb");
    vars.put("var3", "ccccc");
    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
    Execution execution = runtimeService.createExecutionQuery().variableValueLike("var1", "aa%").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance1.getId(), execution.getId());
    execution = runtimeService.createExecutionQuery().variableValueLike("var2", "bb%").singleResult();
    assertNotNull(execution);
    assertEquals(processInstance1.getId(), execution.getId());
    // Pass in null-value, should cause exception
    try {
        execution = runtimeService.createExecutionQuery().variableValueLike("var1", null).singleResult();
        fail("Exception expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertEquals("Only string values can be used with 'like' condition", ae.getMessage());
    }
    // Pass in null name, should cause exception
    try {
        execution = runtimeService.createExecutionQuery().variableValueLike(null, "abcdefg").singleResult();
        fail("Exception expected");
    } catch (ActivitiIllegalArgumentException ae) {
        assertEquals("name is null", ae.getMessage());
    }
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 85 with Execution

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

the class ProcessInstanceQueryTest 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("dateVar", new Date());
    variables.put("booleanVar", true);
    variables.put("nullVar", null);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variables);
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("longVar", null).variableValueEquals("shortVar", null).variableValueEquals("integerVar", null).variableValueEquals("stringVar", null).variableValueEquals("booleanVar", null).variableValueEquals("dateVar", null);
    ProcessInstanceQuery notQuery = runtimeService.createProcessInstanceQuery().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(), "dateVar", null);
    runtimeService.setVariable(processInstance.getId(), "nullVar", null);
    runtimeService.setVariable(processInstance.getId(), "booleanVar", null);
    Execution queryResult = query.singleResult();
    assertNotNull(queryResult);
    assertEquals(processInstance.getId(), queryResult.getId());
    assertNull(notQuery.singleResult());
}
Also used : ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Date(java.util.Date) 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