Search in sources :

Example 16 with ProcessStartedEvent

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

the class IdentityProviderAwareProcessListenerTest method testSetUser.

@Test
public void testSetUser() {
    final IdentityProvider identityProvider = mock(IdentityProvider.class);
    final String userId = "userId";
    when(identityProvider.getName()).thenReturn(userId);
    when(environment.get("IdentityProvider")).thenReturn(identityProvider);
    final WorkflowProcessInstance processInstance = mock(WorkflowProcessInstance.class);
    final HashMap<String, Object> metaData = new HashMap<>();
    when(processInstance.getMetaData()).thenReturn(metaData);
    final ProcessStartedEvent event = new ProcessStartedEventImpl(processInstance, mock(KieRuntime.class));
    listener.beforeProcessStarted(event);
    assertEquals(userId, metaData.get("OwnerId"));
    verify(processInstance).setVariable("initiator", userId);
}
Also used : HashMap(java.util.HashMap) KieRuntime(org.kie.api.runtime.KieRuntime) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) IdentityProvider(org.kie.internal.identity.IdentityProvider) ProcessStartedEventImpl(org.drools.core.event.ProcessStartedEventImpl) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test)

Example 17 with ProcessStartedEvent

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

the class GlobalQuartzDBTimerServiceTest method testContinueTimerWithMisfire.

@Test(timeout = 25000)
public void testContinueTimerWithMisfire() throws Exception {
    // RHBPMS-4729
    System.setProperty("org.quartz.properties", "quartz-db-short-misfire.properties");
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 2);
    // prepare listener to assert results
    final List<Long> timerExporations = new ArrayList<Long>();
    ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            timerExporations.add(event.getProcessInstance().getId());
        }
    };
    // No special configuration for TimerService in order to test RuntimeManager default
    environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/TimerStart2.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
    manager = getManager(environment, true);
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    countDownListener.waitTillCompleted();
    manager.disposeRuntimeEngine(runtime);
    manager.close();
    System.out.println("==== manager.close() ====");
    countDownListener.reset(3);
    // Simulate interval between shutdown and start so the Trigger is older than (now - misfireThreshold)
    Thread.sleep(5000);
    // ---- restart ----
    environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/TimerStart2.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
    manager = getManager(environment, true);
    countDownListener.waitTillCompleted(4000);
    assertEquals(5, timerExporations.size());
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) 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)

Example 18 with ProcessStartedEvent

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

the class TimerUpdateTest method updateTimerLongerDelayTest.

@Test(timeout = 30000)
public void updateTimerLongerDelayTest() {
    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 8s
    kieSession.execute(new UpdateTimerCommand(id, TIMER_NAME, 8));
    countDownListener.waitTillCompleted();
    Assertions.assertThat(timerHasFired()).isTrue();
    long firedTime = timerFiredTime();
    long timeDifference = Math.abs(firedTime - startTime - 8000);
    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 19 with ProcessStartedEvent

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

the class TimerUpdateTest method updateTimerSubprocessLongerDelayTest.

@Test(timeout = 30000)
public void updateTimerSubprocessLongerDelayTest() {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener(TIMER_SUBPROCESS_NAME, 1);
    // delay is set for 5s
    setProcessScenario(TIMER_SUBPROCESS_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());
        }

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (TIMER_SUBPROCESS_NAME.equals(event.getNodeInstance().getNodeName())) {
                System.setProperty(TIMER_FIRED_TEXT, "");
                System.setProperty(TIMER_FIRED_TIME_PROP, String.valueOf(System.currentTimeMillis()));
            }
        }
    });
    Assertions.assertThat(list).isEmpty();
    long id = kieSession.startProcess(PROCESS_SUBPROCESS_NAME).getId();
    long startTime = System.currentTimeMillis();
    Assertions.assertThat(list).isNotEmpty();
    // set delay to 8s
    kieSession.execute(new UpdateTimerCommand(id, TIMER_SUBPROCESS_NAME, 8));
    countDownListener.waitTillCompleted();
    Assertions.assertThat(timerHasFired()).isTrue();
    long firedTime = timerFiredTime();
    long timeDifference = Math.abs(firedTime - startTime - 8000);
    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) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) UpdateTimerCommand(org.jbpm.process.instance.command.UpdateTimerCommand) Test(org.junit.Test)

Example 20 with ProcessStartedEvent

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

the class TimerUpdateTest method updateTimerBeforeDelayTest.

@Test(timeout = 30000)
public void updateTimerBeforeDelayTest() {
    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 on time that passed -> expected that timer fired immediately
    kieSession.execute(new UpdateTimerCommand(id, TIMER_NAME, -5));
    countDownListener.waitTillCompleted();
    Assertions.assertThat(timerHasFired()).isTrue();
    long firedTime = timerFiredTime();
    long timeDifference = Math.abs(firedTime - startTime);
    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)

Aggregations

ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)57 Test (org.junit.Test)55 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)48 ArrayList (java.util.ArrayList)45 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)29 KieBase (org.kie.api.KieBase)29 KieSession (org.kie.api.runtime.KieSession)23 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)19 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)17 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)15 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)12 HashMap (java.util.HashMap)10 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)9 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)8 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)8 ProcessVariableChangedEvent (org.kie.api.event.process.ProcessVariableChangedEvent)8 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)8 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)7 ProcessEvent (org.kie.api.event.process.ProcessEvent)6 WorkItem (org.kie.api.runtime.process.WorkItem)6