Search in sources :

Example 16 with IterableProcessEventListener

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

the class ConditionalFlowTest method testConditionalFlow.

@Test(timeout = 30000)
public void testConditionalFlow() {
    KieSession ksession = createKSession(PROCESS);
    IterableProcessEventListener listener = new IterableProcessEventListener();
    ksession.addEventListener(listener);
    ksession.execute((Command<?>) getCommands().newStartProcess(PROCESS_ID));
    assertProcessStarted(listener, PROCESS_ID);
    assertNextNode(listener, "start");
    assertTriggered(listener, "script");
    assertChangedVariable(listener, "x", null, 5);
    assertLeft(listener, "script");
    assertNextNode(listener, "end1");
    assertProcessCompleted(listener, PROCESS_ID);
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 17 with IterableProcessEventListener

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

the class ScriptTaskTest method testScriptTask.

/**
 * Object and collection access
 */
@Test(timeout = 30000)
public void testScriptTask() {
    KieSession kieSession = createKSession(SCRIPT_TASK);
    IterableProcessEventListener ipel = new IterableProcessEventListener();
    kieSession.addEventListener(ipel);
    Map<String, Object> params = new HashMap<String, Object>();
    Person p = new Person("Vandrovec");
    params.put("person", p);
    List<Person> personList = new ArrayList<Person>();
    personList.add(new Person("Birsky"));
    personList.add(new Person("Korcasko"));
    params.put("personList", personList);
    kieSession.execute((Command<?>) getCommands().newStartProcess(SCRIPT_TASK_ID, params));
    assertMultipleVariablesChanged(ipel, "person", "personList");
    assertProcessStarted(ipel, SCRIPT_TASK_ID);
    assertNextNode(ipel, "start");
    assertTriggered(ipel, "scriptJava");
    assertChangedVariable(ipel, "output", null, "BirskyKorcaskoVandrovec");
    assertLeft(ipel, "scriptJava");
    assertTriggered(ipel, "scriptMvel");
    assertChangedVariable(ipel, "output", "BirskyKorcaskoVandrovec", "VandrovecBirskyKorcasko");
    assertLeft(ipel, "scriptMvel");
    assertTriggered(ipel, "scriptJavaScript");
    assertChangedVariable(ipel, "output", "VandrovecBirskyKorcasko", "JavaScript Node: Vandrovec");
    assertLeft(ipel, "scriptJavaScript");
    assertNextNode(ipel, "end");
    assertProcessCompleted(ipel, SCRIPT_TASK_ID);
}
Also used : HashMap(java.util.HashMap) IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Person(org.jbpm.test.domain.Person) Test(org.junit.Test)

Example 18 with IterableProcessEventListener

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

the class RuleTaskTest method testRuleTask.

@Test(timeout = 30000)
public void testRuleTask() {
    Map<String, ResourceType> res = new HashMap<String, ResourceType>();
    res.put(RULE_TASK, ResourceType.BPMN2);
    res.put(RULE_TASK_DRL, ResourceType.DRL);
    KieSession kieSession = createKSession(res);
    List<String> executedRules = new ArrayList<String>();
    List<Command<?>> commands = new ArrayList<Command<?>>();
    commands.add(CommandFactory.newSetGlobal("executed", executedRules));
    commands.add(CommandFactory.newStartProcess(RULE_TASK_ID));
    commands.add(CommandFactory.newFireAllRules());
    IterableProcessEventListener listener = new IterableProcessEventListener();
    kieSession.addEventListener(listener);
    kieSession.execute(CommandFactory.newBatchExecution(commands));
    assertProcessStarted(listener, RULE_TASK_ID);
    assertNextNode(listener, "start");
    assertNextNode(listener, "rules");
    assertNextNode(listener, "end");
    assertProcessCompleted(listener, RULE_TASK_ID);
    assertEquals(3, executedRules.size());
    String[] expected = new String[] { "firstRule", "secondRule", "thirdRule" };
    for (String expectedRuleName : expected) {
        assertTrue(executedRules.contains(expectedRuleName));
    }
}
Also used : HashMap(java.util.HashMap) Command(org.kie.api.command.Command) IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) ArrayList(java.util.ArrayList) ResourceType(org.kie.api.io.ResourceType) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 19 with IterableProcessEventListener

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

the class RuleTaskTest method testRuleTaskInsertFact.

@Test(timeout = 30000)
public void testRuleTaskInsertFact() {
    Map<String, ResourceType> res = new HashMap<String, ResourceType>();
    res.put(RULE_TASK, ResourceType.BPMN2);
    res.put(RULE_TASK_DRL, ResourceType.DRL);
    KieSession kieSession = createKSession(res);
    List<String> executedRules = new ArrayList<String>();
    List<Command<?>> commands = new ArrayList<Command<?>>();
    commands.add(CommandFactory.newSetGlobal("executed", executedRules));
    commands.add(CommandFactory.newInsert(6));
    commands.add(CommandFactory.newStartProcess(RULE_TASK_ID));
    commands.add(CommandFactory.newFireAllRules());
    IterableProcessEventListener listener = new IterableProcessEventListener();
    kieSession.addEventListener(listener);
    kieSession.execute(CommandFactory.newBatchExecution(commands));
    assertProcessStarted(listener, RULE_TASK_ID);
    assertNextNode(listener, "start");
    assertNextNode(listener, "rules");
    assertNextNode(listener, "end");
    assertProcessCompleted(listener, RULE_TASK_ID);
    assertEquals(4, executedRules.size());
    String[] expected = new String[] { "firstRule", "secondRule", "thirdRule", "fifthRule" };
    for (String expectedRuleName : expected) {
        assertTrue(executedRules.contains(expectedRuleName));
    }
}
Also used : HashMap(java.util.HashMap) Command(org.kie.api.command.Command) IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) ArrayList(java.util.ArrayList) ResourceType(org.kie.api.io.ResourceType) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 20 with IterableProcessEventListener

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

the class EmbeddedSubProcessTest method testProcessWithEmbeddedSubprocess.

@Test(timeout = 30000)
public void testProcessWithEmbeddedSubprocess() {
    KieSession kieSession = createKSession(EMBEDDED);
    IterableProcessEventListener eventListener = new IterableProcessEventListener();
    kieSession.addEventListener(eventListener);
    kieSession.execute((Command<?>) getCommands().newStartProcess(EMBEDDED_ID));
    assertProcessStarted(eventListener, EMBEDDED_ID);
    assertNextNode(eventListener, "start");
    assertNextNode(eventListener, "ScriptOuter");
    assertTriggered(eventListener, "embedded");
    logger.debug("inside embedded subprocess");
    assertNextNode(eventListener, "sub-start");
    assertNextNode(eventListener, "ScriptInner");
    assertNextNode(eventListener, "sub-end");
    assertLeft(eventListener, "embedded");
    logger.debug("outside embedded subprocess");
    assertNextNode(eventListener, "end");
    assertProcessCompleted(eventListener, EMBEDDED_ID);
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

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