use of org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand in project jbpm by kiegroup.
the class AdHocSubProcessTest method testAdHocSubProcessAutoComplete2.
@BZ("808070")
@Test(timeout = 30000)
public void testAdHocSubProcessAutoComplete2() {
KieSession kieSession = createKSession(ADHOC_AUTOCOMPLETE2);
TrackingProcessEventListener eventListener = new TrackingProcessEventListener();
kieSession.addEventListener(eventListener);
TestUserWorkItemHandler handler = new TestUserWorkItemHandler();
kieSession.execute(new RegisterWorkItemHandlerCommand("Human Task", handler));
WorkflowProcessInstance pi = (WorkflowProcessInstance) kieSession.execute((Command<?>) CommandFactory.newStartProcess(ADHOC_AUTOCOMPLETE2_ID));
assertProcessStarted(eventListener, ADHOC_AUTOCOMPLETE2_ID);
assertTriggeredAndLeft(eventListener, "start");
assertTriggered(eventListener, "adhoc");
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(CommandFactory.newSignalEvent(pi.getId(), "task1", null));
commands.add(CommandFactory.newSignalEvent(pi.getId(), "task2", null));
kieSession.execute((Command<?>) CommandFactory.newBatchExecution(commands));
assertTriggered(eventListener, "task1");
assertTriggered(eventListener, "task2");
WorkItem wi = handler.getWorkItems().get(0);
kieSession.getWorkItemManager().completeWorkItem(wi.getId(), null);
assertLeft(eventListener, "adhoc");
assertProcessCompleted(eventListener, ADHOC_AUTOCOMPLETE2_ID);
}
use of org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand in project jbpm by kiegroup.
the class AdHocSubProcessTest method testAdHocSubprocessAutocomplete3.
/**
* Same as {@link #testAdHocSubprocessAutocomplete()} but BPMN contains the
* old autocomplete constant:
* getActivityInstanceAttribute("numberOfActiveInstances") == 0
*/
@Test(timeout = 30000)
public void testAdHocSubprocessAutocomplete3() {
KieSession kieSession = createKSession(ADHOC_AUTOCOMPLETE3);
TrackingProcessEventListener eventListener = new TrackingProcessEventListener();
kieSession.addEventListener(eventListener);
TestUserWorkItemHandler handler = new TestUserWorkItemHandler();
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(new RegisterWorkItemHandlerCommand("Human Task", handler));
kieSession.execute(CommandFactory.newBatchExecution(commands));
WorkflowProcessInstance pi = (WorkflowProcessInstance) kieSession.execute((Command<?>) CommandFactory.newStartProcess(ADHOC_AUTOCOMPLETE3_ID));
assertProcessStarted(eventListener, ADHOC_AUTOCOMPLETE3_ID);
assertTriggeredAndLeft(eventListener, "start");
assertTriggered(eventListener, "adhoc");
kieSession.execute((Command<?>) CommandFactory.newSignalEvent(pi.getId(), "task1", null));
assertTriggered(eventListener, "task1");
kieSession.execute((Command<?>) CommandFactory.newSignalEvent(pi.getId(), "task2", null));
assertTriggered(eventListener, "task2");
WorkItem wi1 = handler.getWorkItems().get(0);
WorkItem wi2 = handler.getWorkItems().get(1);
kieSession.getWorkItemManager().completeWorkItem(wi1.getId(), null);
assertFalse(eventListener.wasNodeLeft("adhoc"));
kieSession.getWorkItemManager().completeWorkItem(wi2.getId(), null);
assertLeft(eventListener, "adhoc");
assertProcessCompleted(eventListener, ADHOC_AUTOCOMPLETE3_ID);
}
use of org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand in project jbpm by kiegroup.
the class AdHocSubProcessTest method testAdHocSubprocessAutocomplete.
/**
* Tests if adhoc subprocess autocompletes when "autocomplete" is set as
* completion condition. Signals 2 tasks inside subprocess;
* the first completes, the second stays active, then completes
* the second one => "autocomplete" => subprocess is also completed.
*/
@Test(timeout = 30000)
public void testAdHocSubprocessAutocomplete() {
KieSession kieSession = createKSession(ADHOC_AUTOCOMPLETE);
TrackingProcessEventListener eventListener = new TrackingProcessEventListener();
kieSession.addEventListener(eventListener);
TestUserWorkItemHandler handler = new TestUserWorkItemHandler();
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(new RegisterWorkItemHandlerCommand("Human Task", handler));
kieSession.execute(CommandFactory.newBatchExecution(commands));
WorkflowProcessInstance pi = (WorkflowProcessInstance) kieSession.execute((Command<?>) CommandFactory.newStartProcess(ADHOC_AUTOCOMPLETE_ID));
assertProcessStarted(eventListener, ADHOC_AUTOCOMPLETE_ID);
assertTriggeredAndLeft(eventListener, "start");
assertTriggered(eventListener, "adhoc");
kieSession.execute((Command<?>) CommandFactory.newSignalEvent(pi.getId(), "task1", null));
assertTriggered(eventListener, "task1");
kieSession.execute((Command<?>) CommandFactory.newSignalEvent(pi.getId(), "task2", null));
assertTriggered(eventListener, "task2");
WorkItem wi1 = handler.getWorkItems().get(0);
WorkItem wi2 = handler.getWorkItems().get(1);
kieSession.getWorkItemManager().completeWorkItem(wi1.getId(), null);
assertFalse(eventListener.wasNodeLeft("adhoc"));
kieSession.getWorkItemManager().completeWorkItem(wi2.getId(), null);
assertLeft(eventListener, "adhoc");
assertProcessCompleted(eventListener, ADHOC_AUTOCOMPLETE_ID);
}
use of org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand in project jbpm by kiegroup.
the class AdHocSubProcessTest method testAdHocSubprocessDynamicWorkItem.
/**
* Tests dynamic insertion of new work item node into the adhoc subprocess.
* Uses DynamicUtils.
*/
@Test(timeout = 30000)
public void testAdHocSubprocessDynamicWorkItem() {
KieSession kieSession = createKSession(ADHOC);
TrackingProcessEventListener eventListener = new TrackingProcessEventListener();
kieSession.addEventListener(eventListener);
WorkflowProcessInstance pi = (WorkflowProcessInstance) kieSession.execute((Command<?>) CommandFactory.newStartProcess(ADHOC_ID));
assertProcessStarted(eventListener, ADHOC_ID);
assertTriggeredAndLeft(eventListener, "start");
assertTriggered(eventListener, "adhoc");
// dynamic node insert
JbpmJUnitBaseTestCase.TestWorkItemHandler handler = getTestWorkItemHandler();
RegisterWorkItemHandlerCommand registerCommand = new RegisterWorkItemHandlerCommand("addedWorkItem", handler);
kieSession.execute(registerCommand);
DynamicNodeInstance dynamicNodeInstance = (DynamicNodeInstance) pi.getNodeInstances().iterator().next();
DynamicUtils.addDynamicWorkItem(dynamicNodeInstance, kieSession, "addedWorkItem", new java.util.HashMap<String, Object>());
WorkItem wi = handler.getWorkItem();
CompleteWorkItemCommand completeCommand = new CompleteWorkItemCommand(wi.getId(), null);
kieSession.execute(completeCommand);
// end of the dynamic stuff
assertEquals("addedWorkItem", wi.getName());
}
use of org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand in project jbpm by kiegroup.
the class EndEventTest method testMessageEndEvent.
@Test(timeout = 30000)
public void testMessageEndEvent() {
KieSession ksession = createKSession(MESSAGE);
IterableProcessEventListener events = new IterableProcessEventListener();
TrackingProcessEventListener process = new TrackingProcessEventListener();
ksession.addEventListener(events);
ksession.addEventListener(process);
RecordingHandler handler = new RecordingHandler();
List<Command<?>> cmds = new ArrayList<Command<?>>();
cmds.add(new RegisterWorkItemHandlerCommand("Send Task", handler));
cmds.add(getCommands().newStartProcess(MESSAGE_ID));
ksession.execute(getCommands().newBatchExecution(cmds, null));
Assertions.assertThat(process.wasProcessStarted(MESSAGE_ID)).isTrue();
Assertions.assertThat(process.wasProcessCompleted(MESSAGE_ID)).isTrue();
assertProcessStarted(events, MESSAGE_ID);
assertNextNode(events, "start");
assertNextNode(events, "script");
assertNextNode(events, "end");
assertProcessCompleted(events, MESSAGE_ID);
Assertions.assertThat(events.hasNext()).isFalse();
Assertions.assertThat(handler.item).isNotNull();
}
Aggregations