Java Code Examples for org.kie.internal.builder.KnowledgeBuilder#newKieBase()

The following examples show how to use org.kie.internal.builder.KnowledgeBuilder#newKieBase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaHandlerWorkitemHandlerTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
private static KieBase readKnowledgeBase() throws Exception {
    ProcessBuilderFactory.setProcessBuilderFactoryService(new ProcessBuilderFactoryServiceImpl());
    ProcessRuntimeFactory.setProcessRuntimeFactoryService(new ProcessRuntimeFactoryServiceImpl());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("JavaHandler.bpmn"),
                 ResourceType.BPMN2);
    return kbuilder.newKieBase();
}
 
Example 2
Source File: RulesDeployer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) {
    LOGGER.debug("Processing deployment {}", deployment.getName());

    KnowledgeBuilder knowledgeBuilder = null;

    DeploymentManager deploymentManager = Context
            .getProcessEngineConfiguration()
            .getDeploymentManager();

    Map<String, ResourceEntity> resources = deployment.getResources();
    for (String resourceName : resources.keySet()) {
        LOGGER.info("Processing resource {}", resourceName);
        if (resourceName.endsWith(".drl")) { // is only parsing .drls sufficient? what about other rule dsl's? (@see ResourceType)
            if (knowledgeBuilder == null) {
                knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
            }
            ResourceEntity resourceEntity = resources.get(resourceName);
            byte[] resourceBytes = resourceEntity.getBytes();
            Resource droolsResource = ResourceFactory.newByteArrayResource(resourceBytes);
            knowledgeBuilder.add(droolsResource, ResourceType.DRL);
        }
    }

    if (knowledgeBuilder != null) {
        KieBase knowledgeBase = knowledgeBuilder.newKieBase();
        deploymentManager.getKnowledgeBaseCache().add(deployment.getId(), knowledgeBase);
    }
}
 
Example 3
Source File: JavaInvokerTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
private static KieBase readKnowledgeBase() throws Exception {
    ProcessBuilderFactory.setProcessBuilderFactoryService(new ProcessBuilderFactoryServiceImpl());
    ProcessRuntimeFactory.setProcessRuntimeFactoryService(new ProcessRuntimeFactoryServiceImpl());
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("JavaInvoker.bpmn"),
                 ResourceType.BPMN2);
    kbuilder.add(ResourceFactory.newClassPathResource("JavaInvokerListResult.bpmn"),
                 ResourceType.BPMN2);
    return kbuilder.newKieBase();
}
 
Example 4
Source File: SerializedPackageMergeTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildAndSerializePackagesWithGetterInLHS() throws Exception {
    // DROOLS-2495
    String drl =   "package com.sample\n" +
                    "import org.drools.compiler.Person\n" +
                    "import org.drools.compiler.Cheese\n" +
                    "rule R1\n" +
                    "when\n" +
                    "  $p : Person()\n" +
                    "  $c : Cheese(type == $p.getName())\n" +
                    "then\n" +
                    "end\n";

    KnowledgeBuilder builder1 = KnowledgeBuilderFactory.newKnowledgeBuilder();
    builder1.add(ResourceFactory.newByteArrayResource(drl.getBytes()), ResourceType.DRL);
    Collection<KiePackage> knowledgePackages = builder1.getKnowledgePackages();

    byte[] pkgBin = null;
    try (ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
            DroolsObjectOutputStream out = new DroolsObjectOutputStream(byteOutStream);) {
        out.writeObject(knowledgePackages);
        out.flush();
        pkgBin = byteOutStream.toByteArray();
    }

    KnowledgeBuilder builder2 = KnowledgeBuilderFactory.newKnowledgeBuilder();
    builder2.add(ResourceFactory.newByteArrayResource(pkgBin), ResourceType.PKG);
    KieBase kbase = builder2.newKieBase();

    KieSession ksession = kbase.newKieSession();
    try {
        ksession.insert(new org.drools.compiler.Person("aaa"));
        ksession.insert(new org.drools.compiler.Cheese("aaa"));
        ksession.fireAllRules();
    } finally {
        ksession.dispose();
    }
}
 
