use of org.kie.kogito.internal.process.runtime.KogitoProcessInstance in project kogito-runtimes by kiegroup.
the class SubProcessTest method testNonExistentSubProcess.
@Test
public void testNonExistentSubProcess() {
String nonExistentSubProcessName = "nonexistent.process";
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.process");
process.setName("Process");
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
SubProcessNode subProcessNode = new SubProcessNode();
subProcessNode.setName("SubProcessNode");
subProcessNode.setId(2);
subProcessNode.setProcessId(nonExistentSubProcessName);
EndNode endNode = new EndNode();
endNode.setName("End");
endNode.setId(3);
connect(startNode, subProcessNode);
connect(subProcessNode, endNode);
process.addNode(startNode);
process.addNode(subProcessNode);
process.addNode(endNode);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime(process);
KogitoProcessInstance pi = kruntime.startProcess("org.drools.core.process.process");
assertEquals(KogitoProcessInstance.STATE_ERROR, pi.getState());
}
use of org.kie.kogito.internal.process.runtime.KogitoProcessInstance in project kogito-runtimes by kiegroup.
the class WorkItemTest method testReachNonRegisteredWorkItemHandler.
@Test
public void testReachNonRegisteredWorkItemHandler() {
String processId = "org.drools.actions";
String workName = "Unnexistent Task";
RuleFlowProcess process = getWorkItemProcess(processId, workName);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime(process);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Doe"));
KogitoProcessInstance processInstance = null;
try {
processInstance = kruntime.startProcess("org.drools.actions", parameters);
fail("should fail if WorkItemHandler for" + workName + "is not registered");
} catch (Throwable e) {
}
assertEquals(KogitoProcessInstance.STATE_ERROR, processInstance.getState());
}
use of org.kie.kogito.internal.process.runtime.KogitoProcessInstance in project kogito-runtimes by kiegroup.
the class WorkItemTest method testMockDataWorkItemHandlerCustomFunction.
@Test
public void testMockDataWorkItemHandlerCustomFunction() {
String processId = "org.drools.actions";
String workName = "Unnexistent Task";
RuleFlowProcess process = getWorkItemProcess(processId, workName);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime(process);
kruntime.getKogitoWorkItemManager().registerWorkItemHandler(workName, new MockDataWorkItemHandler((input) -> {
Map<String, Object> output = new HashMap<String, Object>();
if ("John Doe".equals(input.get("Comment"))) {
output.put("Result", "one");
} else {
output.put("Result", "two");
}
return output;
}));
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Doe"));
KogitoProcessInstance processInstance = kruntime.startProcess("org.drools.actions", parameters);
Object numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
assertNotNull(numberVariable);
assertEquals("one", numberVariable);
assertEquals(KogitoProcessInstance.STATE_COMPLETED, processInstance.getState());
parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Deen"));
processInstance = kruntime.startProcess("org.drools.actions", parameters);
numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
assertNotNull(numberVariable);
assertEquals("two", numberVariable);
assertEquals(KogitoProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.kie.kogito.internal.process.runtime.KogitoProcessInstance in project kogito-runtimes by kiegroup.
the class NodeInnerClassesTest method testNodeReading.
@Test
public void testNodeReading() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.event");
process.setName("Event Process");
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("event");
ObjectDataType personDataType = new ObjectDataType();
personDataType.setClassName("org.drools.Person");
variable.setType(personDataType);
variables.add(variable);
process.getVariableScope().setVariables(variables);
process.setDynamic(true);
CompositeNode compositeNode = new CompositeNode();
compositeNode.setName("CompositeNode");
compositeNode.setId(2);
ForEachNode forEachNode = new ForEachNode();
ForEachNode.ForEachSplitNode split = new ForEachNode.ForEachSplitNode();
split.setName("ForEachSplit");
split.setMetaData("hidden", true);
split.setMetaData("UniqueId", forEachNode.getMetaData("Uniqueid") + ":foreach:split");
forEachNode.internalAddNode(split);
forEachNode.linkIncomingConnections(Node.CONNECTION_DEFAULT_TYPE, new CompositeNode.NodeAndType(split, Node.CONNECTION_DEFAULT_TYPE));
process.addNode(forEachNode);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime(process);
TestProcessEventListener procEventListener = new TestProcessEventListener();
kruntime.getProcessEventManager().addEventListener(procEventListener);
KogitoProcessInstance processInstance = kruntime.startProcess("org.drools.core.process.event");
assertNotNull(processInstance);
}
use of org.kie.kogito.internal.process.runtime.KogitoProcessInstance in project kogito-runtimes by kiegroup.
the class ProcessEventSupportTest method testProcessEventListenerWithEvent.
@Test
public void testProcessEventListenerWithEvent() throws Exception {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.event");
process.setName("Event Process");
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", (Action) context -> logger.info("Executed action"));
actionNode.setAction(action);
actionNode.setId(2);
process.addNode(actionNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
EventNode eventNode = new EventNode();
eventNode.setName("Event");
eventNode.setId(3);
List<EventFilter> filters = new ArrayList<EventFilter>();
EventTypeFilter filter = new EventTypeFilter();
filter.setType("signal");
filters.add(filter);
eventNode.setEventFilters(filters);
process.addNode(eventNode);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, eventNode, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("End");
endNode.setId(4);
process.addNode(endNode);
new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime(process);
final List<ProcessEvent> processEventList = new ArrayList<ProcessEvent>();
final ProcessEventListener processEventListener = new ProcessEventListener() {
public void afterNodeLeft(ProcessNodeLeftEvent event) {
processEventList.add(event);
}
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
processEventList.add(event);
}
public void afterProcessCompleted(ProcessCompletedEvent event) {
processEventList.add(event);
}
public void afterProcessStarted(ProcessStartedEvent event) {
processEventList.add(event);
}
public void beforeNodeLeft(ProcessNodeLeftEvent event) {
processEventList.add(event);
}
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
processEventList.add(event);
}
public void beforeProcessCompleted(ProcessCompletedEvent event) {
processEventList.add(event);
}
public void beforeProcessStarted(ProcessStartedEvent event) {
processEventList.add(event);
}
public void beforeVariableChanged(ProcessVariableChangedEvent event) {
processEventList.add(event);
}
public void afterVariableChanged(ProcessVariableChangedEvent event) {
processEventList.add(event);
}
};
kruntime.getProcessEventManager().addEventListener(processEventListener);
// execute the process
KogitoProcessInstance pi = kruntime.startProcess("org.drools.core.process.event");
pi.signalEvent("signal", null);
assertEquals(20, processEventList.size());
assertEquals("org.drools.core.process.event", processEventList.get(0).getProcessInstance().getProcessId());
assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(1)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(2)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(3)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(4)).getNodeInstance().getNodeName());
assertEquals("Event", ((ProcessNodeTriggeredEvent) processEventList.get(5)).getNodeInstance().getNodeName());
assertEquals("Event", ((ProcessNodeTriggeredEvent) processEventList.get(6)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(7)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(8)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(9)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(10)).getNodeInstance().getNodeName());
assertEquals("org.drools.core.process.event", processEventList.get(11).getProcessInstance().getProcessId());
assertEquals("Event", ((ProcessNodeLeftEvent) processEventList.get(12)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(13)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(14)).getNodeInstance().getNodeName());
assertEquals("org.drools.core.process.event", processEventList.get(15).getProcessInstance().getProcessId());
assertEquals("org.drools.core.process.event", processEventList.get(16).getProcessInstance().getProcessId());
assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(17)).getNodeInstance().getNodeName());
assertEquals("Event", ((ProcessNodeLeftEvent) processEventList.get(19)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(18)).getNodeInstance().getNodeName());
}
Aggregations