use of org.activiti.engine.ManagementService in project Activiti by Activiti.
the class ReplayEventLogTest method testProcessInstanceStartEvents.
@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<String, Object>();
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<String, Object>();
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);
assertTrue(replayProcessInstance.getId().equals(processInstance.getId()) == false);
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();
}
use of org.activiti.engine.ManagementService in project Activiti by Activiti.
the class CustomMybatisMapperConfigurationTest method executeCustomMybatisMapperQuery.
@Test
public void executeCustomMybatisMapperQuery() throws Exception {
AnnotationConfigApplicationContext applicationContext = this.context(Application.class);
ManagementService managementService = applicationContext.getBean(ManagementService.class);
String processDefinitionId = managementService.executeCustomSql(new AbstractCustomSqlExecution<CustomMybatisMapper, String>(CustomMybatisMapper.class) {
@Override
public String execute(CustomMybatisMapper customMybatisMapper) {
return customMybatisMapper.loadProcessDefinitionIdByKey("waiter");
}
});
Assert.assertNotNull("the processDefinitionId should not be null!", processDefinitionId);
}
use of org.activiti.engine.ManagementService in project Activiti by Activiti.
the class CustomMybatisMapperConfigurationTest method executeCustomMybatisXmlQuery.
@Test
public void executeCustomMybatisXmlQuery() throws Exception {
AnnotationConfigApplicationContext applicationContext = this.context(Application.class);
ManagementService managementService = applicationContext.getBean(ManagementService.class);
String processDefinitionDeploymentId = managementService.executeCommand(new Command<String>() {
@Override
public String execute(CommandContext commandContext) {
return (String) commandContext.getDbSqlSession().selectOne("selectProcessDefinitionDeploymentIdByKey", "waiter");
}
});
Assert.assertNotNull("the processDefinitionDeploymentId should not be null!", processDefinitionDeploymentId);
}
use of org.activiti.engine.ManagementService in project Activiti by Activiti.
the class ActivitiRuleJunit4Test method testWaitForJobs.
// this is to show how JobTestHelper could be used to wait for jobs to be all processed
@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:
assertThat(managementService.createJobQuery().count()).isEqualTo(1);
JobTestHelper.waitForJobExecutorToProcessAllJobs(activitiRule, 5000L, 500L);
// the job is done
assertThat(managementService.createJobQuery().count()).isEqualTo(0);
}
Aggregations