Example 5
Source File: ProcessActionTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testActionVariableMVEL() {
	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
       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.actions\" package-name=\"org.drools\" version=\"1\" >\n" +
           "\n" +
           "  <header>\n" +
		"    <imports>\n" +
		"      <import name=\"org.jbpm.integrationtests.TestVariable\" />\n" +
		"    </imports>\n" +
		"    <globals>\n" +
		"      <global identifier=\"list\" type=\"java.util.List\" />\n" +
		"    </globals>\n" +
   		"    <variables>\n" +
   		"      <variable name=\"person\" >\n" +
   		"        <type name=\"org.jbpm.process.core.datatype.impl.type.ObjectDataType\" className=\"org.jbpm.integrationtests.TestVariable\" />\n" +
   		"      </variable>\n" +
   		"    </variables>\n" +
           "  </header>\n" +
           "\n" +
           "  <nodes>\n" +
           "    <start id=\"1\" name=\"Start\" />\n" +
		"    <actionNode id=\"2\" name=\"MyActionNode\" >\n" +
		"      <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Triggered\");\n" +
		"list.add(person.name);\n" +
		"</action>\n" +
		"    </actionNode>\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>");
       kbuilder.add(new ReaderResource(source), ResourceType.DRF);
       KieBase kbase = kbuilder.newKieBase();
       KieSession ksession = kbase.newKieSession();
       List<String> list = new ArrayList<String>();
       ksession.setGlobal("list", list);
       TestVariable person = new TestVariable("John Doe");
       Map<String, Object> params = new HashMap<String, Object>();
       params.put("person", person);
       ProcessInstance processInstance =
           ksession.startProcess("org.drools.actions", params);
       assertEquals(1, list.size());
       assertEquals("John Doe", list.get(0));
       assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
   }
 
Example 6
Source File: ProcessActionTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testActionVariableJava() {
	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
       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.actions\" package-name=\"org.drools\" version=\"1\" >\n" +
           "\n" +
           "  <header>\n" +
		"    <imports>\n" +
		"      <import name=\"org.jbpm.integrationtests.TestVariable\" />\n" +
		"    </imports>\n" +
		"    <globals>\n" +
		"      <global identifier=\"list\" type=\"java.util.List\" />\n" +
		"    </globals>\n" +
   		"    <variables>\n" +
   		"      <variable name=\"person\" >\n" +
   		"        <type name=\"org.jbpm.process.core.datatype.impl.type.ObjectDataType\" className=\"org.jbpm.integrationtests.TestVariable\" />\n" +
   		"      </variable>\n" +
   		"    </variables>\n" +
           "  </header>\n" +
           "\n" +
           "  <nodes>\n" +
           "    <start id=\"1\" name=\"Start\" />\n" +
		"    <actionNode id=\"2\" name=\"MyActionNode\" >\n" +
		"      <action type=\"expression\" dialect=\"java\" >System.out.println(\"Triggered\");\n" +
		"list.add(person.getName());\n" +
		"</action>\n" +
		"    </actionNode>\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>");
       kbuilder.add(new ReaderResource(source), ResourceType.DRF);
       KieBase kbase = kbuilder.newKieBase();
       KieSession ksession = kbase.newKieSession();
       List<String> list = new ArrayList<String>();
       ksession.setGlobal("list", list);
       TestVariable person = new TestVariable("John Doe");
       Map<String, Object> params = new HashMap<String, Object>();
       params.put("person", person);
       ProcessInstance processInstance =
           ksession.startProcess("org.drools.actions", params);
       assertEquals(1, list.size());
       assertEquals("John Doe", list.get(0));
       assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
   }
 
Example 7
Source File: ProcessActionTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testActionContextMVEL() {
	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
       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.actions\" package-name=\"org.drools\" version=\"1\" >\n" +
           "\n" +
           "  <header>\n" +
		"    <imports>\n" +
		"      <import name=\"org.jbpm.integrationtests.test.Message\" />\n" +
		"    </imports>\n" +
		"    <globals>\n" +
		"      <global identifier=\"list\" type=\"java.util.List\" />\n" +
		"    </globals>\n" +
   		"    <variables>\n" +
   		"      <variable name=\"variable\" >\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" +
		"    <actionNode id=\"2\" name=\"MyActionNode\" >\n" +
		"      <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Triggered\");\n" +
		"System.out.println(kcontext.getKnowledgeRuntime());\n" +
		"String myVariable = (String) kcontext.getVariable(\"variable\");\n" +
		"list.add(myVariable);\n" +
		"String nodeName = kcontext.getNodeInstance().getNodeName();\n" +
		"list.add(nodeName);\n" +
		"insert( new Message() );\n" +
		"</action>\n" +
		"    </actionNode>\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>");
       kbuilder.add(new ReaderResource(source), ResourceType.DRF);
       if ( kbuilder.hasErrors() ) {
           fail( kbuilder.getErrors().toString() );
       }
       KieBase kbase = kbuilder.newKieBase();
       KieSession ksession = kbase.newKieSession();
       List<String> list = new ArrayList<String>();
       ksession.setGlobal("list", list);
       ProcessInstance processInstance =
           ksession.startProcess("org.drools.actions");
       assertEquals(2, list.size());
       assertEquals("SomeText", list.get(0));
       assertEquals("MyActionNode", list.get(1));
       Collection<FactHandle> factHandles = ksession.getFactHandles(new ObjectFilter() {
		public boolean accept(Object object) {
			return object instanceof Message;
		}
       });
       assertFalse(factHandles.isEmpty());
       assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
   }
 
