Java Code Examples for org.activiti.engine.runtime.ProcessInstanceQuery#singleResult()
The following examples show how to use
org.activiti.engine.runtime.ProcessInstanceQuery#singleResult() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public void testQueryByProcessDefinitionIds() { final ProcessDefinition processDefinition1 = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).singleResult(); final ProcessDefinition processDefinition2 = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY_2).singleResult(); final Set<String> processDefinitionIdSet = new HashSet<String>(2); processDefinitionIdSet.add(processDefinition1.getId()); processDefinitionIdSet.add(processDefinition2.getId()); ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processDefinitionIds(processDefinitionIdSet); assertEquals(PROCESS_DEPLOY_COUNT, query.count()); assertEquals(PROCESS_DEPLOY_COUNT, query.list().size()); try { query.singleResult(); fail(); } catch (ActivitiException e) { // Exception is expected } }
Example 2
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public void testQueryByProcessDefinitionId() { final ProcessDefinition processDefinition1 = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY).singleResult(); ProcessInstanceQuery query1 = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition1.getId()); assertEquals(PROCESS_DEFINITION_KEY_DEPLOY_COUNT, query1.count()); assertEquals(PROCESS_DEFINITION_KEY_DEPLOY_COUNT, query1.list().size()); try { query1.singleResult(); fail(); } catch (ActivitiException e) { // Exception is expected } final ProcessDefinition processDefinition2 = repositoryService.createProcessDefinitionQuery().processDefinitionKey(PROCESS_DEFINITION_KEY_2).singleResult(); ProcessInstanceQuery query2 = runtimeService.createProcessInstanceQuery().processDefinitionId(processDefinition2.getId()); assertEquals(PROCESS_DEFINITION_KEY_2_DEPLOY_COUNT, query2.count()); assertEquals(PROCESS_DEFINITION_KEY_2_DEPLOY_COUNT, query2.list().size()); assertNotNull(query2.singleResult()); }
Example 3
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void testQueryByProcessDefinitionKeyMultipleResults() { ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processDefinitionKey(PROCESS_DEFINITION_KEY); assertEquals(PROCESS_DEFINITION_KEY_DEPLOY_COUNT, query.count()); assertEquals(PROCESS_DEFINITION_KEY_DEPLOY_COUNT, query.list().size()); try { query.singleResult(); fail(); } catch (ActivitiException e) { // Exception is expected } }
Example 4
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Deployment(resources = {"org/activiti5/engine/test/api/runtime/superProcess.bpmn20.xml", "org/activiti5/engine/test/api/runtime/subProcess.bpmn20.xml"}) public void testQueryBySuperProcessInstanceId() { ProcessInstance superProcessInstance = runtimeService.startProcessInstanceByKey("subProcessQueryTest"); ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().superProcessInstanceId(superProcessInstance.getId()); ProcessInstance subProcessInstance = query.singleResult(); assertNotNull(subProcessInstance); assertEquals(1, query.list().size()); assertEquals(1, query.count()); }
Example 5
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void testQueryByProcessDefinitionKeys() { final Set<String> processDefinitionKeySet = new HashSet<String>(2); processDefinitionKeySet.add(PROCESS_DEFINITION_KEY); processDefinitionKeySet.add(PROCESS_DEFINITION_KEY_2); ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processDefinitionKeys(processDefinitionKeySet); assertEquals(PROCESS_DEPLOY_COUNT, query.count()); assertEquals(PROCESS_DEPLOY_COUNT, query.list().size()); try { query.singleResult(); fail(); } catch (ActivitiException e) { // Exception is expected } }
Example 6
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void testQueryByProcessDefinitionKeyMultipleResults() { ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processDefinitionKey(PROCESS_DEFINITION_KEY); assertEquals(PROCESS_DEFINITION_KEY_DEPLOY_COUNT, query.count()); assertEquals(PROCESS_DEFINITION_KEY_DEPLOY_COUNT, query.list().size()); try { query.singleResult(); fail(); } catch (ActivitiException e) { // Exception is expected } }
Example 7
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void testQueryNoSpecificsSingleResult() { ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery(); try { query.singleResult(); fail(); } catch (ActivitiException e) { // Exception is expected } }
Example 8
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@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()); }
Example 9
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Deployment(resources = { "org/activiti/engine/test/api/runtime/superProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/subProcess.bpmn20.xml" }) public void testOrQueryBySuperProcessInstanceId() { ProcessInstance superProcessInstance = runtimeService.startProcessInstanceByKey("subProcessQueryTest"); ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().or().superProcessInstanceId(superProcessInstance.getId()).processDefinitionId("undefined").endOr(); ProcessInstance subProcessInstance = query.singleResult(); assertNotNull(subProcessInstance); assertEquals(1, query.list().size()); assertEquals(1, query.count()); }
Example 10
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Deployment(resources = { "org/activiti/engine/test/api/runtime/superProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/subProcess.bpmn20.xml" }) public void testQueryBySuperProcessInstanceId() { ProcessInstance superProcessInstance = runtimeService.startProcessInstanceByKey("subProcessQueryTest"); ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().superProcessInstanceId(superProcessInstance.getId()); ProcessInstance subProcessInstance = query.singleResult(); assertNotNull(subProcessInstance); assertEquals(1, query.list().size()); assertEquals(1, query.count()); }
Example 11
Source File: ProcessInstanceResourceRepository.java From crnk-framework with Apache License 2.0 | 5 votes |
@Override public <S extends T> S create(S resource) { checkFilter(resource, true); String processDefinitionKey = resource.getProcessDefinitionKey(); String businessKey = resource.getBusinessKey(); String tenantId = resource.getTenantId(); Map<String, Object> variables = resourceMapper.mapToVariables(resource); ProcessInstance processInstance = runtimeService.startProcessInstanceByKeyAndTenantId(processDefinitionKey, businessKey, variables, tenantId); applyUpdates(processInstance, resource); ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()); processInstanceQuery.includeProcessVariables(); ProcessInstance updatedProcessInstance = processInstanceQuery.singleResult(); if (updatedProcessInstance != null) { return (S) mapResult(updatedProcessInstance); } // process already terminated, unfortunately no shared interfaces HistoricProcessInstanceQuery historicQuery = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()); historicQuery.includeProcessVariables(); HistoricProcessInstance historicProcessInstance = historicQuery.singleResult(); PreconditionUtil.verify(historicProcessInstance != null, "could not found potentially terminated process instance with id %s", processInstance.getId()); ProcessInstance finishedProcessInstance = new MappedHistoricProcessInstance(historicProcessInstance); S result = (S) mapResult(finishedProcessInstance); result.setName(resource.getName()); result.setBusinessKey(resource.getBusinessKey()); return result; }
Example 12
Source File: ActivitiKit.java From my_curd with Apache License 2.0 | 5 votes |
/** * 查询运行时 流程实例 * * @param processInstanceId 流程实例id * @param includeProcessVariables 是否包含流程变量 * @return 流程实例 */ public static ProcessInstance getRuntimeProcessInstance(String processInstanceId, boolean includeProcessVariables) { ProcessInstanceQuery query = getRuntimeService() .createProcessInstanceQuery() .processInstanceId(processInstanceId); if (includeProcessVariables) { query.includeProcessVariables(); } return query.singleResult(); }
Example 13
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void testQueryNoSpecificsSingleResult() { ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery(); try { query.singleResult(); fail(); } catch (ActivitiException e) { // Exception is expected } }
Example 14
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" }) public void testQueryLongVariable() { Map<String, Object> vars = new HashMap<String, Object>(); vars.put("longVar", 12345L); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<String, Object>(); vars.put("longVar", 12345L); vars.put("longVar2", 67890L); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<String, Object>(); vars.put("longVar", 55555L); ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); // Query on single long variable, should result in 2 matches ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("longVar", 12345L); List<ProcessInstance> processInstances = query.list(); assertNotNull(processInstances); assertEquals(2, processInstances.size()); // Query on two long variables, should result in single match query = runtimeService.createProcessInstanceQuery().variableValueEquals("longVar", 12345L).variableValueEquals("longVar2", 67890L); ProcessInstance resultInstance = query.singleResult(); assertNotNull(resultInstance); assertEquals(processInstance2.getId(), resultInstance.getId()); // Query with unexisting variable value resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("longVar", 999L).singleResult(); assertNull(resultInstance); // Test NOT_EQUALS resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("longVar", 12345L).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); // Test GREATER_THAN resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("longVar", 44444L).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("longVar", 55555L).count()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("longVar", 1L).count()); // Test GREATER_THAN_OR_EQUAL resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("longVar", 44444L).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("longVar", 55555L).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("longVar", 1L).count()); // Test LESS_THAN processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("longVar", 55555L).list(); assertEquals(2, processInstances.size()); List<String> expectedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); List<String> ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expectedIds); assertTrue(ids.isEmpty()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("longVar", 12345L).count()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("longVar", 66666L).count()); // Test LESS_THAN_OR_EQUAL processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("longVar", 55555L).list(); assertEquals(3, processInstances.size()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("longVar", 12344L).count()); // Test value-only matching resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(55555L).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); processInstances = runtimeService.createProcessInstanceQuery().variableValueEquals(12345L).list(); assertEquals(2, processInstances.size()); expectedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expectedIds); assertTrue(ids.isEmpty()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(999L).singleResult(); assertNull(resultInstance); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); runtimeService.deleteProcessInstance(processInstance3.getId(), "test"); }
Example 15
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" }) public void testQueryDoubleVariable() { Map<String, Object> vars = new HashMap<String, Object>(); vars.put("doubleVar", 12345.6789); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<String, Object>(); vars.put("doubleVar", 12345.6789); vars.put("doubleVar2", 9876.54321); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<String, Object>(); vars.put("doubleVar", 55555.5555); ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); // Query on single double variable, should result in 2 matches ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("doubleVar", 12345.6789); List<ProcessInstance> processInstances = query.list(); assertNotNull(processInstances); assertEquals(2, processInstances.size()); // Query on two double variables, should result in single value query = runtimeService.createProcessInstanceQuery().variableValueEquals("doubleVar", 12345.6789).variableValueEquals("doubleVar2", 9876.54321); ProcessInstance resultInstance = query.singleResult(); assertNotNull(resultInstance); assertEquals(processInstance2.getId(), resultInstance.getId()); // Query with unexisting variable value resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("doubleVar", 9999.99).singleResult(); assertNull(resultInstance); // Test NOT_EQUALS resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("doubleVar", 12345.6789).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); // Test GREATER_THAN resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("doubleVar", 44444.4444).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("doubleVar", 55555.5555).count()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("doubleVar", 1.234).count()); // Test GREATER_THAN_OR_EQUAL resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("doubleVar", 44444.4444).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("doubleVar", 55555.5555).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("doubleVar", 1.234).count()); // Test LESS_THAN processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("doubleVar", 55555.5555).list(); assertEquals(2, processInstances.size()); List<String> expectedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); List<String> ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expectedIds); assertTrue(ids.isEmpty()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("doubleVar", 12345.6789).count()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("doubleVar", 66666.6666).count()); // Test LESS_THAN_OR_EQUAL processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("doubleVar", 55555.5555).list(); assertEquals(3, processInstances.size()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("doubleVar", 12344.6789).count()); // Test value-only matching resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(55555.5555).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); processInstances = runtimeService.createProcessInstanceQuery().variableValueEquals(12345.6789).list(); assertEquals(2, processInstances.size()); expectedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expectedIds); assertTrue(ids.isEmpty()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(999.999).singleResult(); assertNull(resultInstance); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); runtimeService.deleteProcessInstance(processInstance3.getId(), "test"); }
Example 16
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" }) public void testQueryIntegerVariable() { Map<String, Object> vars = new HashMap<String, Object>(); vars.put("integerVar", 12345); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<String, Object>(); vars.put("integerVar", 12345); vars.put("integerVar2", 67890); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<String, Object>(); vars.put("integerVar", 55555); ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); // Query on single integer variable, should result in 2 matches ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("integerVar", 12345); List<ProcessInstance> processInstances = query.list(); assertNotNull(processInstances); assertEquals(2, processInstances.size()); // Query on two integer variables, should result in single value query = runtimeService.createProcessInstanceQuery().variableValueEquals("integerVar", 12345).variableValueEquals("integerVar2", 67890); ProcessInstance resultInstance = query.singleResult(); assertNotNull(resultInstance); assertEquals(processInstance2.getId(), resultInstance.getId()); // Query with unexisting variable value resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("integerVar", 9999).singleResult(); assertNull(resultInstance); // Test NOT_EQUALS resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("integerVar", 12345).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); // Test GREATER_THAN resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 44444).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 55555).count()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 1).count()); // Test GREATER_THAN_OR_EQUAL resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 44444).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 55555).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 1).count()); // Test LESS_THAN processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 55555).list(); assertEquals(2, processInstances.size()); List<String> expectedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); List<String> ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expectedIds); assertTrue(ids.isEmpty()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 12345).count()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 66666).count()); // Test LESS_THAN_OR_EQUAL processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("integerVar", 55555).list(); assertEquals(3, processInstances.size()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("integerVar", 12344).count()); // Test value-only matching resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(55555).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); processInstances = runtimeService.createProcessInstanceQuery().variableValueEquals(12345).list(); assertEquals(2, processInstances.size()); expectedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expectedIds); assertTrue(ids.isEmpty()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(9999).singleResult(); assertNull(resultInstance); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); runtimeService.deleteProcessInstance(processInstance3.getId(), "test"); }
Example 17
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
@Deployment(resources={ "org/activiti5/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()); }
Example 18
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" }) public void testQueryStringVariable() { Map<String, Object> vars = new HashMap<String, Object>(); vars.put("stringVar", "abcdef"); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<String, Object>(); vars.put("stringVar", "abcdef"); vars.put("stringVar2", "ghijkl"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<String, Object>(); vars.put("stringVar", "azerty"); ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); // Test EQUAL on single string variable, should result in 2 matches ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("stringVar", "abcdef"); List<ProcessInstance> processInstances = query.list(); assertNotNull(processInstances); assertEquals(2, processInstances.size()); // Test EQUAL on two string variables, should result in single match query = runtimeService.createProcessInstanceQuery().variableValueEquals("stringVar", "abcdef").variableValueEquals("stringVar2", "ghijkl"); ProcessInstance resultInstance = query.singleResult(); assertNotNull(resultInstance); assertEquals(processInstance2.getId(), resultInstance.getId()); // Test NOT_EQUAL, should return only 1 resultInstance resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("stringVar", "abcdef").singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); // Test GREATER_THAN, should return only matching 'azerty' resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("stringVar", "abcdef").singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("stringVar", "z").singleResult(); assertNull(resultInstance); // Test GREATER_THAN_OR_EQUAL, should return 3 results assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("stringVar", "abcdef").count()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("stringVar", "z").count()); // Test LESS_THAN, should return 2 results processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("stringVar", "abcdeg").list(); assertEquals(2, processInstances.size()); List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); List<String> ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expecedIds); assertTrue(ids.isEmpty()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("stringVar", "abcdef").count()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("stringVar", "z").count()); // Test LESS_THAN_OR_EQUAL processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("stringVar", "abcdef").list(); assertEquals(2, processInstances.size()); expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expecedIds); assertTrue(ids.isEmpty()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("stringVar", "z").count()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("stringVar", "aa").count()); // Test LIKE resultInstance = runtimeService.createProcessInstanceQuery().variableValueLike("stringVar", "azert%").singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueLike("stringVar", "%y").singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueLike("stringVar", "%zer%").singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLike("stringVar", "a%").count()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLike("stringVar", "%x%").count()); // Test value-only matching resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("azerty").singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); processInstances = runtimeService.createProcessInstanceQuery().variableValueEquals("abcdef").list(); assertEquals(2, processInstances.size()); expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expecedIds); assertTrue(ids.isEmpty()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("notmatchinganyvalues").singleResult(); assertNull(resultInstance); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); runtimeService.deleteProcessInstance(processInstance3.getId(), "test"); }
Example 19
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
@Deployment(resources={ "org/activiti5/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testQueryShortVariable() { Map<String, Object> vars = new HashMap<String, Object>(); short shortVar = 1234; vars.put("shortVar", shortVar); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); short shortVar2 = 6789; vars = new HashMap<String, Object>(); vars.put("shortVar", shortVar); vars.put("shortVar2", shortVar2); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<String, Object>(); vars.put("shortVar", (short)5555); ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); // Query on single short variable, should result in 2 matches ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("shortVar", shortVar); List<ProcessInstance> processInstances = query.list(); assertNotNull(processInstances); assertEquals(2, processInstances.size()); // Query on two short variables, should result in single value query = runtimeService.createProcessInstanceQuery().variableValueEquals("shortVar", shortVar).variableValueEquals("shortVar2", shortVar2); ProcessInstance resultInstance = query.singleResult(); assertNotNull(resultInstance); assertEquals(processInstance2.getId(), resultInstance.getId()); // Query with unexisting variable value short unexistingValue = (short)9999; resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("shortVar", unexistingValue).singleResult(); assertNull(resultInstance); // Test NOT_EQUALS resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("shortVar", (short)1234).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); // Test GREATER_THAN resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("shortVar", (short)4444).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("shortVar", (short)5555).count()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("shortVar",(short)1).count()); // Test GREATER_THAN_OR_EQUAL resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("shortVar", (short)4444).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("shortVar", (short)5555).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("shortVar",(short)1).count()); // Test LESS_THAN processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("shortVar", (short)5555).list(); assertEquals(2, processInstances.size()); List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); List<String> ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expecedIds); assertTrue(ids.isEmpty()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("shortVar", (short)1234).count()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("shortVar",(short)6666).count()); // Test LESS_THAN_OR_EQUAL processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("shortVar", (short)5555).list(); assertEquals(3, processInstances.size()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("shortVar", (short)1233).count()); // Test value-only matching resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals((short) 5555).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); processInstances = runtimeService.createProcessInstanceQuery().variableValueEquals((short)1234).list(); assertEquals(2, processInstances.size()); expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expecedIds); assertTrue(ids.isEmpty()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals((short) 999).singleResult(); assertNull(resultInstance); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); runtimeService.deleteProcessInstance(processInstance3.getId(), "test"); }
Example 20
Source File: ProcessInstanceQueryTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
@Deployment(resources={ "org/activiti5/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testQueryIntegerVariable() { Map<String, Object> vars = new HashMap<String, Object>(); vars.put("integerVar", 12345); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<String, Object>(); vars.put("integerVar", 12345); vars.put("integerVar2", 67890); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<String, Object>(); vars.put("integerVar", 55555); ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); // Query on single integer variable, should result in 2 matches ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("integerVar", 12345); List<ProcessInstance> processInstances = query.list(); assertNotNull(processInstances); assertEquals(2, processInstances.size()); // Query on two integer variables, should result in single value query = runtimeService.createProcessInstanceQuery().variableValueEquals("integerVar", 12345).variableValueEquals("integerVar2", 67890); ProcessInstance resultInstance = query.singleResult(); assertNotNull(resultInstance); assertEquals(processInstance2.getId(), resultInstance.getId()); // Query with unexisting variable value resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("integerVar", 9999).singleResult(); assertNull(resultInstance); // Test NOT_EQUALS resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("integerVar", 12345).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); // Test GREATER_THAN resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 44444).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 55555).count()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar",1).count()); // Test GREATER_THAN_OR_EQUAL resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 44444).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 55555).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar",1).count()); // Test LESS_THAN processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 55555).list(); assertEquals(2, processInstances.size()); List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); List<String> ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expecedIds); assertTrue(ids.isEmpty()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 12345).count()); assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar",66666).count()); // Test LESS_THAN_OR_EQUAL processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("integerVar", 55555).list(); assertEquals(3, processInstances.size()); assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("integerVar", 12344).count()); // Test value-only matching resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(55555).singleResult(); assertNotNull(resultInstance); assertEquals(processInstance3.getId(), resultInstance.getId()); processInstances = runtimeService.createProcessInstanceQuery().variableValueEquals(12345).list(); assertEquals(2, processInstances.size()); expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); ids = new ArrayList<String>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expecedIds); assertTrue(ids.isEmpty()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals(9999).singleResult(); assertNull(resultInstance); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); runtimeService.deleteProcessInstance(processInstance3.getId(), "test"); }