Search in sources :

Example 1 with ManagementService

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();
}
Also used : ReplaySimulationRun(org.activiti.crystalball.simulator.ReplaySimulationRun) Task(org.activiti.engine.task.Task) RuntimeService(org.activiti.engine.RuntimeService) HashMap(java.util.HashMap) TaskService(org.activiti.engine.TaskService) EventLogEntry(org.activiti.engine.event.EventLogEntry) SimpleEventCalendar(org.activiti.crystalball.simulator.SimpleEventCalendar) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) HistoryService(org.activiti.engine.HistoryService) SimulationEventComparator(org.activiti.crystalball.simulator.SimulationEventComparator) EventLogTransformer(org.activiti.crystalball.simulator.delegate.event.impl.EventLogTransformer) ManagementService(org.activiti.engine.ManagementService) SimulationDebugger(org.activiti.crystalball.simulator.SimulationDebugger) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) SimulationEvent(org.activiti.crystalball.simulator.SimulationEvent) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl) Test(org.junit.Test)

Example 2 with ManagementService

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);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ManagementService(org.activiti.engine.ManagementService) CustomMybatisMapper(activiti.mappers.CustomMybatisMapper) Test(org.junit.Test)

Example 3 with ManagementService

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);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ManagementService(org.activiti.engine.ManagementService) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) Test(org.junit.Test)

Example 4 with ManagementService

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);
}
Also used : ManagementService(org.activiti.engine.ManagementService) RuntimeService(org.activiti.engine.RuntimeService) Test(org.junit.Test) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ManagementService (org.activiti.engine.ManagementService)4 Test (org.junit.Test)4 RuntimeService (org.activiti.engine.RuntimeService)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 CustomMybatisMapper (activiti.mappers.CustomMybatisMapper)1 HashMap (java.util.HashMap)1 ReplaySimulationRun (org.activiti.crystalball.simulator.ReplaySimulationRun)1 SimpleEventCalendar (org.activiti.crystalball.simulator.SimpleEventCalendar)1 SimulationDebugger (org.activiti.crystalball.simulator.SimulationDebugger)1 SimulationEvent (org.activiti.crystalball.simulator.SimulationEvent)1 SimulationEventComparator (org.activiti.crystalball.simulator.SimulationEventComparator)1 EventLogTransformer (org.activiti.crystalball.simulator.delegate.event.impl.EventLogTransformer)1 HistoryService (org.activiti.engine.HistoryService)1 TaskService (org.activiti.engine.TaskService)1 EventLogEntry (org.activiti.engine.event.EventLogEntry)1 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)1 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)1 NoExecutionVariableScope (org.activiti.engine.impl.el.NoExecutionVariableScope)1 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1