Example 8
Source File: ProcessActionTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
 public void testActionContextJava() {
 	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
     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.actions\" package-name=\"org.drools\" version=\"1\" >\n" +
         "\n" +
         "  <header>\n" +
"    <imports>\n" +
"      <import name=\"org.jbpm.integrationtests.test.Message\" />\n" +
"    </imports>\n" +
"    <globals>\n" +
"      <global identifier=\"list\" type=\"java.util.List\" />\n" +
"    </globals>\n" +
 		"    <variables>\n" +
 		"      <variable name=\"variable\" >\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" +
"    <actionNode id=\"2\" name=\"MyActionNode\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >System.out.println(\"Triggered\");\n" +
"String myVariable = (String) kcontext.getVariable(\"variable\");\n" +
"list.add(myVariable);\n" +
"String nodeName = kcontext.getNodeInstance().getNodeName();\n" +
"list.add(nodeName);\n" +
"insert( new Message() );\n" +
"</action>\n" +
"    </actionNode>\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>");
     kbuilder.add(new ReaderResource(source), ResourceType.DRF);
     KieBase kbase = kbuilder.newKieBase();
     KieSession ksession = kbase.newKieSession();
     List<String> list = new ArrayList<String>();
     ksession.setGlobal("list", list);
     ProcessInstance processInstance =
         ksession.startProcess("org.drools.actions");
     assertEquals(2, list.size());
     assertEquals("SomeText", list.get(0));
     assertEquals("MyActionNode", list.get(1));
     Collection<FactHandle> factHandles = ksession.getFactHandles(new ObjectFilter() {
public boolean accept(Object object) {
	return object instanceof Message;
}
     });
     assertFalse(factHandles.isEmpty());
     assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
 }
 
Example 9
Source File: ProcessActionTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
 public void testOnEntryExit() {
     KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
     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.actions\" package-name=\"org.drools\" version=\"1\" >\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" +
         "    <workItem id=\"2\" name=\"HumanTask\" >\n" +
         "      <work name=\"Human Task\" >\n" +
         "        <parameter name=\"ActorId\" >\n" +
         "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" +
         "          <value>John Doe</value>\n" +
         "        </parameter>\n" +
         "        <parameter name=\"TaskName\" >\n" +
         "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" +
         "          <value>Do something</value>\n" +
         "        </parameter>\n" +
         "        <parameter name=\"Priority\" >\n" +
         "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" +
         "        </parameter>\n" +
         "        <parameter name=\"Comment\" >\n" +
         "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" +
         "        </parameter>\n" +
         "      </work>\n" +
         "      <onEntry>\n" +
         "        <action type=\"expression\" name=\"Print\" dialect=\"mvel\" >list.add(\"Executing on entry action\");</action>\n" + 
         "      </onEntry>\n" + 
         "      <onExit>\n" +
         "        <action type=\"expression\" name=\"Print\" dialect=\"java\" >list.add(\"Executing on exit action1\");</action>\n" +
         "        <action type=\"expression\" name=\"Print\" dialect=\"java\" >list.add(\"Executing on exit action2\");</action>\n" +
         "      </onExit>\n" +
         "    </workItem>\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>");
     kbuilder.add(new ReaderResource(source), ResourceType.DRF);
     KieBase kbase = kbuilder.newKieBase();
     KieSession ksession = kbase.newKieSession();
     TestWorkItemHandler handler = new TestWorkItemHandler();
     ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
     List<String> list = new ArrayList<String>();
     ksession.setGlobal("list", list);
     ProcessInstance processInstance =
         ksession.startProcess("org.drools.actions");
     assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
     WorkItem workItem = handler.getWorkItem();
     assertNotNull(workItem);
     assertEquals(1, list.size());
     ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
     assertEquals(3, list.size());
     assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
 }
 
