Java Code Examples for org.camunda.bpm.engine.runtime.ProcessInstanceQuery#list()
The following examples show how to use
org.camunda.bpm.engine.runtime.ProcessInstanceQuery#list() .
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: ProcessInstanceRestServiceImpl.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Override public List<ProcessInstanceDto> queryProcessInstances( ProcessInstanceQueryDto queryDto, Integer firstResult, Integer maxResults) { ProcessEngine engine = getProcessEngine(); queryDto.setObjectMapper(getObjectMapper()); ProcessInstanceQuery query = queryDto.toQuery(engine); List<ProcessInstance> matchingInstances; if (firstResult != null || maxResults != null) { matchingInstances = executePaginatedQuery(query, firstResult, maxResults); } else { matchingInstances = query.list(); } List<ProcessInstanceDto> instanceResults = new ArrayList<ProcessInstanceDto>(); for (ProcessInstance instance : matchingInstances) { ProcessInstanceDto resultInstance = ProcessInstanceDto.fromProcessInstance(instance); instanceResults.add(resultInstance); } return instanceResults; }
Example 2
Source File: ProcessInstanceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneProcessTaskCase.cmmn", "org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml" }) public void testQueryByCaseInstanceId() { String caseInstanceId = caseService .withCaseDefinitionByKey("oneProcessTaskCase") .create() .getId(); ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery(); query.caseInstanceId(caseInstanceId); assertEquals(1, query.count()); List<ProcessInstance> result = query.list(); assertEquals(1, result.size()); ProcessInstance processInstance = result.get(0); assertEquals(caseInstanceId, processInstance.getCaseInstanceId()); }
Example 3
Source File: ProcessInstanceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testQueryByProcessInstanceIds() { Set<String> processInstanceIds = new HashSet<>(this.processInstanceIds); // start an instance that will not be part of the query runtimeService.startProcessInstanceByKey(PROCESS_DEFINITION_KEY_2, "2"); ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processInstanceIds(processInstanceIds); assertEquals(5, processInstanceQuery.count()); List<ProcessInstance> processInstances = processInstanceQuery.list(); assertNotNull(processInstances); assertEquals(5, processInstances.size()); for (ProcessInstance processInstance : processInstances) { assertTrue(processInstanceIds.contains(processInstance.getId())); } }
Example 4
Source File: ProcessInstanceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test @Deployment(resources={"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testQueryAllVariableTypes() throws Exception { Map<String, Object> vars = new HashMap<>(); 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); ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery() .variableValueEquals("nullVar", null) .variableValueEquals("stringVar", "string") .variableValueEquals("longVar", 10L) .variableValueEquals("doubleVar", 1.2) .variableValueEquals("integerVar", 1234) .variableValueEquals("booleanVar", true) .variableValueEquals("shortVar", (short) 123); List<ProcessInstance> processInstances = query.list(); assertNotNull(processInstances); Assert.assertEquals(1, processInstances.size()); Assert.assertEquals(processInstance.getId(), processInstances.get(0).getId()); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); }
Example 5
Source File: StartTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment(resources = "org/camunda/bpm/engine/test/bpmn/event/timer/StartTimerEventTest.testRecalculateExpressionStartTimerEvent.bpmn20.xml") public void testRecalculateUnchangedExpressionStartTimerEventCreationDateBased() throws Exception { // given JobQuery jobQuery = managementService.createJobQuery(); ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample"); assertEquals(1, jobQuery.count()); assertEquals(0, processInstanceQuery.count()); // when moveByMinutes(1); managementService.recalculateJobDuedate(jobQuery.singleResult().getId(), true); // then due date should be based on the creation time assertEquals(1, jobQuery.count()); assertEquals(0, processInstanceQuery.count()); Job jobUpdated = jobQuery.singleResult(); Date expectedDate = LocalDateTime.fromDateFields(jobUpdated.getCreateTime()).plusHours(2).toDate(); assertEquals(expectedDate, jobUpdated.getDuedate()); // move the clock forward 2 hours and 1 minute moveByMinutes(121); executeAllJobs(); List<ProcessInstance> pi = processInstanceQuery.list(); assertEquals(1, pi.size()); assertEquals(0, jobQuery.count()); }
Example 6
Source File: StartTimerEventTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Deployment public void testRecalculateExpressionStartTimerEvent() throws Exception { // given JobQuery jobQuery = managementService.createJobQuery(); ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample"); assertEquals(1, jobQuery.count()); assertEquals(0, processInstanceQuery.count()); Job job = jobQuery.singleResult(); Date oldDate = job.getDuedate(); // when moveByMinutes(2); Date currentTime = ClockUtil.getCurrentTime(); managementService.recalculateJobDuedate(job.getId(), false); // then assertEquals(1, jobQuery.count()); assertEquals(0, processInstanceQuery.count()); Date newDate = jobQuery.singleResult().getDuedate(); assertNotEquals(oldDate, newDate); assertTrue(oldDate.before(newDate)); Date expectedDate = LocalDateTime.fromDateFields(currentTime).plusHours(2).toDate(); assertThat(newDate).isCloseTo(expectedDate, 1000l); // move the clock forward 2 hours and 2 min moveByMinutes(122); executeAllJobs(); List<ProcessInstance> pi = processInstanceQuery.list(); assertEquals(1, pi.size()); assertEquals(0, jobQuery.count()); }
Example 7
Source File: ProcessInstanceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testQueryByRootProcessInstances() { // given String superProcess = "calling"; String subProcess = "called"; BpmnModelInstance callingInstance = ProcessModels.newModel(superProcess) .startEvent() .callActivity() .calledElement(subProcess) .endEvent() .done(); BpmnModelInstance calledInstance = ProcessModels.newModel(subProcess) .startEvent() .userTask() .endEvent() .done(); testHelper.deploy(callingInstance, calledInstance); String businessKey = "theOne"; String processInstanceId = runtimeService.startProcessInstanceByKey(superProcess, businessKey).getProcessInstanceId(); // when ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery() .processInstanceBusinessKey(businessKey) .rootProcessInstances(); // then assertEquals(1, query.count()); List<ProcessInstance> list = query.list(); assertEquals(1, list.size()); assertEquals(processInstanceId, list.get(0).getId()); }
Example 8
Source File: ProcessInstanceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testQueryByDeploymentId() { // given String firstDeploymentId = repositoryService .createDeploymentQuery() .singleResult() .getId(); // make a second deployment and start an instance org.camunda.bpm.engine.repository.Deployment secondDeployment = repositoryService.createDeployment() .addClasspathResource("org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml") .deploy(); ProcessInstance secondProcessInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); // when ProcessInstanceQuery query = runtimeService .createProcessInstanceQuery() .deploymentId(firstDeploymentId); // then the instance belonging to the second deployment is not returned assertEquals(5, query.count()); List<ProcessInstance> instances = query.list(); assertEquals(5, instances.size()); for (ProcessInstance returnedInstance : instances) { assertTrue(!returnedInstance.getId().equals(secondProcessInstance.getId())); } // cleanup repositoryService.deleteDeployment(secondDeployment.getId(), true); }
Example 9
Source File: ProcessInstanceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/superCase.cmmn", "org/camunda/bpm/engine/test/api/runtime/superProcessWithCallActivityInsideSubProcess.bpmn20.xml", "org/camunda/bpm/engine/test/api/runtime/subProcess.bpmn20.xml" }) public void testQueryByCaseInstanceIdHierarchy() { String caseInstanceId = caseService .withCaseDefinitionByKey("oneProcessTaskCase") .businessKey("aBusinessKey") .create() .getId(); ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery(); query.caseInstanceId(caseInstanceId); assertEquals(2, query.count()); List<ProcessInstance> result = query.list(); assertEquals(2, result.size()); ProcessInstance firstProcessInstance = result.get(0); assertEquals(caseInstanceId, firstProcessInstance.getCaseInstanceId()); ProcessInstance secondProcessInstance = result.get(1); assertEquals(caseInstanceId, secondProcessInstance.getCaseInstanceId()); }
Example 10
Source File: BoundedNumberOfMaxResultsTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void shouldReturnUnboundedResults_UnboundMaxResults() { // given engineRule.getProcessEngineConfiguration() .setQueryMaxResultsLimit(Integer.MAX_VALUE); ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); // when List<ProcessInstance> processInstances = processInstanceQuery.list(); // then assertThat(processInstances.size()).isEqualTo(0); }
Example 11
Source File: BoundedNumberOfMaxResultsTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void shouldThrowException_UnboundedResultsForList() { // given ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); // then thrown.expect(BadUserRequestException.class); thrown.expectMessage("An unbound number of results is forbidden!"); // when processInstanceQuery.list(); }
Example 12
Source File: BoundedNumberOfMaxResultsTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void shouldReturnUnboundedResults_NotAuthenticated() { // given identityService.clearAuthentication(); ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); // when List<ProcessInstance> processInstances = processInstanceQuery.list(); // then assertThat(processInstances.size()).isEqualTo(0); }
Example 13
Source File: ProcessInstanceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Test @Deployment(resources={"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testQueryDateVariable() throws Exception { Map<String, Object> vars = new HashMap<>(); Date date1 = Calendar.getInstance().getTime(); vars.put("dateVar", date1); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); Date date2 = Calendar.getInstance().getTime(); vars = new HashMap<>(); vars.put("dateVar", date1); vars.put("dateVar2", date2); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); Calendar nextYear = Calendar.getInstance(); nextYear.add(Calendar.YEAR, 1); vars = new HashMap<>(); vars.put("dateVar",nextYear.getTime()); ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); Calendar nextMonth = Calendar.getInstance(); nextMonth.add(Calendar.MONTH, 1); Calendar twoYearsLater = Calendar.getInstance(); twoYearsLater.add(Calendar.YEAR, 2); Calendar oneYearAgo = Calendar.getInstance(); oneYearAgo.add(Calendar.YEAR, -1); // Query on single short variable, should result in 2 matches ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().variableValueEquals("dateVar", date1); List<ProcessInstance> processInstances = query.list(); assertNotNull(processInstances); Assert.assertEquals(2, processInstances.size()); // Query on two short variables, should result in single value query = runtimeService.createProcessInstanceQuery().variableValueEquals("dateVar", date1).variableValueEquals("dateVar2", date2); ProcessInstance resultInstance = query.singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance2.getId(), resultInstance.getId()); // Query with unexisting variable value Date unexistingDate = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("01/01/1989 12:00:00"); resultInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("dateVar", unexistingDate).singleResult(); assertNull(resultInstance); // Test NOT_EQUALS resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("dateVar", date1).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); // Test GREATER_THAN resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("dateVar", nextMonth.getTime()).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("dateVar", nextYear.getTime()).count()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("dateVar", oneYearAgo.getTime()).count()); // Test GREATER_THAN_OR_EQUAL resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("dateVar", nextMonth.getTime()).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("dateVar", nextYear.getTime()).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("dateVar",oneYearAgo.getTime()).count()); // Test LESS_THAN processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("dateVar", nextYear.getTime()).list(); Assert.assertEquals(2, processInstances.size()); List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); List<String> ids = new ArrayList<>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expecedIds); assertTrue(ids.isEmpty()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("dateVar", date1).count()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("dateVar", twoYearsLater.getTime()).count()); // Test LESS_THAN_OR_EQUAL processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("dateVar", nextYear.getTime()).list(); Assert.assertEquals(3, processInstances.size()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("dateVar", oneYearAgo.getTime()).count()); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); runtimeService.deleteProcessInstance(processInstance3.getId(), "test"); }
Example 14
Source File: ProcessInstanceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Test @Deployment(resources={"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testQueryShortVariable() { Map<String, Object> vars = new HashMap<>(); short shortVar = 1234; vars.put("shortVar", shortVar); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); short shortVar2 = 6789; vars = new HashMap<>(); vars.put("shortVar", shortVar); vars.put("shortVar2", shortVar2); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<>(); 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); Assert.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); Assert.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); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); // Test GREATER_THAN resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("shortVar", (short)4444).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("shortVar", (short)5555).count()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("shortVar",(short)1).count()); // Test GREATER_THAN_OR_EQUAL resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("shortVar", (short)4444).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("shortVar", (short)5555).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("shortVar",(short)1).count()); // Test LESS_THAN processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("shortVar", (short)5555).list(); Assert.assertEquals(2, processInstances.size()); List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); List<String> ids = new ArrayList<>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expecedIds); assertTrue(ids.isEmpty()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("shortVar", (short)1234).count()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("shortVar",(short)6666).count()); // Test LESS_THAN_OR_EQUAL processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("shortVar", (short)5555).list(); Assert.assertEquals(3, processInstances.size()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("shortVar", (short)1233).count()); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); runtimeService.deleteProcessInstance(processInstance3.getId(), "test"); }
Example 15
Source File: ProcessInstanceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Test @Deployment(resources={"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testQueryIntegerVariable() { Map<String, Object> vars = new HashMap<>(); vars.put("integerVar", 12345); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<>(); vars.put("integerVar", 12345); vars.put("integerVar2", 67890); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<>(); 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); Assert.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); Assert.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); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); // Test GREATER_THAN resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 44444).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar", 55555).count()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("integerVar",1).count()); // Test GREATER_THAN_OR_EQUAL resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 44444).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar", 55555).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("integerVar",1).count()); // Test LESS_THAN processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 55555).list(); Assert.assertEquals(2, processInstances.size()); List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); List<String> ids = new ArrayList<>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expecedIds); assertTrue(ids.isEmpty()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar", 12345).count()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("integerVar",66666).count()); // Test LESS_THAN_OR_EQUAL processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("integerVar", 55555).list(); Assert.assertEquals(3, processInstances.size()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("integerVar", 12344).count()); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); runtimeService.deleteProcessInstance(processInstance3.getId(), "test"); }
Example 16
Source File: ProcessInstanceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Test @Deployment(resources={"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testQueryDoubleVariable() { Map<String, Object> vars = new HashMap<>(); vars.put("doubleVar", 12345.6789); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<>(); vars.put("doubleVar", 12345.6789); vars.put("doubleVar2", 9876.54321); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<>(); 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); Assert.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); Assert.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); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); // Test GREATER_THAN resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("doubleVar", 44444.4444).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("doubleVar", 55555.5555).count()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("doubleVar",1.234).count()); // Test GREATER_THAN_OR_EQUAL resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("doubleVar", 44444.4444).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("doubleVar", 55555.5555).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("doubleVar",1.234).count()); // Test LESS_THAN processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("doubleVar", 55555.5555).list(); Assert.assertEquals(2, processInstances.size()); List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); List<String> ids = new ArrayList<>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expecedIds); assertTrue(ids.isEmpty()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("doubleVar", 12345.6789).count()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("doubleVar",66666.6666).count()); // Test LESS_THAN_OR_EQUAL processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("doubleVar", 55555.5555).list(); Assert.assertEquals(3, processInstances.size()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("doubleVar", 12344.6789).count()); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); runtimeService.deleteProcessInstance(processInstance3.getId(), "test"); }
Example 17
Source File: ProcessInstanceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Test @Deployment(resources={"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testQueryLongVariable() { Map<String, Object> vars = new HashMap<>(); vars.put("longVar", 12345L); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<>(); vars.put("longVar", 12345L); vars.put("longVar2", 67890L); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<>(); 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); Assert.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); Assert.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); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); // Test GREATER_THAN resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("longVar", 44444L).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("longVar", 55555L).count()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThan("longVar",1L).count()); // Test GREATER_THAN_OR_EQUAL resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("longVar", 44444L).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("longVar", 55555L).singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("longVar",1L).count()); // Test LESS_THAN processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThan("longVar", 55555L).list(); Assert.assertEquals(2, processInstances.size()); List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); List<String> ids = new ArrayList<>(Arrays.asList(processInstances.get(0).getId(), processInstances.get(1).getId())); ids.removeAll(expecedIds); assertTrue(ids.isEmpty()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThan("longVar", 12345L).count()); Assert.assertEquals(3, runtimeService.createProcessInstanceQuery().variableValueLessThan("longVar",66666L).count()); // Test LESS_THAN_OR_EQUAL processInstances = runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("longVar", 55555L).list(); Assert.assertEquals(3, processInstances.size()); Assert.assertEquals(0, runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("longVar", 12344L).count()); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); runtimeService.deleteProcessInstance(processInstance3.getId(), "test"); }
Example 18
Source File: ProcessInstanceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Test @Deployment(resources={"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testQueryStringVariable() { Map<String, Object> vars = new HashMap<>(); vars.put("stringVar", "abcdef"); ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<>(); vars.put("stringVar", "abcdef"); vars.put("stringVar2", "ghijkl"); ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars); vars = new HashMap<>(); 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); Assert.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); Assert.assertEquals(processInstance2.getId(), resultInstance.getId()); // Test NOT_EQUAL, should return only 1 resultInstance resultInstance = runtimeService.createProcessInstanceQuery().variableValueNotEquals("stringVar", "abcdef").singleResult(); assertNotNull(resultInstance); Assert.assertEquals(processInstance3.getId(), resultInstance.getId()); // Test GREATER_THAN, should return only matching 'azerty' resultInstance = runtimeService.createProcessInstanceQuery().variableValueGreaterThan("stringVar", "abcdef").singleResult(); assertNotNull(resultInstance); Assert.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(); Assert.assertEquals(2, processInstances.size()); List<String> expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); List<String> ids = new ArrayList<>(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(); Assert.assertEquals(2, processInstances.size()); expecedIds = Arrays.asList(processInstance1.getId(), processInstance2.getId()); ids = new ArrayList<>(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()); runtimeService.deleteProcessInstance(processInstance1.getId(), "test"); runtimeService.deleteProcessInstance(processInstance2.getId(), "test"); runtimeService.deleteProcessInstance(processInstance3.getId(), "test"); }