Search in sources :

Example 86 with DefaultProcessEventListener

use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.

the class TimerUpdateTest method updateTimerShortherDelayTest.

@Test(timeout = 30000)
public void updateTimerShortherDelayTest() {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(TIMER_NAME, 1);
    // delay is set for 5s
    setProcessScenario(TIMER_FILE);
    kieSession.addEventListener(countDownListener);
    final List<Long> list = new ArrayList<Long>();
    kieSession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            list.add(event.getProcessInstance().getId());
        }
    });
    Assertions.assertThat(list).isEmpty();
    long id = kieSession.startProcess(PROCESS_NAME).getId();
    long startTime = System.currentTimeMillis();
    Assertions.assertThat(list).isNotEmpty();
    // set delay to 3s
    kieSession.execute(new UpdateTimerCommand(id, TIMER_NAME, 3));
    countDownListener.waitTillCompleted();
    Assertions.assertThat(timerHasFired()).isTrue();
    long firedTime = timerFiredTime();
    long timeDifference = Math.abs(firedTime - startTime - 3000);
    logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
    Assertions.assertThat(timeDifference).isLessThan(500);
    Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) UpdateTimerCommand(org.jbpm.process.instance.command.UpdateTimerCommand) Test(org.junit.Test)

Example 87 with DefaultProcessEventListener

use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.

the class TimerUpdateTest method updateBoundaryTimerTest.

@Test(timeout = 30000)
public void updateBoundaryTimerTest() {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(BOUNDARY_TIMER_NAME, 1);
    // timer is set for long duration (100s)
    setProcessScenario(BOUNDARY_TIMER_FILE);
    final List<Long> list = new ArrayList<Long>();
    kieSession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            list.add(event.getProcessInstance().getId());
        }
    });
    kieSession.addEventListener(countDownListener);
    Assertions.assertThat(list).isEmpty();
    long id = kieSession.startProcess(BOUNDARY_PROCESS_NAME).getId();
    long startTime = System.currentTimeMillis();
    Assertions.assertThat(list).isNotEmpty();
    // set timer delay to 3s
    kieSession.execute(new UpdateTimerCommand(id, BOUNDARY_TIMER_ATTACHED_TO_NAME, 3));
    countDownListener.waitTillCompleted();
    Assertions.assertThat(timerHasFired()).isTrue();
    long firedTime = timerFiredTime();
    long timeDifference = Math.abs(firedTime - startTime - 3000);
    logger.info("Start time: " + startTime + ", fired time: " + firedTime + ", difference: " + (firedTime - startTime));
    Assertions.assertThat(timeDifference).isLessThan(1000);
    Assertions.assertThat(kieSession.getProcessInstance(id)).isNull();
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) UpdateTimerCommand(org.jbpm.process.instance.command.UpdateTimerCommand) Test(org.junit.Test)

Example 88 with DefaultProcessEventListener

use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.

the class StartEventTest method testSignalStartEventDataMapping.

@Test
@BZ("1154557")
public void testSignalStartEventDataMapping() throws Exception {
    KieSession ksession = createKSession(SIGNAL_DATA_MAPPING);
    final List<Long> list = new ArrayList<Long>();
    final List<String> variableList = new ArrayList<String>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        public void afterProcessStarted(ProcessStartedEvent event) {
            list.add(event.getProcessInstance().getId());
            variableList.add((String) ((WorkflowProcessInstance) event.getProcessInstance()).getVariable("x"));
        }
    });
    ksession.signalEvent("MyStartSignal", "NewValue");
    Assertions.assertThat(list).hasSize(1);
    Assertions.assertThat(variableList.get(0)).isEqualTo("NewValue");
}
Also used : ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 89 with DefaultProcessEventListener

use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.

the class HumanTaskSwimlaneTest method testSwimlaneWithMultipleActorsAssigned.

@Test
public void testSwimlaneWithMultipleActorsAssigned() {
    createRuntimeManager(SWIMLANE_MULTIPLE_ACTORS);
    String user = "john";
    RuntimeEngine runtime = getRuntimeEngine();
    KieSession kSession = runtime.getKieSession();
    TaskService taskservice = runtime.getTaskService();
    kSession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
            if (event.getNodeInstance().getNodeName().equals("TASK")) {
                Object swimlaneActorId = ((HumanTaskNodeInstance) event.getNodeInstance()).getWorkItem().getParameter("SwimlaneActorId");
                assertNull(swimlaneActorId);
            }
        }
    });
    Map<String, Object> map = new HashMap<String, Object>();
    ProcessInstance instance = kSession.startProcess(SWIMLANE_MULTIPLE_ACTORS_ID, map);
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Ready);
    statuses.add(Status.Reserved);
    statuses.add(Status.InProgress);
    List<TaskSummary> tasks = taskservice.getTasksByStatusByProcessInstanceId(instance.getId(), statuses, "en_US");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    assertEquals(Status.Ready, task.getStatus());
    taskservice.claim(task.getId(), user);
    taskservice.start(task.getId(), user);
    tasks = taskservice.getTasksByStatusByProcessInstanceId(instance.getId(), statuses, "en_US");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    task = tasks.get(0);
    assertEquals(Status.InProgress, task.getStatus());
    taskservice.complete(task.getId(), user, map);
    assertProcessInstanceCompleted(instance.getId());
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) ArrayList(java.util.ArrayList) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) TaskSummary(org.kie.api.task.model.TaskSummary) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 90 with DefaultProcessEventListener

use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.

the class PerCaseRuntimeManagerTest method testMultipleProcessesInSingleCaseCompletedInSequence.

@Test
public void testMultipleProcessesInSingleCaseCompletedInSequence() {
    final Set<Long> ksessionUsed = new HashSet<Long>();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(new DefaultProcessEventListener() {

                @Override
                public void beforeProcessStarted(ProcessStartedEvent event) {
                    ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
                }
            });
            return listeners;
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment);
    assertNotNull(manager);
    // ksession for process instance #1
    // since there is no process instance yet we need to get new session
    RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    long ksession1Id = ksession.getIdentifier();
    assertTrue(ksession1Id > 0);
    ProcessInstance pi1 = ksession.startProcess("ScriptTask");
    assertEquals(ProcessInstance.STATE_COMPLETED, pi1.getState());
    manager.disposeRuntimeEngine(runtime);
    runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
    ksession = runtime.getKieSession();
    ProcessInstance pi2 = ksession.startProcess("ScriptTask");
    assertEquals(ProcessInstance.STATE_COMPLETED, pi2.getState());
    // there should be only one ksession used
    assertEquals(1, ksessionUsed.size());
    assertEquals(ksession1Id, ksessionUsed.iterator().next().longValue());
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)98 Test (org.junit.Test)87 ArrayList (java.util.ArrayList)69 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)59 KieBase (org.kie.api.KieBase)57 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)48 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)48 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)40 KieSession (org.kie.api.runtime.KieSession)38 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)30 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)27 WorkItem (org.kie.api.runtime.process.WorkItem)27 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)26 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)25 HashMap (java.util.HashMap)24 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)19 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)16 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)11 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)9 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)7