Example 10
Source File: ProcessStateTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testActionState() {
	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    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.state\" package-name=\"org.drools\" version=\"1\" >\n" +
        "\n" +
        "  <header>\n" +
        "    <globals>\n" +
        "      <global identifier=\"list\" type=\"java.util.List\" />\n" +
        "    </globals>\n" +
        "    <variables>\n" +
        "      <variable name=\"s\" >\n" +
        "        <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" +
        "        <value>a</value>\n" +
        "      </variable>\n" +
        "    </variables>\n" +
        "  </header>\n" +
        "\n" +
        "  <nodes>\n" +
        "    <start id=\"1\" name=\"Start\" />\n" +
        "    <state id=\"2\" name=\"State\" >\n" +
        "      <onEntry>" +
        "        <action type=\"expression\" dialect=\"mvel\" >list.add(\"Action1\" + s);</action>\n" +
        "        <action type=\"expression\" dialect=\"java\" >list.add(\"Action2\" + s);</action>\n" +
        "      </onEntry>\n" +
        "      <onExit>\n" +
        "        <action type=\"expression\" dialect=\"mvel\" >list.add(\"Action3\" + s);</action>\n" +
        "        <action type=\"expression\" dialect=\"java\" >list.add(\"Action4\" + s);</action>\n" +
        "      </onExit>\n" +
        "    </state>\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>");
    kbuilder.add( ResourceFactory.newReaderResource( source ), ResourceType.DRF );
    KieBase kbase = kbuilder.newKieBase();
    KieSession ksession = kbase.newKieSession();
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    // start process
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance)
        ksession.startProcess("org.drools.state");
    // should be in state A
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    Collection<NodeInstance> nodeInstances = processInstance.getNodeInstances();
    assertEquals(1, nodeInstances.size());
    StateNodeInstance stateInstance = (StateNodeInstance) nodeInstances.iterator().next();
    assertEquals("State", stateInstance.getNodeName());
    assertEquals(2, list.size());
    assertTrue(list.contains("Action1a"));
    assertTrue(list.contains("Action2a"));
    processInstance.signalEvent("signal", "End");
    nodeInstances = processInstance.getNodeInstances();
    assertEquals(0, nodeInstances.size());
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    assertEquals(4, list.size());
    assertTrue(list.contains("Action3a"));
    assertTrue(list.contains("Action4a"));
}
 
Example 11
Source File: ProcessStateTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
 @Disabled
 public void FIXMEtestDelayedStateConstraintPriorities2() {
 	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
     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.state\" package-name=\"org.drools\" version=\"1\" >\n" +
         "\n" +
         "  <header>\n" +
"    <imports>\n" +
"      <import name=\"org.jbpm.integrationtests.test.Person\" />\n" +
"    </imports>\n" +
"    <globals>\n" +
"      <global identifier=\"list\" type=\"java.util.List\" />\n" +
"    </globals>\n" +
         "  </header>\n" +
         "\n" +
         "  <nodes>\n" +
         "    <start id=\"1\" name=\"Start\" />\n" +
         "    <state id=\"2\" >\n" +
         "      <constraints>\n" +
         "        <constraint toNodeId=\"3\" name=\"one\" priority=\"2\" >\n" +
         "            Person( )" +
         "        </constraint>"+
          "       <constraint toNodeId=\"5\" name=\"two\" priority=\"1\" >\n" +
         "           Person( )" +
         "        </constraint>"+
         "      </constraints>\n" +
         "    </state>\n" +
"    <actionNode id=\"3\" name=\"ActionNode1\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"1\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"4\" name=\"End\" />\n" +
"    <actionNode id=\"5\" name=\"ActionNode2\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"2\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"6\" 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" +
         "    <connection from=\"2\" to=\"5\" />\n" +
         "    <connection from=\"5\" to=\"6\" />\n" +
         "  </connections>\n" +
         "\n" +
         "</process>");
     kbuilder.add( ResourceFactory.newReaderResource( source ), ResourceType.DRF );
     KieBase kbase = kbuilder.newKieBase();
     KieSession ksession = kbase.newKieSession();
     List<String> list = new ArrayList<String>();
     ksession.setGlobal("list", list);
     ProcessInstance processInstance = ksession.startProcess("org.drools.state");
     assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
     assertTrue(list.isEmpty());
     Person person = new Person("John Doe", 30);
     ksession.insert(person);
     assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
     assertEquals(1, list.size());
     assertEquals("2", list.get(0));
 }
 
