Java Code Examples for org.flowable.engine.RuntimeService#startProcessInstanceByKey()
The following examples show how to use
org.flowable.engine.RuntimeService#startProcessInstanceByKey() .
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: ActivitiRuleJunit4Test.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = { "org/activiti/engine/test/bpmn/async/AsyncTaskTest.testAsyncTask.bpmn20.xml" }) public void testWaitForJobs() { RuntimeService runtimeService = activitiRule.getRuntimeService(); ManagementService managementService = activitiRule.getManagementService(); // start process runtimeService.startProcessInstanceByKey("asyncTask"); // now there should be one job in the database: assertEquals(1, managementService.createJobQuery().count()); JobTestHelper.waitForJobExecutorToProcessAllJobs(activitiRule, 7000L, 500L); // the job is done assertEquals(0, managementService.createJobQuery().count()); }
Example 2
Source File: MuleVMTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test public void send() throws Exception { Assert.assertTrue(muleContext.isStarted()); ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); Deployment deployment = repositoryService.createDeployment() .addClasspathResource("org/activiti/mule/testVM.bpmn20.xml") .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE) .deploy(); RuntimeService runtimeService = processEngine.getRuntimeService(); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess"); Assert.assertFalse(processInstance.isEnded()); Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable"); Assert.assertEquals(30, result); runtimeService.deleteProcessInstance(processInstance.getId(), "test"); processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId()); repositoryService.deleteDeployment(deployment.getId()); assertAndEnsureCleanDb(processEngine); ProcessEngines.destroy(); }
Example 3
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" }) public void logAddGroup(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); assertThat(processInstance).isNotNull(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); assertThat(task).isNotNull(); try { taskService.addGroupIdentityLink(task.getId(), "newCandidateGroup", IdentityLinkType.PARTICIPANT); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); assertThat(logEntries).hasSize(2); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_IDENTITY_LINK_ADDED") .list(); assertThat(logEntries).hasSize(1); assertThat(logEntries.get(0).getData()).contains( "\"type\":\"participant\"", "\"groupId\":\"newCandidateGroup\"" ); } } finally { taskService.complete(task.getId()); deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId()); } }
Example 4
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" }) public void logProcessTaskEvents(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); assertThat(processInstance).isNotNull(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); assertThat(task).isNotNull(); try { taskService.setAssignee(task.getId(), "newAssignee"); taskService.setOwner(task.getId(), "newOwner"); taskService.complete(task.getId()); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); assertThat(logEntries).hasSize(4); HistoricTaskLogEntry logEntry = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_CREATED").singleResult(); assertThat(logEntry).isNotNull(); assertThat(logEntry.getProcessDefinitionId()).isEqualTo(processInstance.getProcessDefinitionId()); assertThat(logEntry.getExecutionId()).isEqualTo(task.getExecutionId()); assertThat(logEntry.getProcessInstanceId()).isEqualTo(processInstance.getId()); assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_ASSIGNEE_CHANGED").count()).isEqualTo(1); assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_OWNER_CHANGED").count()).isEqualTo(1); assertThat(historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).type("USER_TASK_COMPLETED").count()).isEqualTo(1); } } finally { deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId()); } }
Example 5
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" }) public void logAddCandidateGroup(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); assertThat(processInstance).isNotNull(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); assertThat(task).isNotNull(); try { taskService.addCandidateGroup(task.getId(), "newCandidateGroup"); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); assertThat(logEntries).hasSize(2); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_IDENTITY_LINK_ADDED") .list(); assertThat(logEntries).hasSize(1); assertThat(logEntries.get(0).getData()).contains( "\"type\":\"candidate\"", "\"groupId\":\"newCandidateGroup\"" ); } } finally { taskService.complete(task.getId()); deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId()); } }
Example 6
Source File: ActivitiRuleJunit4Test.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment public void ruleUsageExample() { RuntimeService runtimeService = activitiRule.getRuntimeService(); runtimeService.startProcessInstanceByKey("ruleUsage"); TaskService taskService = activitiRule.getTaskService(); org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult(); assertEquals("My Task", task.getName()); taskService.complete(task.getId()); assertEquals(0, runtimeService.createProcessInstanceQuery().count()); }
Example 7
Source File: Application.java From flowable-engine with Apache License 2.0 | 5 votes |
@Bean CommandLineRunner basics(final RuntimeService runtimeService) { return new CommandLineRunner() { @Override public void run(String... strings) throws Exception { runtimeService.startProcessInstanceByKey("waiter", Collections.singletonMap("customerId", (Object) 243L)); } }; }
Example 8
Source File: ProcessWithFormTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test public void completeTaskWithoutValidationOnModelLevelBadExpression(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService, TaskService taskService, RepositoryService repositoryService) { repositoryService.createDeployment(). addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml", ONE_TASK_PROCESS. replace("START_EVENT_VALIDATION", "true"). replace("USER_TASK_VALIDATION", "${BAD_EXPRESSION}") ). deploy(); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey( "oneTaskWithFormSideEffectProcess", Collections.emptyMap() ); SideEffectExecutionListener.reset(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService(); FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult(); assertThatThrownBy(() -> taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator"))) .isInstanceOf(FlowableException.class) .hasMessage("Unknown property used in expression: ${BAD_EXPRESSION}"); assertThat(SideEffectExecutionListener.getSideEffect()).isZero(); }
Example 9
Source File: ProcessWithFormTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test public void completeTaskWithValidationOnModelLevelStringExpression(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService, TaskService taskService, RepositoryService repositoryService) { repositoryService.createDeployment(). addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml", ONE_TASK_PROCESS. replace("START_EVENT_VALIDATION", "true"). replace("USER_TASK_VALIDATION", "${true}") ). deploy(); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey( "oneTaskWithFormSideEffectProcess", Collections.emptyMap() ); SideEffectExecutionListener.reset(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService(); FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult(); assertThatThrownBy(() -> taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator"))) .isInstanceOf(RuntimeException.class) .hasMessage("validation failed"); assertThat(SideEffectExecutionListener.getSideEffect()).isZero(); }
Example 10
Source File: FlowableJupiterTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/bpmn/async/AsyncTaskTest.testAsyncTask.bpmn20.xml" }) void testWaitForJobs(FlowableTestHelper testHelper, RuntimeService runtimeService, ManagementService managementService) { // start process runtimeService.startProcessInstanceByKey("asyncTask"); // now there should be one job in the database: assertThat(managementService.createJobQuery().count()).isEqualTo(1); testHelper.waitForJobExecutorToProcessAllJobs(7000L, 500L); // the job is done assertThat(managementService.createJobQuery().count()).isZero(); }
Example 11
Source File: ReplayRunTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test public void testProcessInstanceStartEvents() throws Exception { ProcessEngineImpl processEngine = initProcessEngine(); TaskService taskService = processEngine.getTaskService(); RuntimeService runtimeService = processEngine.getRuntimeService(); Map<String, Object> variables = new HashMap<>(); variables.put(TEST_VARIABLE, TEST_VALUE); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(USERTASK_PROCESS, BUSINESS_KEY, variables); Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult(); TimeUnit.MILLISECONDS.sleep(50); taskService.complete(task.getId()); final SimulationDebugger simRun = new ReplaySimulationRun(processEngine, getReplayHandlers(processInstance.getId())); simRun.init(new NoExecutionVariableScope()); // original process is finished - there should not be any running process instance/task assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count()); assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); simRun.step(); // replay process was started assertEquals(1, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count()); // there should be one task assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); simRun.step(); // userTask was completed - replay process was finished assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count()); assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); simRun.close(); processEngine.close(); ProcessEngines.destroy(); }
Example 12
Source File: ProcessWithFormTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test public void completeTaskWithoutValidationOnModelLevelExpression(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService, TaskService taskService, RepositoryService repositoryService) { Deployment deployment = repositoryService.createDeployment(). addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml", ONE_TASK_PROCESS. replace("START_EVENT_VALIDATION", "${true}"). replace("USER_TASK_VALIDATION", "${allowValidation}") ). deploy(); ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult(); assertThatThrownBy(() -> runtimeService.startProcessInstanceWithForm(processDefinition.getId(), "__COMPLETE", Collections.singletonMap("allowValidation", Boolean.TRUE),"oneTaskWithFormSideEffectProcess")) .isInstanceOf(RuntimeException.class) .hasMessageContaining("validation failed"); assertThat(SideEffectExecutionListener.getSideEffect()).isZero(); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey( "oneTaskWithFormSideEffectProcess", Collections.singletonMap("allowValidation", Boolean.TRUE) ); SideEffectExecutionListener.reset(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService(); FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult(); assertThatThrownBy(() -> taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator"))) .isInstanceOf(RuntimeException.class); assertThat(SideEffectExecutionListener.getSideEffect()).isZero(); }
Example 13
Source File: ProcessWithFormTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test public void completeTaskWithValidationOnMissingModelLevel(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService, TaskService taskService, RepositoryService repositoryService) { repositoryService.createDeployment(). addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml", ONE_TASK_PROCESS. replace("flowable:formFieldValidation=\"START_EVENT_VALIDATION\"", ""). replace("flowable:formFieldValidation=\"USER_TASK_VALIDATION\"", "") ). deploy(); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey( "oneTaskWithFormSideEffectProcess", Collections.emptyMap() ); SideEffectExecutionListener.reset(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService(); FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult(); assertThatThrownBy(() -> taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator"))) .isInstanceOf(RuntimeException.class) .hasMessage("validation failed"); assertThat(SideEffectExecutionListener.getSideEffect()).isZero(); }
Example 14
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" }) public void logDeleteCandidateGroup(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); assertThat(processInstance).isNotNull(); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); assertThat(task).isNotNull(); taskService.addCandidateGroup(task.getId(), "newCandidateGroup"); try { taskService.deleteCandidateGroup(task.getId(), "newCandidateGroup"); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); assertThat(logEntries).hasSize(3); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_IDENTITY_LINK_REMOVED") .list(); assertThat(logEntries).hasSize(1); assertThat(logEntries.get(0).getData()).contains( "\"type\":\"candidate\"", "\"groupId\":\"newCandidateGroup\"" ); } } finally { taskService.complete(task.getId()); deleteTaskWithLogEntries(taskService, managementService, processEngineConfiguration, task.getId()); } }
Example 15
Source File: FlowableJupiterTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment void extensionUsageExample(ProcessEngine processEngine) { RuntimeService runtimeService = processEngine.getRuntimeService(); runtimeService.startProcessInstanceByKey("extensionUsage"); TaskService taskService = processEngine.getTaskService(); org.flowable.task.api.Task task = taskService.createTaskQuery().singleResult(); assertThat(task.getName()).isEqualTo("My Task"); taskService.complete(task.getId()); assertThat(runtimeService.createProcessInstanceQuery().count()).isZero(); assertThat(processEngine.getName()).as("process engine name").isEqualTo(ProcessEngines.NAME_DEFAULT); }
Example 16
Source File: StartProcessInstanceTestDelegate.java From flowable-engine with Apache License 2.0 | 4 votes |
public void execute(DelegateExecution execution) { RuntimeService runtimeService = Context.getProcessEngineConfiguration().getRuntimeService(); runtimeService.startProcessInstanceByKey("oneTaskProcess"); }
Example 17
Source File: HistoryServiceTaskLogTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test @Deployment(resources = "org/flowable/engine/test/api/task/TaskIdentityLinksTest.testCustomIdentityLink.bpmn20.xml") public void logIdentityLinkEventsForProcessIdentityLinks(RuntimeService runtimeService, TaskService taskService, HistoryService historyService, ManagementService managementService, ProcessEngineConfiguration processEngineConfiguration) { runtimeService.startProcessInstanceByKey("customIdentityLink"); List<org.flowable.task.api.Task> tasks = taskService.createTaskQuery().taskInvolvedUser("kermit").list(); assertThat(tasks).hasSize(1); task = tasks.get(0); if (HistoryTestHelper.isHistoricTaskLoggingEnabled(processEngineConfiguration)) { List<HistoricTaskLogEntry> logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); // create, identityLinkAdded, identityLinkAdded assertThat(logEntries).hasSize(3); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_IDENTITY_LINK_ADDED") .list(); assertThat(logEntries).hasSize(2); boolean hasKermit = false; boolean hasManagement = false; String data = logEntries.get(0).getData(); String data1 = logEntries.get(1).getData(); if ((data.contains("\"type\":\"businessAdministrator\"") && data.contains("\"userId\":\"kermit\"")) || (data1.contains("\"type\":\"businessAdministrator\"") && data1.contains("\"userId\":\"kermit\""))) { hasKermit = true; } if ((data.contains("\"type\":\"businessAdministrator\"") && data.contains("\"groupId\":\"management\"")) || (data1.contains("\"type\":\"businessAdministrator\"") && data1.contains("\"groupId\":\"management\""))) { hasManagement = true; } assertThat(hasKermit).isTrue(); assertThat(hasManagement).isTrue(); taskService.complete(tasks.get(0).getId()); HistoryTestHelper.waitForJobExecutorToProcessAllHistoryJobs(processEngineConfiguration, managementService, 10000, 200); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()).list(); // + completed event. Do not expect identity link removed events assertThat(logEntries).hasSize(4); logEntries = historyService.createHistoricTaskLogEntryQuery().taskId(task.getId()) .type("USER_TASK_COMPLETED") .list(); assertThat(logEntries).hasSize(1); } }
Example 18
Source File: ProcessDefinitionCacheTest.java From flowable-engine with Apache License 2.0 | 4 votes |
public void testDeployRevisedProcessAfterDeleteOnOtherProcessEngine() { // Setup both process engines StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration(); standaloneProcessEngineConfiguration.setEngineName("reboot-test-schema"); standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000"); standaloneProcessEngineConfiguration.setAsyncExecutorActivate(false); standaloneProcessEngineConfiguration.setFlowable5CompatibilityEnabled(true); ProcessEngine processEngine1 = standaloneProcessEngineConfiguration.buildProcessEngine(); RepositoryService repositoryService1 = processEngine1.getRepositoryService(); StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration2 = new StandaloneProcessEngineConfiguration(); standaloneProcessEngineConfiguration2.setEngineName("reboot-test"); standaloneProcessEngineConfiguration2.setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE); standaloneProcessEngineConfiguration2.setJdbcUrl("jdbc:h2:mem:activiti-process-cache-test;DB_CLOSE_DELAY=1000"); standaloneProcessEngineConfiguration2.setAsyncExecutorActivate(false); standaloneProcessEngineConfiguration2.setFlowable5CompatibilityEnabled(true); ProcessEngine processEngine2 = standaloneProcessEngineConfiguration2.buildProcessEngine(); RepositoryService repositoryService2 = processEngine2.getRepositoryService(); RuntimeService runtimeService2 = processEngine2.getRuntimeService(); TaskService taskService2 = processEngine2.getTaskService(); // Deploy first version of process: start->originalTask->end on first process engine String deploymentId = repositoryService1.createDeployment() .addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml") .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE) .deploy() .getId(); // Start process instance on second engine String processDefinitionId = repositoryService2.createProcessDefinitionQuery().singleResult().getId(); runtimeService2.startProcessInstanceById(processDefinitionId); org.flowable.task.api.Task task = taskService2.createTaskQuery().singleResult(); assertEquals("original task", task.getName()); // Delete the deployment on second process engine repositoryService2.deleteDeployment(deploymentId, true); assertEquals(0, repositoryService2.createDeploymentQuery().count()); assertEquals(0, runtimeService2.createProcessInstanceQuery().count()); // deploy a revised version of the process: start->revisedTask->end on first process engine // // Before the bugfix, this would set the cache on the first process engine, // but the second process engine still has the original process definition in his cache. // Since there is a deployment delete in between, the new generated process definition id is the same // as in the original deployment, making the second process engine using the old cached process definition. deploymentId = repositoryService1.createDeployment() .addClasspathResource("org/activiti/engine/test/cache/revisedProcess.bpmn20.xml") .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE) .deploy() .getId(); // Start process instance on second process engine -> must use revised process definition repositoryService2.createProcessDefinitionQuery().singleResult().getId(); runtimeService2.startProcessInstanceByKey("oneTaskProcess"); task = taskService2.createTaskQuery().singleResult(); assertEquals("revised task", task.getName()); // cleanup repositoryService1.deleteDeployment(deploymentId, true); processEngine1.close(); processEngine2.close(); }
Example 19
Source File: ProcessTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test public void testCompleteTaskWithAnotherForm() { ProcessEngineConfiguration processEngineConfiguration = (ProcessEngineConfiguration) appEngineConfiguration.getEngineConfigurations() .get(EngineConfigurationConstants.KEY_PROCESS_ENGINE_CONFIG); RuntimeService runtimeService = processEngineConfiguration.getRuntimeService(); TaskService taskService = processEngineConfiguration.getTaskService(); FormEngineConfiguration formEngineConfiguration = (FormEngineConfiguration) appEngineConfiguration.getEngineConfigurations() .get(EngineConfigurationConstants.KEY_FORM_ENGINE_CONFIG); AppDeployment deployment = appRepositoryService.createDeployment() .addClasspathResource("org/flowable/engine/configurator/test/oneTaskWithFormProcess.bpmn20.xml") .addClasspathResource("org/flowable/engine/configurator/test/another.form") .addClasspathResource("org/flowable/engine/configurator/test/simple.form").deploy(); try { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTask"); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); assertNotNull(task); runtimeService.addUserIdentityLink(processInstance.getId(), "anotherUser", IdentityLinkType.STARTER); taskService.addUserIdentityLink(task.getId(), "testUser", IdentityLinkType.PARTICIPANT); assertEquals(2, runtimeService.getIdentityLinksForProcessInstance(processInstance.getId()).size()); assertEquals(1, taskService.getIdentityLinksForTask(task.getId()).size()); FormDefinition formDefinition = formEngineConfiguration.getFormRepositoryService().createFormDefinitionQuery().formDefinitionKey("anotherForm").singleResult(); assertNotNull(formDefinition); Map<String, Object> variables = new HashMap<>(); variables.put("anotherInput", "test"); taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), null, variables); assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).count()); } finally { appRepositoryService.deleteDeployment(deployment.getId(), true); processEngineConfiguration.getRepositoryService() .createDeploymentQuery() .parentDeploymentId(deployment.getId()) .list() .forEach(processDeployment -> processEngineConfiguration.getRepositoryService().deleteDeployment(processDeployment.getId(), true)); formEngineConfiguration.getFormRepositoryService() .createDeploymentQuery() .parentDeploymentId(deployment.getId()) .list() .forEach(formDeployment -> formEngineConfiguration.getFormRepositoryService().deleteDeployment(formDeployment.getId(), true)); } }
Example 20
Source File: ReplayEventLogTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test public void testProcessInstanceStartEvents() throws Exception { ProcessEngineImpl processEngine = initProcessEngine(); TaskService taskService = processEngine.getTaskService(); RuntimeService runtimeService = processEngine.getRuntimeService(); ManagementService managementService = processEngine.getManagementService(); HistoryService historyService = processEngine.getHistoryService(); // record events Map<String, Object> variables = new HashMap<>(); variables.put(TEST_VARIABLE, TEST_VALUE); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(USERTASK_PROCESS, BUSINESS_KEY, variables); Task task = taskService.createTaskQuery().taskDefinitionKey("userTask").singleResult(); TimeUnit.MILLISECONDS.sleep(50); variables = new HashMap<>(); variables.put(TASK_TEST_VARIABLE, TASK_TEST_VALUE); taskService.complete(task.getId(), variables); // transform log events List<EventLogEntry> eventLogEntries = managementService.getEventLogEntries(null, null); EventLogTransformer transformer = new EventLogTransformer(getTransformers()); List<SimulationEvent> simulationEvents = transformer.transform(eventLogEntries); SimpleEventCalendar eventCalendar = new SimpleEventCalendar(processEngine.getProcessEngineConfiguration().getClock(), new SimulationEventComparator()); eventCalendar.addEvents(simulationEvents); // replay process instance run final SimulationDebugger simRun = new ReplaySimulationRun(processEngine, eventCalendar, getReplayHandlers(processInstance.getId())); simRun.init(new NoExecutionVariableScope()); // original process is finished - there should not be any running process instance/task assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count()); assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); simRun.step(); // replay process was started ProcessInstance replayProcessInstance = runtimeService.createProcessInstanceQuery() .processDefinitionKey(USERTASK_PROCESS) .singleResult(); assertNotNull(replayProcessInstance); assertNotEquals(replayProcessInstance.getId(), processInstance.getId()); assertEquals(TEST_VALUE, runtimeService.getVariable(replayProcessInstance.getId(), TEST_VARIABLE)); // there should be one task assertEquals(1, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); simRun.step(); // userTask was completed - replay process was finished assertEquals(0, runtimeService.createProcessInstanceQuery().processDefinitionKey(USERTASK_PROCESS).count()); assertEquals(0, taskService.createTaskQuery().taskDefinitionKey("userTask").count()); HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery() .processInstanceId(replayProcessInstance.getId()) .variableName(TASK_TEST_VARIABLE) .singleResult(); assertNotNull(variableInstance); assertEquals(TASK_TEST_VALUE, variableInstance.getValue()); // close simulation simRun.close(); processEngine.close(); ProcessEngines.destroy(); }