use of org.drools.util.io.ReaderResource in project kogito-runtimes by kiegroup.
the class ProcessDynamicNodeTest method TODOtestDynamicAsyncActions.
@Test
@Disabled("Not done yet")
public void TODOtestDynamicAsyncActions() {
Reader source = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"ruleflow\" id=\"org.drools.dynamic\" package-name=\"org.drools\" >\n" + "\n" + " <header>\n" + " <globals>\n" + " <global identifier=\"list\" type=\"java.util.List\" />\n" + " </globals>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <dynamic id=\"2\" name=\"DynamicNode\" >\n" + " <nodes>\n" + " <workItem id=\"1\" name=\"Work\" >\n" + " <work name=\"Work\" />\n" + " </workItem>\n" + " <actionNode id=\"2\" name=\"Action2\" >\n" + " <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Action2\");\n" + "list.add(\"Action2\");</action>\n" + " </actionNode>\n" + " <actionNode id=\"3\" name=\"Action3\" >\n" + " <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Action3\");\n" + "list.add(\"Action3\");</action>\n" + " </actionNode>\n" + " </nodes>\n" + " <connections>\n" + " <connection from=\"1\" to=\"3\" />\n" + " </connections>\n" + " <in-ports/>\n" + " <out-ports/>\n" + " </dynamic>\n" + " <actionNode id=\"3\" name=\"Action4\" >\n" + " <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Action4\");\n" + "list.add(\"Action4\");</action>\n" + " </actionNode>\n" + " <end id=\"4\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " <connection from=\"3\" to=\"4\" />\n" + " </connections>\n" + "</process>");
builder.add(new ReaderResource(source), ResourceType.DRF);
for (KnowledgeBuilderError error : builder.getErrors()) {
logger.error(error.toString());
}
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
List<String> list = new ArrayList<String>();
kruntime.getKieSession().setGlobal("list", list);
TestWorkItemHandler testHandler = new TestWorkItemHandler();
kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Work", testHandler);
KogitoProcessInstance processInstance = kruntime.startProcess("org.drools.dynamic");
assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
assertEquals(1, list.size());
KogitoWorkItem workItem = testHandler.getWorkItem();
assertNotNull(workItem);
kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
assertEquals(KogitoProcessInstance.STATE_COMPLETED, processInstance.getState());
assertEquals(3, list.size());
}
use of org.drools.util.io.ReaderResource in project kogito-runtimes by kiegroup.
the class ProcessEventListenerTest method testInternalNodeSignalEvent.
@Test
public void testInternalNodeSignalEvent() {
Reader source = new StringReader(process);
builder.add(new ReaderResource(source), ResourceType.DRF);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
final List<ProcessEvent> processEventList = new ArrayList<>();
final ProcessEventListener listener = createProcessEventListener(processEventList);
kruntime.getProcessEventManager().addEventListener(listener);
KogitoProcessInstance processInstance = kruntime.startProcess("org.drools.core.event");
assertEquals(KogitoProcessInstance.STATE_COMPLETED, processInstance.getState());
assertEquals("MyValue", ((VariableScopeInstance) ((org.jbpm.process.instance.ProcessInstance) processInstance).getContextInstance(VariableScope.VARIABLE_SCOPE)).getVariable("MyVar"));
assertEquals(28, processEventList.size());
for (ProcessEvent e : processEventList) {
logger.debug(e.toString());
}
assertEquals("org.drools.core.event", processEventList.get(2).getProcessInstance().getProcessId());
}
use of org.drools.util.io.ReaderResource in project kogito-runtimes by kiegroup.
the class ProcessEventTest method testProcessInstanceSignalCompositeEvent.
@Test
public void testProcessInstanceSignalCompositeEvent() throws Exception {
Reader source = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.core.event\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <variables>\n" + " <variable name=\"MyVar\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>SomeText</value>\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <composite id=\"2\" name=\"CompositeNode\" >\n" + " <nodes>\n" + " <eventNode id=\"2\" name=\"Event\" variableName=\"MyVar\" >\n" + " <eventFilters>\n" + " <eventFilter type=\"eventType\" eventType=\"MyEvent\" />\n" + " </eventFilters>\n" + " </eventNode>\n" + " <join id=\"3\" name=\"Join\" type=\"1\" />\n" + " </nodes>\n" + " <connections>\n" + " <connection from=\"2\" to=\"3\" />\n" + " </connections>\n" + " <in-ports>\n" + " <in-port type=\"DROOLS_DEFAULT\" nodeId=\"3\" nodeInType=\"DROOLS_DEFAULT\" />\n" + " </in-ports>\n" + " <out-ports>\n" + " <out-port type=\"DROOLS_DEFAULT\" nodeId=\"3\" nodeOutType=\"DROOLS_DEFAULT\" />\n" + " </out-ports>\n" + " </composite>\n" + " <end id=\"3\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " </connections>\n" + "\n" + "</process>");
builder.add(new ReaderResource(source), ResourceType.DRF);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
KogitoProcessInstance processInstance = kruntime.startProcess("org.drools.core.event");
assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
processInstance = kruntime.getProcessInstance(processInstance.getStringId());
processInstance.signalEvent("MyEvent", "MyValue");
assertEquals(KogitoProcessInstance.STATE_COMPLETED, processInstance.getState());
assertEquals("MyValue", ((VariableScopeInstance) ((org.jbpm.process.instance.ProcessInstance) processInstance).getContextInstance(VariableScope.VARIABLE_SCOPE)).getVariable("MyVar"));
}
use of org.drools.util.io.ReaderResource in project kogito-runtimes by kiegroup.
the class ProcessEventTest method testInternalEventCorrelation.
@Test
public void testInternalEventCorrelation() throws Exception {
Reader source = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.core.event\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <variables>\n" + " <variable name=\"MyVar\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>SomeText</value>\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <eventNode id=\"2\" name=\"Event\" variableName=\"MyVar\" >\n" + " <eventFilters>\n" + " <eventFilter type=\"eventType\" eventType=\"MyEvent\" />\n" + " </eventFilters>\n" + " </eventNode>\n" + " <join id=\"3\" name=\"Join\" type=\"1\" />\n" + " <end id=\"4\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"3\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " <connection from=\"3\" to=\"4\" />\n" + " </connections>\n" + "\n" + "</process>");
builder.add(new ReaderResource(source), ResourceType.DRF);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
KogitoProcessInstance processInstance = kruntime.startProcess("org.drools.core.event");
assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
assertEquals("SomeText", ((VariableScopeInstance) ((org.jbpm.process.instance.ProcessInstance) processInstance).getContextInstance(VariableScope.VARIABLE_SCOPE)).getVariable("MyVar"));
processInstance = kruntime.getProcessInstance(processInstance.getStringId());
kruntime.signalEvent("MyEvent", "MyValue");
assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
}
use of org.drools.util.io.ReaderResource in project kogito-runtimes by kiegroup.
the class ProcessEventTest method testInternalCompositeEventCorrelation.
@Test
public void testInternalCompositeEventCorrelation() throws Exception {
Reader source = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.core.event\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <variables>\n" + " <variable name=\"MyVar\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>SomeText</value>\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <composite id=\"2\" name=\"CompositeNode\" >\n" + " <nodes>\n" + " <eventNode id=\"2\" name=\"Event\" variableName=\"MyVar\" >\n" + " <eventFilters>\n" + " <eventFilter type=\"eventType\" eventType=\"MyEvent\" />\n" + " </eventFilters>\n" + " </eventNode>\n" + " <join id=\"3\" name=\"Join\" type=\"1\" />\n" + " </nodes>\n" + " <connections>\n" + " <connection from=\"2\" to=\"3\" />\n" + " </connections>\n" + " <in-ports>\n" + " <in-port type=\"DROOLS_DEFAULT\" nodeId=\"3\" nodeInType=\"DROOLS_DEFAULT\" />\n" + " </in-ports>\n" + " <out-ports>\n" + " <out-port type=\"DROOLS_DEFAULT\" nodeId=\"3\" nodeOutType=\"DROOLS_DEFAULT\" />\n" + " </out-ports>\n" + " </composite>\n" + " <end id=\"3\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " </connections>\n" + "\n" + "</process>");
builder.add(new ReaderResource(source), ResourceType.DRF);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
KogitoProcessInstance processInstance = kruntime.startProcess("org.drools.core.event");
assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
processInstance = kruntime.getProcessInstance(processInstance.getStringId());
kruntime.signalEvent("MyEvent", "MyValue");
assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
}
Aggregations