Example 12
Source File: ProcessStateTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
 @Disabled
 public void FIXMEtestDelayedStateConstraintPriorities1() {
 	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
     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.state\" package-name=\"org.drools\" version=\"1\" >\n" +
         "\n" +
         "  <header>\n" +
"    <imports>\n" +
"      <import name=\"org.jbpm.integrationtests.test.Person\" />\n" +
"    </imports>\n" +
"    <globals>\n" +
"      <global identifier=\"list\" type=\"java.util.List\" />\n" +
"    </globals>\n" +
         "  </header>\n" +
         "\n" +
         "  <nodes>\n" +
         "    <start id=\"1\" name=\"Start\" />\n" +
         "    <state id=\"2\" >\n" +
         "      <constraints>\n" +
         "        <constraint toNodeId=\"3\" name=\"one\" priority=\"1\" >\n" +
         "            Person( )" +
         "        </constraint>"+
          "       <constraint toNodeId=\"5\" name=\"two\" priority=\"2\" >\n" +
         "           Person( )" +
         "        </constraint>"+
         "      </constraints>\n" +
         "    </state>\n" +
"    <actionNode id=\"3\" name=\"ActionNode1\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"1\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"4\" name=\"End\" />\n" +
"    <actionNode id=\"5\" name=\"ActionNode2\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"2\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"6\" 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" +
         "    <connection from=\"2\" to=\"5\" />\n" +
         "    <connection from=\"5\" to=\"6\" />\n" +
         "  </connections>\n" +
         "\n" +
         "</process>");
     kbuilder.add( ResourceFactory.newReaderResource(source), ResourceType.DRF );
     KieBase kbase = kbuilder.newKieBase();
     KieSession ksession = kbase.newKieSession();
     List<String> list = new ArrayList<String>();
     ksession.setGlobal("list", list);
     ProcessInstance processInstance = ksession.startProcess("org.drools.state");
     assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
     assertTrue(list.isEmpty());
     Person person = new Person("John Doe", 30);
     ksession.insert(person);
     assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
     assertEquals(1, list.size());
     assertEquals("1", list.get(0));
 }
 
Example 13
Source File: ProcessStateTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
 public void testDelayedStateConstraint2() {
 	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
     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.state\" package-name=\"org.jbpm\" version=\"1\" >\n" +
         "\n" +
         "  <header>\n" +
"    <imports>\n" +
"      <import name=\"org.jbpm.integrationtests.test.Person\" />\n" +
"    </imports>\n" +
"    <globals>\n" +
"      <global identifier=\"list\" type=\"java.util.List\" />\n" +
"    </globals>\n" +
         "  </header>\n" +
         "\n" +
         "  <nodes>\n" +
         "    <start id=\"1\" name=\"Start\" />\n" +
         "    <state id=\"2\" >\n" +
         "      <constraints>\n" +
         "        <constraint toNodeId=\"3\" name=\"age &gt; 21\" >\n" +
         "            Person( age &gt; 21 )" +
         "        </constraint>"+
          "       <constraint toNodeId=\"5\" name=\"age &lt;=21 \" >\n" +
         "           Person( age &lt;= 21 )" +
         "        </constraint>"+
         "      </constraints>\n" +
         "    </state>\n" +
"    <actionNode id=\"3\" name=\"ActionNode1\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"1\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"4\" name=\"End\" />\n" +
"    <actionNode id=\"5\" name=\"ActionNode2\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"2\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"6\" 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" +
         "    <connection from=\"2\" to=\"5\" />\n" +
         "    <connection from=\"5\" to=\"6\" />\n" +
         "  </connections>\n" +
         "\n" +
         "</process>");
     kbuilder.add( ResourceFactory.newReaderResource( source ), ResourceType.DRF );
     KieBase kbase = kbuilder.newKieBase();
     KieSession ksession = kbase.newKieSession();
     List<String> list = new ArrayList<String>();
     ksession.setGlobal("list", list);
     ProcessInstance processInstance = ksession.startProcess("org.drools.state");
     assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
     assertTrue(list.isEmpty());
     Person person = new Person("John Doe", 20);
     ksession.insert(person);
     ksession.fireAllRules();
     assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
     assertEquals(1, list.size());
     assertEquals("2", list.get(0));
 }
 
