Search in sources :

Example 16 with ProcessInstance

use of org.jbpm.process.instance.ProcessInstance in project jbpm by kiegroup.

the class ProcessExceptionHandlerTest method testProcessExceptionHandlerTriggerNode.

@Test
public void testProcessExceptionHandlerTriggerNode() {
    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.exception\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + "  <header>\n" + "    <globals>\n" + "      <global identifier=\"list\" type=\"java.util.List\" />\n" + "    </globals>\n" + "    <exceptionHandlers>\n" + "      <exceptionHandler faultName=\"myFault\" type=\"action\"  >\n" + "        <action type=\"expression\" name=\"Complete\" dialect=\"java\" >((org.jbpm.process.instance.ProcessInstance) context.getProcessInstance()).setState(org.jbpm.process.instance.ProcessInstance.STATE_COMPLETED);</action>\n" + "      </exceptionHandler>\n" + "    </exceptionHandlers>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <fault id=\"2\" name=\"Fault\" faultName=\"myFault\" />\n" + "  </nodes>\n" + "\n" + "  <connections>\n" + "    <connection from=\"1\" to=\"2\" />\n" + "  </connections>\n" + "\n" + "</process>");
    builder.addRuleFlow(source);
    KieSession session = createKieSession(builder.getPackages());
    ProcessInstance processInstance = (ProcessInstance) session.startProcess("org.drools.exception");
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.jbpm.process.instance.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 17 with ProcessInstance

use of org.jbpm.process.instance.ProcessInstance in project jbpm by kiegroup.

the class ProcessForEachTest method testForEach.

@Test
public void testForEach() {
    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=\"ForEach\" id=\"org.drools.ForEach\" package-name=\"org.drools\" >\n" + "  <header>\n" + "    <globals>\n" + "      <global identifier=\"myList\" type=\"java.util.List\" />\n" + "    </globals>\n" + "    <variables>\n" + "      <variable name=\"collection\" >\n" + "        <type name=\"org.jbpm.process.core.datatype.impl.type.ObjectDataType\" className=\"java.util.List\" />\n" + "      </variable>\n" + "    </variables>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <forEach id=\"2\" name=\"ForEach\" variableName=\"item\" collectionExpression=\"collection\" >\n" + "      <nodes>\n" + "    <actionNode id=\"1\" name=\"Action\" >\n" + "        <action type=\"expression\" dialect=\"mvel\" >myList.add(item);</action>\n" + "    </actionNode>\n" + "      </nodes>\n" + "      <connections>\n" + "      </connections>\n" + "      <in-ports>\n" + "        <in-port type=\"DROOLS_DEFAULT\" nodeId=\"1\" nodeInType=\"DROOLS_DEFAULT\" />\n" + "      </in-ports>\n" + "      <out-ports>\n" + "        <out-port type=\"DROOLS_DEFAULT\" nodeId=\"1\" nodeOutType=\"DROOLS_DEFAULT\" />\n" + "      </out-ports>\n" + "    </forEach>\n" + "    <start id=\"1\" name=\"Start\" />\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" + "</process>");
    builder.addRuleFlow(source);
    KieSession workingMemory = createKieSession(builder.getPackages());
    List<String> myList = new ArrayList<String>();
    workingMemory.setGlobal("myList", myList);
    List<String> collection = new ArrayList<String>();
    collection.add("one");
    collection.add("two");
    collection.add("three");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("collection", collection);
    ProcessInstance processInstance = (ProcessInstance) workingMemory.startProcess("org.drools.ForEach", params);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    assertEquals(3, myList.size());
}
Also used : HashMap(java.util.HashMap) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.jbpm.process.instance.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 18 with ProcessInstance

use of org.jbpm.process.instance.ProcessInstance in project jbpm by kiegroup.

the class ProcessForEachTest method testForEachWithEventNode.

