private void checkVariables(VariableMap map, int expectedSize) { List<HistoricVariableInstance> variables = engineRule.getHistoryService() .createHistoricVariableInstanceQuery() .orderByVariableName() .asc() .list(); assertEquals(expectedSize, variables.size()); assertEquals(variables.size(), map.size()); for (HistoricVariableInstance instance : variables) { assertTrue(map.containsKey(instance.getName())); Object instanceValue = instance.getTypedValue().getValue(); Object mapValue = map.getValueTyped(instance.getName()).getValue(); if (instanceValue == null) { assertNull(mapValue); } else if (instanceValue instanceof byte[]) { assertTrue(Arrays.equals((byte[]) instanceValue, (byte[]) mapValue)); } else { assertEquals(instanceValue, mapValue); } } }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testNativeHistoricVariableInstanceTest() { Date date = Calendar.getInstance().getTime(); Map<String, Object> vars = new HashMap<String, Object>(); vars.put("stringVar", "abcdef"); vars.put("dateVar", date); runtimeService.startProcessInstanceByKey(ONE_TASK_PROCESS, vars); assertEquals(2, historyService.createNativeHistoricVariableInstanceQuery().sql("SELECT count(*) FROM " + managementService.getTableName(HistoricVariableInstance.class)).count()); assertEquals(1, historyService.createNativeHistoricVariableInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(HistoricVariableInstance.class)).listPage(0, 1).size()); List<HistoricVariableInstance> variables = historyService.createNativeHistoricVariableInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(HistoricVariableInstance.class)).list(); assertEquals(2, variables.size()); for (HistoricVariableInstance variable : variables) { assertTrue(vars.containsKey(variable.getName())); assertEquals(vars.get(variable.getName()), variable.getValue()); vars.remove(variable.getName()); } }
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testQueryByVariableTypeIn() { // given Map<String, Object> variables1 = new HashMap<String, Object>(); variables1.put("stringVar", "test"); variables1.put("boolVar", true); runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1); // when HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery().variableTypeIn("string"); // then assertEquals(1, query.list().size()); assertEquals(1, query.count()); assertEquals(query.list().get(0).getName(), "stringVar"); }
protected VariableMap collectLastVariables(CommandContext commandContext, HistoricProcessInstance processInstance) { HistoryService historyService = commandContext.getProcessEngineConfiguration().getHistoryService(); List<HistoricVariableInstance> historicVariables = historyService.createHistoricVariableInstanceQuery() .executionIdIn(processInstance.getId()) .list(); VariableMap variables = new VariableMapImpl(); for (HistoricVariableInstance variable : historicVariables) { variables.putValueTyped(variable.getName(), variable.getTypedValue()); } return variables; }
protected VariableMap collectLastVariables(CommandContext commandContext, HistoricProcessInstance processInstance) { HistoryService historyService = commandContext.getProcessEngineConfiguration().getHistoryService(); List<HistoricVariableInstance> historicVariables = historyService.createHistoricVariableInstanceQuery() .executionIdIn(processInstance.getId()) .list(); VariableMap variables = new VariableMapImpl(); for (HistoricVariableInstance variable : historicVariables) { variables.putValueTyped(variable.getName(), variable.getTypedValue()); } return variables; }
@Deployment(resources={"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testQueryByVariableTypeInWithCapitalLetter() { // given Map<String, Object> variables1 = new HashMap<String, Object>(); variables1.put("stringVar", "test"); variables1.put("boolVar", true); runtimeService.startProcessInstanceByKey("oneTaskProcess", variables1); // when HistoricVariableInstanceQuery query = historyService.createHistoricVariableInstanceQuery(); query.variableTypeIn("Boolean"); // then assertEquals(1, query.list().size()); assertEquals(1, query.count()); assertEquals(query.list().get(0).getName(), "boolVar"); }
@Deployment public void testNestedJoinParallelGatewayLocalVariableOnLastJoiningExecution() { // when runtimeService.startProcessInstanceByKey("process"); // then assertEquals(0, runtimeService.createVariableInstanceQuery().count()); HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult(); assertNotNull(historicVariable); assertEquals("testVar", historicVariable.getName()); }
@Deployment public void testNestedJoinInclusiveGatewayLocalVariableOnLastJoiningExecution() { // when runtimeService.startProcessInstanceByKey("process"); // then assertEquals(0, runtimeService.createVariableInstanceQuery().count()); HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult(); assertNotNull(historicVariable); assertEquals("testVar", historicVariable.getName()); }
@Deployment public void testJoinParallelGatewayLocalVariableOnLastJoiningExecution() { // when runtimeService.startProcessInstanceByKey("process"); // then assertEquals(0, runtimeService.createVariableInstanceQuery().count()); HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult(); assertNotNull(historicVariable); assertEquals("testVar", historicVariable.getName()); }
@Deployment public void testJoinInclusiveGatewayLocalVariableOnLastJoiningExecution() { // when runtimeService.startProcessInstanceByKey("process"); // then assertEquals(0, runtimeService.createVariableInstanceQuery().count()); HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult(); assertNotNull(historicVariable); assertEquals("testVar", historicVariable.getName()); }
@Test public void testDeployProcessArchive() { // the process can successfully be executed ProcessInstance pi = runtimeService.startProcessInstanceByKey("testProcess"); HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery() .processInstanceId(pi.getId()) .singleResult(); assertNotNull(variable); assertEquals("executed", variable.getName()); assertEquals(true, variable.getValue()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/twoTasksProcess.bpmn20.xml"}) public void testQueryByProcessDefinitionKey() { // given runtimeService.startProcessInstanceByKey("twoTasksProcess", Variables.createVariables().putValue("initial", "foo")); // when HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery() .processDefinitionKey("twoTasksProcess").singleResult(); // then assertNotNull(variable); assertEquals("initial", variable.getName()); assertEquals("foo", variable.getValue()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/twoTasksProcess.bpmn20.xml"}) public void testQueryByProcessDefinitionId() { // given ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoTasksProcess", Variables.createVariables().putValue("initial", "foo")); // when HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery() .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult(); // then assertNotNull(variable); assertEquals("initial", variable.getName()); assertEquals("foo", variable.getValue()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml", "org/camunda/bpm/engine/test/api/twoTasksProcess.bpmn20.xml"}) public void testQueryByProcessDefinitionKeyTwoDefinitions() { // given runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValue("initial", "bar")); runtimeService.startProcessInstanceByKey("twoTasksProcess", Variables.createVariables().putValue("initial", "foo")); // when HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery() .processDefinitionKey("twoTasksProcess").singleResult(); // then assertNotNull(variable); assertEquals("initial", variable.getName()); assertEquals("foo", variable.getValue()); }
@Deployment(resources = "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn") public void testQueryByCaseActivityId() { // given caseService.createCaseInstanceByKey("oneTaskCase", Variables.putValue("foo", "bar")); CaseExecution caseExecution = caseService .createCaseExecutionQuery() .activityId("PI_HumanTask_1") .singleResult(); caseService.setVariableLocal(caseExecution.getId(), "bar", "foo"); // when HistoricVariableInstanceQuery query = historyService .createHistoricVariableInstanceQuery() .caseActivityIdIn("PI_HumanTask_1"); // then assertEquals(1, query.count()); assertEquals("bar", query.singleResult().getName()); assertEquals("foo", query.singleResult().getValue()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testQueryByProcessInstanceIdAndVariableId() { // given ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", Variables.createVariables().putValue("initial", "bar")); VariableInstance variable = runtimeService.createVariableInstanceQuery().variableName("initial").singleResult(); assertNotNull(variable); // when HistoricVariableInstance historyVariable = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()) .variableId(variable.getId()) .singleResult(); // then assertNotNull(historyVariable); assertEquals("initial", historyVariable.getName()); assertEquals("bar", historyVariable.getValue()); }
@Test public void testSubmitTaskFormForStandaloneTask() { // given String id = "standaloneTask"; Task task = taskService.newTask(id); taskService.saveTask(task); // when formService.submitTaskForm(task.getId(), Variables.createVariables().putValue("foo", "bar")); if (processEngineConfiguration.getHistoryLevel().getId() >= HistoryLevel.HISTORY_LEVEL_AUDIT.getId()) { HistoricVariableInstance variableInstance = historyService .createHistoricVariableInstanceQuery() .taskIdIn(id) .singleResult(); assertNotNull(variableInstance); assertEquals("foo", variableInstance.getName()); assertEquals("bar", variableInstance.getValue()); } taskService.deleteTask(id, true); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/twoTasksProcess.bpmn20.xml"}) public void testQueryNotIncludeDeleted() { //given ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoTasksProcess", Variables.createVariables().putValue("initial", "foo")); Task task = taskService.createTaskQuery().singleResult(); taskService.setVariables(task.getId(), Variables.createVariables().putValue("bar", "abc")); taskService.complete(task.getId()); //when runtimeService.removeVariable(processInstance.getId(), "bar"); //then HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery().singleResult(); assertEquals(HistoricVariableInstance.STATE_CREATED, variable.getState()); assertEquals("initial", variable.getName()); assertEquals("foo", variable.getValue()); }
@Deployment public void testForkParallelGatewayTreeCompaction() { // given runtimeService.startProcessInstanceByKey("process"); Task task1 = taskService .createTaskQuery() .taskDefinitionKey("task1") .singleResult(); Execution task2Execution = runtimeService .createExecutionQuery() .activityId("task2") .singleResult(); // when runtimeService.setVariableLocal(task2Execution.getId(), "foo", "bar"); taskService.complete(task1.getId()); // then assertEquals(1, runtimeService.createVariableInstanceQuery().count()); HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult(); assertNotNull(historicVariable); assertEquals("foo", historicVariable.getName()); }
@Deployment public void testNestedForkParallelGatewayTreeCompaction() { // given runtimeService.startProcessInstanceByKey("process"); Task task1 = taskService .createTaskQuery() .taskDefinitionKey("task1") .singleResult(); Execution task2Execution = runtimeService .createExecutionQuery() .activityId("task2") .singleResult(); // when runtimeService.setVariableLocal(task2Execution.getId(), "foo", "bar"); taskService.complete(task1.getId()); // then assertEquals(1, runtimeService.createVariableInstanceQuery().count()); HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery().singleResult(); assertNotNull(historicVariable); assertEquals("foo", historicVariable.getName()); }