Example 14
Source File: ProcessStateTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
 public void testDelayedStateConstraint() {
 	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
     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.state\" package-name=\"org.jbpm\" version=\"1\" >\n" +
         "\n" +
         "  <header>\n" +
"    <imports>\n" +
"      <import name=\"org.jbpm.integrationtests.test.Person\" />\n" +
"    </imports>\n" +
"    <globals>\n" +
"      <global identifier=\"list\" type=\"java.util.List\" />\n" +
"    </globals>\n" +
         "  </header>\n" +
         "\n" +
         "  <nodes>\n" +
         "    <start id=\"1\" name=\"Start\" />\n" +
         "    <state id=\"2\" >\n" +
         "      <constraints>\n" +
         "        <constraint toNodeId=\"3\" name=\"one\" >\n" +
         "            Person( age &gt; 21 )" +
         "        </constraint>"+
          "       <constraint toNodeId=\"4\" name=\"two\" >\n" +
         "           Person( age &lt;= 21 )" +
         "        </constraint>"+
         "      </constraints>\n" +
         "    </state>\n" +
"    <actionNode id=\"3\" name=\"ActionNode1\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"1\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"4\" name=\"End\" />\n" +
"    <actionNode id=\"5\" name=\"ActionNode2\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"2\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"6\" 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" +
         "    <connection from=\"2\" to=\"5\" />\n" +
         "    <connection from=\"5\" to=\"6\" />\n" +
         "  </connections>\n" +
         "\n" +
         "</process>");
     kbuilder.add( ResourceFactory.newReaderResource( source ), ResourceType.DRF );
     KieBase kbase = kbuilder.newKieBase();
     KieSession ksession = kbase.newKieSession();
     List<String> list = new ArrayList<String>();
     ksession.setGlobal("list", list);
     ProcessInstance processInstance = ksession.startProcess("org.drools.state");
     assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
     assertTrue(list.isEmpty());
     Person person = new Person("John Doe", 30);
     ksession.insert(person);
     ksession.fireAllRules();
     assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
     assertEquals(1, list.size());
     assertEquals("1", list.get(0));
 }
 
Example 15
Source File: ProcessStateTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
 public void testImmediateStateConstraintPriorities2() {
 	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
     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.state\" package-name=\"org.drools\" version=\"1\" >\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" +
         "    <state id=\"2\" >\n" +
         "      <constraints>\n" +
         "        <constraint toNodeId=\"3\" name=\"one\" priority=\"2\" >\n" +
         "            eval(true)" +
         "        </constraint>"+
          "       <constraint toNodeId=\"5\" name=\"two\" priority=\"1\" >\n" +
         "           eval(true)" +
         "        </constraint>"+
         "      </constraints>\n" +
         "    </state>\n" +
"    <actionNode id=\"3\" name=\"ActionNode1\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"1\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"4\" name=\"End\" />\n" +
"    <actionNode id=\"5\" name=\"ActionNode2\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"2\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"6\" 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" +
         "    <connection from=\"2\" to=\"5\" />\n" +
         "    <connection from=\"5\" to=\"6\" />\n" +
         "  </connections>\n" +
         "\n" +
         "</process>");
     kbuilder.add( ResourceFactory.newReaderResource( source ), ResourceType.DRF );
     KieBase kbase = kbuilder.newKieBase();
     KieSession ksession = kbase.newKieSession();
     List<String> list = new ArrayList<String>();
     ksession.setGlobal("list", list);
     ProcessInstance processInstance = ksession.startProcess("org.drools.state");
     assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
     assertEquals(1, list.size());
     assertEquals("2", list.get(0));
 }
 
Example 16
Source File: ProcessStateTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
 public void testImmediateStateConstraintPriorities1() {
 	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
     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.state\" package-name=\"org.drools\" version=\"1\" >\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" +
         "    <state id=\"2\" >\n" +
         "      <constraints>\n" +
         "        <constraint toNodeId=\"3\" name=\"one\" priority=\"1\" >\n" +
         "            eval(true)" +
         "        </constraint>"+
          "       <constraint toNodeId=\"5\" name=\"two\" priority=\"2\" >\n" +
         "           eval(true)" +
         "        </constraint>"+
         "      </constraints>\n" +
         "    </state>\n" +
"    <actionNode id=\"3\" name=\"ActionNode1\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"1\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"4\" name=\"End\" />\n" +
"    <actionNode id=\"5\" name=\"ActionNode2\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"2\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"6\" 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" +
         "    <connection from=\"2\" to=\"5\" />\n" +
         "    <connection from=\"5\" to=\"6\" />\n" +
         "  </connections>\n" +
         "\n" +
         "</process>");
     kbuilder.add( ResourceFactory.newReaderResource( source ), ResourceType.DRF );
     KieBase kbase = kbuilder.newKieBase();
     KieSession ksession = kbase.newKieSession();
     List<String> list = new ArrayList<String>();
     ksession.setGlobal("list", list);
     ProcessInstance processInstance = ksession.startProcess("org.drools.state");
     assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
     assertEquals(1, list.size());
     assertEquals("1", list.get(0));
 }
 
