@Deployment( resources = { "org/activiti/examples/bpmn/event/timer/BoundaryTimerEventTest.testInterruptingTimerDuration.bpmn" }) @Test public void testInterruptingTimerDuration() { // Start process instance RuntimeService runtimeService = activitiRule.getRuntimeService(); ProcessInstance pi = runtimeService.startProcessInstanceByKey("escalationExample"); // There should be one task, with a timer : first line support TaskService taskService = activitiRule.getTaskService(); Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult(); assertEquals("First line support", task.getName()); // Manually execute the job ManagementService managementService = activitiRule.getManagementService(); Job timer = managementService.createJobQuery().singleResult(); managementService.executeJob(timer.getId()); // The timer has fired, and the second task (secondlinesupport) now exists task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult(); assertEquals("Second line support", task.getName()); }
@Test @Deployment(resources = {PROCESS_RESOURCE}) public void processRejected() throws InterruptedException { Map<String, Object> procVars = createStartFormVariables(); ProcessInstance pi = activitiRule .getProcessEngine() .getRuntimeService() .startProcessInstanceByKey(PROCESS_KEY, procVars); // assertNotNull(pi); Task task = activitiRule.getTaskService().createTaskQuery().singleResult(); // assertNotNull(task); Map<String, Object> taskVars = new HashMap<String, Object>(); taskVars.put("decide", "reject"); activitiRule.getProcessEngine().getTaskService().complete(task.getId(), taskVars); HistoryService historyService = activitiRule.getHistoryService(); HistoricProcessInstance historicProcessInstance = historyService .createHistoricProcessInstanceQuery() .processInstanceId(pi.getProcessInstanceId()) .singleResult(); // assertNotNull(historicProcessInstance); // check that only one process running // assertEquals(pi.getProcessInstanceId(), historicProcessInstance.getId()); List<HistoricActivityInstance> activityList = historyService .createHistoricActivityInstanceQuery() .processInstanceId(pi.getProcessInstanceId()) .list(); JobQuery jquery = activitiRule.getManagementService().createJobQuery(); // check how many tasks must be done // assertEquals("done task count", 6, activityList.size()); // and the job is done // assertEquals("job is done", 0, jquery.count()); // assertEquals(0, activitiRule.getProcessEngine().getRuntimeService() // .createProcessInstanceQuery().count()); }
@Test @Deployment(resources = {"chapter4/bookorder.bpmn20.xml"}) public void queryHistoricVariableUpdates() { startAndComplete(); HistoryService historyService = activitiRule.getHistoryService(); List<HistoricDetail> historicVariableUpdateList = historyService.createHistoricDetailQuery().variableUpdates().list(); assertNotNull(historicVariableUpdateList); assertEquals(3, historicVariableUpdateList.size()); for (HistoricDetail historicDetail : historicVariableUpdateList) { assertTrue(historicDetail instanceof HistoricVariableUpdate); HistoricVariableUpdate historicVariableUpdate = (HistoricVariableUpdate) historicDetail; assertNotNull(historicVariableUpdate.getExecutionId()); System.out.println( "historic variable update, revision " + historicVariableUpdate.getRevision() + ", variable type name " + historicVariableUpdate.getVariableTypeName() + ", variable name " + historicVariableUpdate.getVariableName() + ", Variable value '" + historicVariableUpdate.getValue() + "'"); } }
private String startAndComplete() { RuntimeService runtimeService = activitiRule.getRuntimeService(); Map<String, Object> variableMap = new HashMap<String, Object>(); variableMap.put("isbn", "123456"); String processInstanceID = runtimeService.startProcessInstanceByKey("bookorder", variableMap).getId(); TaskService taskService = activitiRule.getTaskService(); Task task = taskService.createTaskQuery().taskCandidateGroup("sales").singleResult(); variableMap = new HashMap<String, Object>(); variableMap.put("extraInfo", "Extra information"); variableMap.put("isbn", "654321"); taskService.complete(task.getId(), variableMap); return processInstanceID; }
private String deployProcessString(String processString) { RepositoryService repositoryService = activitiRule.getRepositoryService(); String resourceName = "xmlString." + BpmnDeployer.BPMN_RESOURCE_SUFFIXES; return repositoryService .createDeployment() .addString(resourceName, processString) .deploy() .getId(); }
@Test @Deployment(resources = {PROCESS_RESOURCE}) public void startProcessInstance() throws InterruptedException { Map<String, Object> procVars = createStartFormVariables(); ProcessInstance pi = activitiRule .getProcessEngine() .getRuntimeService() .startProcessInstanceByKey(PROCESS_KEY, procVars); // assertNotNull(pi); activitiRule .getProcessEngine() .getRuntimeService() .deleteProcessInstance(pi.getProcessInstanceId(), "not needed, created only for test"); }
@Test public void startProcess() throws Exception { RepositoryService repositoryService = activitiRule.getRepositoryService(); TaskService taskService = activitiRule.getTaskService(); repositoryService .createDeployment() .addInputStream("process1.bpmn20.xml", new FileInputStream(filename)) .deploy(); RuntimeService runtimeService = activitiRule.getRuntimeService(); Map<String, Object> variableMap = new HashMap<String, Object>(); variableMap.put("name", "Activiti"); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("MyProcess", variableMap); assertNotNull(processInstance.getId()); System.out.println( "id " + processInstance.getId() + " " + processInstance.getProcessDefinitionId()); assertNotNull(taskService.createTaskQuery().taskAssignee("fg").singleResult()); }
@Test public void testDeployIdenticalProcessDefinitions() { List<String> deploymentIds = new ArrayList<String>(); deploymentIds.add( deployProcessString( ("<definitions " + NAMESPACE + " " + TARGET_NAMESPACE + ">" + " <process id='IDR' name='Insurance Damage Report' />" + "</definitions>"))); deploymentIds.add( deployProcessString( ("<definitions " + NAMESPACE + " " + TARGET_NAMESPACE + ">" + " <process id='IDR' name='Insurance Damage Report' />" + "</definitions>"))); RepositoryService repositoryService = activitiRule.getRepositoryService(); List<ProcessDefinition> processDefinitions = repositoryService .createProcessDefinitionQuery() .orderByProcessDefinitionKey() .asc() .orderByProcessDefinitionVersion() .desc() .list(); assertNotNull(processDefinitions); assertEquals(2, processDefinitions.size()); ProcessDefinition processDefinition = processDefinitions.get(0); assertEquals("IDR", processDefinition.getKey()); assertEquals("Insurance Damage Report", processDefinition.getName()); assertTrue(processDefinition.getId().startsWith("IDR:2")); assertEquals(2, processDefinition.getVersion()); processDefinition = processDefinitions.get(1); assertEquals("IDR", processDefinition.getKey()); assertEquals("Insurance Damage Report", processDefinition.getName()); assertTrue(processDefinition.getId().startsWith("IDR:1")); assertEquals(1, processDefinition.getVersion()); deleteDeployments(deploymentIds); }
@Test @Deployment(resources = {"chapter4/bookorder.bpmn20.xml"}) public void queryHistoricInstances() { String processInstanceID = startAndComplete(); HistoryService historyService = activitiRule.getHistoryService(); HistoricProcessInstance historicProcessInstance = historyService .createHistoricProcessInstanceQuery() .processInstanceId(processInstanceID) .singleResult(); assertNotNull(historicProcessInstance); assertEquals(processInstanceID, historicProcessInstance.getId()); System.out.println( "history process with definition id " + historicProcessInstance.getProcessDefinitionId() + ", started at " + historicProcessInstance.getStartTime() + ", ended at " + historicProcessInstance.getEndTime() + ", duration was " + historicProcessInstance.getDurationInMillis()); }
@Test @Deployment(resources = {"chapter4/bookorder.bpmn20.xml"}) public void queryHistoricActivities() { startAndComplete(); HistoryService historyService = activitiRule.getHistoryService(); List<HistoricActivityInstance> activityList = historyService.createHistoricActivityInstanceQuery().list(); assertEquals(4, activityList.size()); for (HistoricActivityInstance historicActivityInstance : activityList) { assertNotNull(historicActivityInstance.getActivityId()); System.out.println( "history activity " + historicActivityInstance.getActivityName() + ", type " + historicActivityInstance.getActivityType() + ", starttime " + historicActivityInstance.getStartTime() + ", endtime " + historicActivityInstance.getEndTime() + ", duration was " + historicActivityInstance.getDurationInMillis()); } }
@Before public void injectDependencies() throws Exception { MockitoAnnotations.initMocks(this); Mockitos.register(this); new TestContextManager(getClass()).prepareTestInstance(this); processEngine = TestHelper.getProcessEngine(activitiRule.getConfigurationResource()); activitiRule.setProcessEngine(processEngine); ActivitiFluentTestHelper.setUpEngineAndServices( activitiRule.getProcessEngine(), activitiRule.getProcessEngine().getRepositoryService(), activitiRule.getProcessEngine().getRuntimeService(), activitiRule.getProcessEngine().getTaskService(), activitiRule.getProcessEngine().getHistoryService(), activitiRule.getProcessEngine().getIdentityService(), activitiRule.getProcessEngine().getManagementService(), activitiRule.getProcessEngine().getFormService()); }
private void deleteDeployments(Collection<String> deploymentIds) { RepositoryService repositoryService = activitiRule.getRepositoryService(); for (String deploymentId : deploymentIds) { repositoryService.deleteDeployment(deploymentId); } }