@Test
public void testForEachWithEventNode() {
    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=\"ForEach\" id=\"org.drools.ForEach\" package-name=\"org.drools\" >\n" + "  <header>\n" + "    <globals>\n" + "      <global identifier=\"myList\" type=\"java.util.List\" />\n" + "    </globals>\n" + "    <variables>\n" + "      <variable name=\"collection\" >\n" + "        <type name=\"org.jbpm.process.core.datatype.impl.type.ObjectDataType\" className=\"java.util.List\" />\n" + "      </variable>\n" + "    </variables>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <forEach id=\"2\" name=\"ForEach\" variableName=\"item\" collectionExpression=\"collection\" >\n" + "      <nodes>\n" + "        <eventNode id=\"2\" name=\"OrderPreparation Response\" >\n" + "          <eventFilters>\n" + "            <eventFilter type=\"eventType\" eventType=\"MyEvent\" />\n" + "          </eventFilters>\n" + "        </eventNode>\n" + "        <actionNode id=\"3\" name=\"ORDER_PREP\" >\n" + "          <action type=\"expression\" dialect=\"java\" >System.out.println(\"action1\");</action>\n" + "        </actionNode>\n" + "        <join id=\"4\" name=\"Join\" type=\"1\" />\n" + "        <actionNode id=\"5\" name=\"ORDER_VALIDATION\" >\n" + "          <action type=\"expression\" dialect=\"java\" >System.out.println(\"action2\");myList.add(item);</action>\n" + "        </actionNode>\n" + "      </nodes>\n" + "      <connections>\n" + "        <connection from=\"3\" to=\"4\" />\n" + "        <connection from=\"2\" to=\"4\" />\n" + "        <connection from=\"4\" to=\"5\" />\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=\"5\" nodeOutType=\"DROOLS_DEFAULT\" />\n" + "      </out-ports>\n" + "    </forEach>\n" + "    <start id=\"1\" name=\"Start\" />\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" + "</process>");
    builder.addRuleFlow(source);
    KieSession workingMemory = createKieSession(builder.getPackages());
    List<String> myList = new ArrayList<String>();
    workingMemory.setGlobal("myList", myList);
    List<String> collection = new ArrayList<String>();
    collection.add("one");
    collection.add("two");
    collection.add("three");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("collection", collection);
    ProcessInstance processInstance = (ProcessInstance) workingMemory.startProcess("org.drools.ForEach", params);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    processInstance.signalEvent("MyEvent", null);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    assertEquals(3, myList.size());
}
Also used : HashMap(java.util.HashMap) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.jbpm.process.instance.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 19 with ProcessInstance

use of org.jbpm.process.instance.ProcessInstance in project jbpm by kiegroup.

the class ProcessForEachTest method testForEachEmptyList.

@Test
public void testForEachEmptyList() {
    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=\"ForEach\" id=\"org.drools.ForEach\" package-name=\"org.drools\" >\n" + "  <header>\n" + "    <globals>\n" + "      <global identifier=\"myList\" type=\"java.util.List\" />\n" + "    </globals>\n" + "    <variables>\n" + "      <variable name=\"collection\" >\n" + "        <type name=\"org.jbpm.process.core.datatype.impl.type.ObjectDataType\" className=\"java.util.List\" />\n" + "      </variable>\n" + "    </variables>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <forEach id=\"2\" name=\"ForEach\" variableName=\"item\" collectionExpression=\"collection\" >\n" + "      <nodes>\n" + "    <actionNode id=\"1\" name=\"Action\" >\n" + "        <action type=\"expression\" dialect=\"mvel\" >myList.add(item);</action>\n" + "    </actionNode>\n" + "      </nodes>\n" + "      <connections>\n" + "      </connections>\n" + "      <in-ports>\n" + "        <in-port type=\"DROOLS_DEFAULT\" nodeId=\"1\" nodeInType=\"DROOLS_DEFAULT\" />\n" + "      </in-ports>\n" + "      <out-ports>\n" + "        <out-port type=\"DROOLS_DEFAULT\" nodeId=\"1\" nodeOutType=\"DROOLS_DEFAULT\" />\n" + "      </out-ports>\n" + "    </forEach>\n" + "    <start id=\"1\" name=\"Start\" />\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" + "</process>");
    builder.addRuleFlow(source);
    KieSession workingMemory = createKieSession(builder.getPackages());
    List<String> myList = new ArrayList<String>();
    workingMemory.setGlobal("myList", myList);
    List<String> collection = new ArrayList<String>();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("collection", collection);
    ProcessInstance processInstance = (ProcessInstance) workingMemory.startProcess("org.drools.ForEach", params);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : HashMap(java.util.HashMap) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.jbpm.process.instance.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 20 with ProcessInstance