Example 17
Source File: ProcessStateTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
 public void testImmediateStateConstraint1() {
 	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
     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.state\" package-name=\"org.drools\" version=\"1\" >\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" +
         "    <state id=\"2\" >\n" +
         "      <constraints>\n" +
         "        <constraint toNodeId=\"3\" name=\"one\" >\n" +
         "            eval(true)" +
         "        </constraint>"+
          "       <constraint toNodeId=\"4\" name=\"two\" >\n" +
         "           eval(false)" +
         "        </constraint>"+
         "      </constraints>\n" +
         "    </state>\n" +
"    <actionNode id=\"3\" name=\"ActionNode1\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"1\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"4\" name=\"End\" />\n" +
"    <actionNode id=\"5\" name=\"ActionNode2\" >\n" +
"      <action type=\"expression\" dialect=\"java\" >list.add(\"2\");</action>\n" +
"    </actionNode>\n" +
         "    <end id=\"6\" 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" +
         "    <connection from=\"2\" to=\"5\" />\n" +
         "    <connection from=\"5\" to=\"6\" />\n" +
         "  </connections>\n" +
         "\n" +
         "</process>");
     kbuilder.add( ResourceFactory.newReaderResource( source ), ResourceType.DRF );
     KieBase kbase = kbuilder.newKieBase();
     KieSession ksession = kbase.newKieSession();
     List<String> list = new ArrayList<String>();
     ksession.setGlobal("list", list);
     ProcessInstance processInstance = ksession.startProcess("org.drools.state");
     assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
     assertEquals(1, list.size());
     assertEquals("1", list.get(0));
 }
 
Example 18
Source File: ProcessStateTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testManualSignalState() {
	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    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.state\" package-name=\"org.drools\" version=\"1\" >\n" +
        "\n" +
        "  <header>\n" +
        "  </header>\n" +
        "\n" +
        "  <nodes>\n" +
        "    <start id=\"1\" name=\"Start\" />\n" +
        "    <state id=\"2\" name=\"StateA\" >\n" +
        "      <constraints>\n" +
        "        <constraint toNodeId=\"3\" name=\"toB\" />\n" +
         "       <constraint toNodeId=\"4\" name=\"toC\" />\n" +
        "      </constraints>\n" +
        "    </state>\n" +
        "    <state id=\"3\" name=\"StateB\" />\n" +
        "    <state id=\"4\" name=\"StateC\" />\n" +
        "    <end id=\"5\" name=\"End\" />\n" +
        "  </nodes>\n" +
        "\n" +
        "  <connections>\n" +
        "    <connection from=\"1\" to=\"2\" />\n" +
        "    <connection from=\"2\" to=\"3\" />\n" +
        "    <connection from=\"2\" to=\"4\" />\n" +
        "    <connection from=\"3\" to=\"2\" />\n" +
        "    <connection from=\"4\" to=\"5\" />\n" +
        "  </connections>\n" +
        "\n" +
        "</process>");
    kbuilder.add( ResourceFactory.newReaderResource( source ), ResourceType.DRF );
    KieBase kbase = kbuilder.newKieBase();
    KieSession ksession = kbase.newKieSession();
    // start process
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance)
        ksession.startProcess("org.drools.state");
    // should be in state A
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    Collection<NodeInstance> nodeInstances = processInstance.getNodeInstances();
    assertEquals(1, nodeInstances.size());
    StateNodeInstance stateInstance = (StateNodeInstance) nodeInstances.iterator().next();
    assertEquals("StateA", stateInstance.getNodeName());
    // signal "toB" so we move to state B
    processInstance.signalEvent("signal", "toB");
    nodeInstances = processInstance.getNodeInstances();
    assertEquals(1, nodeInstances.size());
    stateInstance = (StateNodeInstance) nodeInstances.iterator().next();
    assertEquals("StateB", stateInstance.getNodeName());
    // if no constraint specified for a connection,
    // we default to the name of the target node
    // signal "StateA", so we move back to state A
    processInstance.signalEvent("signal", "StateA");
    nodeInstances = processInstance.getNodeInstances();
    assertEquals(1, nodeInstances.size());
    stateInstance = (StateNodeInstance) nodeInstances.iterator().next();
    assertEquals("StateA", stateInstance.getNodeName());
    // signal "toC" so we move to state C
    processInstance.signalEvent("signal", "toC");
    nodeInstances = processInstance.getNodeInstances();
    assertEquals(1, nodeInstances.size());
    stateInstance = (StateNodeInstance) nodeInstances.iterator().next();
    assertEquals("StateC", stateInstance.getNodeName());
    // signal something completely wrong, this should simply be ignored
    processInstance.signalEvent("signal", "Invalid");
    nodeInstances = processInstance.getNodeInstances();
    assertEquals(1, nodeInstances.size());
    stateInstance = (StateNodeInstance) nodeInstances.iterator().next();
    assertEquals("StateC", stateInstance.getNodeName());
    // signal "End", so we move to the end
    processInstance.signalEvent("signal", "End");
    nodeInstances = processInstance.getNodeInstances();
    assertEquals(0, nodeInstances.size());
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
 
