Search in sources :

Example 1 with ReaderResource

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());
}
Also used : TestWorkItemHandler(org.jbpm.integrationtests.handler.TestWorkItemHandler) KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) Reader(java.io.Reader) StringReader(java.io.StringReader) ReaderResource(org.drools.util.io.ReaderResource) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with ReaderResource

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());
}
Also used : ProcessEvent(org.kie.api.event.process.ProcessEvent) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ReaderResource(org.drools.util.io.ReaderResource) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 3 with ReaderResource

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"));
}
Also used : KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ReaderResource(org.drools.util.io.ReaderResource) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 4 with ReaderResource

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());
}
Also used : KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ReaderResource(org.drools.util.io.ReaderResource) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 5 with ReaderResource

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());
}
Also used : KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) ReaderResource(org.drools.util.io.ReaderResource) Test(org.junit.jupiter.api.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

ReaderResource (org.drools.util.io.ReaderResource)52 StringReader (java.io.StringReader)51 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)51 Test (org.junit.jupiter.api.Test)51 KogitoProcessRuntime (org.kie.kogito.internal.process.runtime.KogitoProcessRuntime)50 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)47 Reader (java.io.Reader)45 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)20 TestWorkItemHandler (org.jbpm.integrationtests.handler.TestWorkItemHandler)11 Disabled (org.junit.jupiter.api.Disabled)10 Person (org.jbpm.integrationtests.test.Person)8 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)7 KnowledgeBuilderError (org.kie.internal.builder.KnowledgeBuilderError)5 Message (org.jbpm.integrationtests.test.Message)4 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)3 SemanticKnowledgeBuilderConfigurationImpl (org.jbpm.compiler.xml.compiler.SemanticKnowledgeBuilderConfigurationImpl)3 FactHandle (org.kie.api.runtime.rule.FactHandle)3 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)2 ByteArrayResource (org.drools.util.io.ByteArrayResource)1