use of org.jbpm.process.instance.ProcessInstance in project jbpm by kiegroup.

the class ProcessForEachTest method testForEachCancelIndependent.

@Test
public void testForEachCancelIndependent() {
    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=\"ForEach\" id=\"org.drools.ForEach\" package-name=\"org.jbpm\" >\n" + "  <header>\n" + "    <globals>\n" + "      <global identifier=\"myList\" type=\"java.util.List\" />\n" + "    </globals>\n" + "    <variables>\n" + "      <variable name=\"collection\" >\n" + "        <type name=\"org.jbpm.process.core.datatype.impl.type.ObjectDataType\" className=\"java.util.List\" />\n" + "      </variable>\n" + "    </variables>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <forEach id=\"2\" name=\"ForEach\" variableName=\"item\" collectionExpression=\"collection\" >\n" + "      <nodes>\n" + "    <subProcess id=\"1\" name=\"SubProcess\" processId=\"org.drools.subflow\" />\n" + "      </nodes>\n" + "      <connections>\n" + "      </connections>\n" + "      <in-ports>\n" + "        <in-port type=\"DROOLS_DEFAULT\" nodeId=\"1\" nodeInType=\"DROOLS_DEFAULT\" />\n" + "      </in-ports>\n" + "      <out-ports>\n" + "        <out-port type=\"DROOLS_DEFAULT\" nodeId=\"1\" nodeOutType=\"DROOLS_DEFAULT\" />\n" + "      </out-ports>\n" + "    </forEach>\n" + "    <start id=\"1\" name=\"Start\" />\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" + "</process>");
    builder.addRuleFlow(source);
    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.subflow\" package-name=\"org.jbpm\" >\n" + "\n" + "  <header>\n" + "    <imports>\n" + "      <import name=\"org.jbpm.integrationtests.test.Person\" />\n" + "    </imports>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <milestone id=\"2\" name=\"Event Wait\" >\n" + "      <constraint type=\"rule\" dialect=\"mvel\" >Person( )</constraint>" + "    </milestone>\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.addRuleFlow(source);
    KieSession workingMemory = createKieSession(builder.getPackages());
    List<String> collection = new ArrayList<String>();
    collection.add("one");
    collection.add("two");
    collection.add("three");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("collection", collection);
    ProcessInstance processInstance = (ProcessInstance) workingMemory.startProcess("org.drools.ForEach", params);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    assertEquals(4, workingMemory.getProcessInstances().size());
    processInstance.setState(ProcessInstance.STATE_ABORTED);
    assertEquals(3, workingMemory.getProcessInstances().size());
}
Also used : HashMap(java.util.HashMap) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.jbpm.process.instance.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

ProcessInstance (org.jbpm.process.instance.ProcessInstance)49 KieSession (org.kie.api.runtime.KieSession)34 StringReader (java.io.StringReader)33 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)33 Test (org.junit.Test)33 Reader (java.io.Reader)30 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)16 TestWorkItemHandler (org.jbpm.integrationtests.handler.TestWorkItemHandler)10 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)8 DroolsError (org.drools.compiler.compiler.DroolsError)6 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)6 Person (org.jbpm.integrationtests.test.Person)5 WorkItem (org.kie.api.runtime.process.WorkItem)5 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)5 KieRuntime (org.kie.api.runtime.KieRuntime)4 WorkItemHandlerNotFoundException (org.drools.core.WorkItemHandlerNotFoundException)3 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)3 WorkItem (org.drools.core.process.instance.WorkItem)3 Message (org.jbpm.integrationtests.test.Message)3