Example 19
Source File: ProcessDynamicNodeTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
  public void testAddDynamicSubProcess() {
  	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" +
              "  </header>\n" +
              "\n" +
              "  <nodes>\n" +
              "    <start id=\"1\" name=\"Start\" />\n" + 
              "    <dynamic id=\"2\" name=\"DynamicNode\" >\n" +
		"      <completionCondition>autocomplete</completionCondition>\n" +
              "      <nodes>\n" +
              "        <actionNode id=\"1\" name=\"Action\" >\n" +
              "          <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Action\");</action>\n" +
              "        </actionNode>\n" +
              "      </nodes>\n" +
              "      <connections>\n" +
              "      </connections>\n" +
              "      <in-ports/>\n" +
              "      <out-ports/>\n" +
              "    </dynamic>\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>");
  	Reader source2 = 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=\"subflow\" id=\"org.drools.subflow\" package-name=\"org.drools\" >\n" +
              "\n" +
              "  <header>\n" +
      		"    <variables>\n" +
      		"      <variable name=\"x\" >\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" + 
              "    <actionNode id=\"2\" name=\"Action\" >\n" +
              "      <action type=\"expression\" dialect=\"mvel\" >System.out.println(x);</action>\n" +
              "    </actionNode>\n" +
              "    <workItem id=\"3\" name=\"Work\" >\n" +
           "      <work name=\"Human Task\" />\n" +
           "    </workItem>\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>");
  	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newReaderResource(source), ResourceType.DRF);
kbuilder.add(ResourceFactory.newReaderResource(source2), ResourceType.DRF);
KieBase kbase = kbuilder.newKieBase();
KieSession ksession = kbase.newKieSession();
KieRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
// start a new process instance
ProcessInstance processInstance = (ProcessInstance) ksession.startProcess("org.drools.dynamic");
DynamicNodeInstance dynamicContext = (DynamicNodeInstance) 
	((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next();
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("x", "NewValue");
assertNull(handler.getWorkItem());
assertEquals(0, dynamicContext.getNodeInstances().size());
DynamicUtils.addDynamicSubProcess(dynamicContext, ksession, "org.drools.subflow", parameters);
assertNotNull(handler.getWorkItem());
assertEquals(1, dynamicContext.getNodeInstances().size());
logger.close();
  }
 
Example 20
Source File: ProcessDynamicNodeTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
  public void testAddDynamicWorkItem() {
  	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" +
              "  </header>\n" +
              "\n" +
              "  <nodes>\n" +
              "    <start id=\"1\" name=\"Start\" />\n" + 
              "    <dynamic id=\"2\" name=\"DynamicNode\" >\n" +
		"      <completionCondition>autocomplete</completionCondition>\n" +
		"      <nodes>\n" +
              "        <actionNode id=\"1\" name=\"Action\" >\n" +
              "          <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Action\");</action>\n" +
              "        </actionNode>\n" +
              "      </nodes>\n" +
              "      <connections>\n" +
              "      </connections>\n" +
              "      <in-ports/>\n" +
              "      <out-ports/>\n" +
              "    </dynamic>\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>");
  	KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newReaderResource(source), ResourceType.DRF);
KieBase kbase = kbuilder.newKieBase();
KieSession ksession = kbase.newKieSession();
KieRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
// start a new process instance
ProcessInstance processInstance = (ProcessInstance) ksession.startProcess("org.drools.dynamic");
DynamicNodeInstance dynamicContext = (DynamicNodeInstance) 
	((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next();
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("TaskName", "Dynamic Task");
assertNull(handler.getWorkItem());
assertEquals(0, dynamicContext.getNodeInstances().size());
DynamicUtils.addDynamicWorkItem(dynamicContext, ksession, "Human Task", parameters);
assertNotNull(handler.getWorkItem());
assertEquals(1, dynamicContext.getNodeInstances().size());
logger.close();
  }