Search in sources :

Example 11 with IterableProcessEventListener

use of org.jbpm.test.listener.IterableProcessEventListener in project jbpm by kiegroup.

the class DataObjectTest method testDataObject.

/**
 * DataObject is linked via association with Human Task. Work item should
 * obtain this DataObject in parameters.
 */
@Test(timeout = 30000)
public void testDataObject() {
    KieSession ksession = createKSession(PROCESS);
    IterableProcessEventListener listener = new IterableProcessEventListener();
    ksession.addEventListener(listener);
    Map<String, Object> params = new HashMap<String, Object>();
    Person mojmir = new Person("Mojmir");
    params.put("person", mojmir);
    JbpmJUnitBaseTestCase.TestWorkItemHandler wih = getTestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", wih);
    StartProcessCommand spc = new StartProcessCommand();
    spc.setProcessId(PROCESS_ID);
    spc.setParameters(params);
    ksession.execute(spc);
    assertChangedVariable(listener, "person", null, mojmir);
    assertProcessStarted(listener, PROCESS_ID);
    assertNextNode(listener, "start");
    assertTriggered(listener, "userTask");
    WorkItem wi = wih.getWorkItem();
    assertTrue(wi.getParameters().containsKey("PersonInput"));
    Object param = wi.getParameter("PersonInput");
    assertTrue(param instanceof Person);
    Person userTaskInput = (Person) param;
    assertEquals("Mojmir", userTaskInput.getName());
    listener.clear();
    ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
    assertLeft(listener, "userTask");
    assertNextNode(listener, "end");
    assertProcessCompleted(listener, PROCESS_ID);
}
Also used : HashMap(java.util.HashMap) IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) JbpmJUnitBaseTestCase(org.jbpm.test.JbpmJUnitBaseTestCase) KieSession(org.kie.api.runtime.KieSession) Person(org.jbpm.test.domain.Person) StartProcessCommand(org.drools.core.command.runtime.process.StartProcessCommand) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 12 with IterableProcessEventListener

use of org.jbpm.test.listener.IterableProcessEventListener in project jbpm by kiegroup.

the class StartEventTest method testSignalStartEvent.

@Test(timeout = 30000)
public void testSignalStartEvent() {
    KieSession ksession = createKSession(SIGNAL);
    IterableProcessEventListener events = new IterableProcessEventListener();
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    ksession.addEventListener(events);
    ksession.addEventListener(process);
    Command<?> cmd = getCommands().newSignalEvent("start", null);
    ksession.execute(cmd);
    Assertions.assertThat(process.wasProcessStarted(SIGNAL_ID)).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(SIGNAL_ID)).isTrue();
    assertProcessStarted(events, SIGNAL_ID);
    assertNextNode(events, "start");
    assertNextNode(events, "script");
    assertNextNode(events, "end");
    assertProcessCompleted(events, SIGNAL_ID);
    Assertions.assertThat(events.hasNext()).isFalse();
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 13 with IterableProcessEventListener

use of org.jbpm.test.listener.IterableProcessEventListener in project jbpm by kiegroup.

the class ExclusiveGatewayTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    ksession = createKSession(EXCLUSIVE_GATEWAY);
    iterableListener = new IterableProcessEventListener();
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) Before(org.junit.Before)

Example 14 with IterableProcessEventListener

use of org.jbpm.test.listener.IterableProcessEventListener in project jbpm by kiegroup.

the class EndEventTest method testNoneEndEvent.

@Test(timeout = 30000)
public void testNoneEndEvent() {
    KieSession ksession = createKSession(NONE);
    IterableProcessEventListener events = new IterableProcessEventListener();
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    ksession.addEventListener(events);
    ksession.addEventListener(process);
    Command<?> cmd = CommandFactory.newStartProcess(NONE_ID);
    ksession.execute(cmd);
    Assertions.assertThat(process.wasProcessStarted(NONE_ID)).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(NONE_ID)).isTrue();
    assertProcessStarted(events, NONE_ID);
    assertNextNode(events, "start");
    assertNextNode(events, "script");
    assertNextNode(events, "end");
    assertProcessCompleted(events, NONE_ID);
    Assertions.assertThat(events.hasNext()).isFalse();
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 15 with IterableProcessEventListener

use of org.jbpm.test.listener.IterableProcessEventListener in project jbpm by kiegroup.

the class EndEventTest method testCompensateEndEvent.

@BZ("1021631")
@Test(timeout = 30000)
public void testCompensateEndEvent() {
    KieSession ksession = createKSession(COMPENSATE);
    IterableProcessEventListener events = new IterableProcessEventListener();
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    ksession.addEventListener(events);
    ksession.addEventListener(process);
    Command<ProcessInstance> cmd = getCommands().newStartProcess(COMPENSATE_ID);
    ProcessInstance pi = ksession.execute(cmd);
    Assertions.assertThat(process.wasProcessStarted(COMPENSATE_ID)).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(COMPENSATE_ID)).isTrue();
    assertProcessStarted(events, COMPENSATE_ID);
    assertNextNode(events, "start");
    assertTriggered(events, "subprocess");
    assertNextNode(events, "sub-start");
    assertTriggered(events, "script");
    assertChangedVariable(events, "x", null, 0);
    assertLeft(events, "script");
    assertNextNode(events, "sub-end");
    assertLeft(events, "subprocess");
    assertTriggered(events, "end");
    assertLeft(events, "compensate-catch");
    assertTriggered(events, "compensate");
    assertChangedVariable(events, "x", 0, null);
    assertLeft(events, "compensate");
    Assertions.assertThat(pi.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Aggregations

IterableProcessEventListener (org.jbpm.test.listener.IterableProcessEventListener)34 Test (org.junit.Test)32 KieSession (org.kie.api.runtime.KieSession)18 TrackingProcessEventListener (org.jbpm.test.listener.TrackingProcessEventListener)17 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)15 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 Command (org.kie.api.command.Command)4 BZ (qa.tools.ikeeper.annotation.BZ)3 Person (org.jbpm.test.domain.Person)2 Before (org.junit.Before)2 ResourceType (org.kie.api.io.ResourceType)2 RegisterWorkItemHandlerCommand (org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand)1 StartProcessCommand (org.drools.core.command.runtime.process.StartProcessCommand)1 JbpmJUnitBaseTestCase (org.jbpm.test.JbpmJUnitBaseTestCase)1 DebugProcessEventListener (org.jbpm.test.listener.DebugProcessEventListener)1 Ignore (org.junit.Ignore)1 WorkItem (org.kie.api.runtime.process.WorkItem)1