Java Code Examples for org.kie.api.runtime.KieSession#startProcess()

The following examples show how to use org.kie.api.runtime.KieSession#startProcess() . 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: JavaInvokerTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
@Test
public void testStaticMethod1() throws Exception {
    KieBase kbase = readKnowledgeBase();
    KieSession ksession = createSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Java",
                                                          new JavaInvocationWorkItemHandler());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("Class",
               "org.jbpm.process.workitem.java.MyJavaClass");
    params.put("Method",
               "staticMethod1");
    params.put("Object",
               new MyJavaClass());
    ksession.startProcess("com.sample.bpmn.java",
                          params);
}
 
Example 2
Source File: StandaloneBPMNProcessTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testEventBasedSplit() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EventBasedSplit.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    // Yes
    ProcessInstance processInstance = ksession.startProcess("com.sample.test");
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    ksession.signalEvent("Yes", "YesValue", processInstance.getId());
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    // No
    processInstance = ksession.startProcess("com.sample.test");
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    ksession.signalEvent("No", "NoValue", processInstance.getId());
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
 
Example 3
Source File: ProcessFlowControlTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testRuleFlowActionDialects() throws Exception {
    builder.addRuleFlow( new InputStreamReader( getClass().getResourceAsStream( "test_ActionDialects.rfm" ) ) );

    final KieSession session = createKieSession(true, builder.getPackages());
    
    List<String> list = new ArrayList<String>();
    session.setGlobal( "list",
                       list );

    session.startProcess( "ActionDialects" );

    assertEquals( 2,
                  list.size() );
    assertEquals( "mvel was here",
                  list.get( 0 ) );
    assertEquals( "java was here",
                  list.get( 1 ) );
}
 
Example 4
Source File: SLAComplianceTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testSLAonProcessMet() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLA.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);        
    
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);

    WorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("ActorId"));
            
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);

    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);        
    
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(ProcessInstance.SLA_MET, slaCompliance);
    
    ksession.dispose();
}
 
Example 5
Source File: ActivityTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testUserTaskParametrizedInput() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithParametrizedInput.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    ksession = restoreSession(ksession, true);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("Executing task of process instance " + processInstance.getId() + " as work item with Hello",
            workItem.getParameter("Description").toString().trim());
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    ksession.dispose();
}
 
Example 6
Source File: CompensationTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void compensationInSubSubProcesses() throws Exception {
    KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-InSubSubProcess.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "0");
    ProcessInstance processInstance = ksession.startProcess("CompensateSubSubSub", params);

    ksession.signalEvent("Compensation", "_C-2", processInstance.getId());
    
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);

    // compensation activity (assoc. with script task) signaled *after* script task
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    assertProcessVarValue(processInstance, "x", "2");
}
 
Example 7
Source File: WorkItemHandlerExceptionHandlingTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Test
public void testErrornousHandlerWithStrategyRetry() throws Exception {
      
    KieBase kbase = createKnowledgeBaseWithoutDumper("handler/BPMN2-UserTaskWithBooleanOutput.bpmn2", "handler/BPMN2-ScriptTask.bpmn2");

    KieSession ksession = createKnowledgeSession(kbase);
    ErrornousWorkItemHandler workItemHandler = new ErrornousWorkItemHandler("ScriptTask", HandlingStrategy.RETRY);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    
    Map<String, Object> params = new HashMap<>();
    params.put("isChecked", false);
    ProcessInstance processInstance = ksession.startProcess("com.sample.boolean", params);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    assertProcessVarValue(processInstance, "isChecked", "true");
          
}
 
Example 8
Source File: JavaInvokerTest.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
@Test
public void failingtestHello() throws Exception {
    KieBase kbase = readKnowledgeBase();
    KieSession ksession = createSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Java",
                                                          new JavaInvocationWorkItemHandler());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("Class",
               "org.jbpm.process.workitem.java.MyJavaClass");
    params.put("Method",
               "writeHello");
    List<Object> parameters = new ArrayList<Object>();
    parameters.add("krisv");
    params.put("Parameters",
               parameters);
    ksession.startProcess("com.sample.bpmn.java",
                          params);
}
 
Example 9
Source File: ExecutionFlowControlTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testRuleFlowUpgrade() throws Exception {
    final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    // Set the system property so that automatic conversion can happen
    System.setProperty( "drools.ruleflow.port", "true" );

    kbuilder.add( ResourceFactory.newClassPathResource("ruleflow.drl", ExecutionFlowControlTest.class), ResourceType.DRL);
    kbuilder.add( ResourceFactory.newClassPathResource("ruleflow40.rfm", ExecutionFlowControlTest.class), ResourceType.DRF);
    KieBase kbase = kbuilder.newKieBase();
    final KieSession ksession = kbase.newKieSession();
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.fireAllRules();
    assertEquals(0, list.size());
    final ProcessInstance processInstance = ksession.startProcess("0");
    assertEquals( ProcessInstance.STATE_COMPLETED,
            processInstance.getState() );
    
    assertEquals( 4,
                  list.size() );
    assertEquals( "Rule1",
                  list.get( 0 ) );
    list.subList(1,2).contains( "Rule2" );
    list.subList(1,2).contains( "Rule3" );
    assertEquals( "Rule4",
                  list.get( 3 ) );
    assertEquals( ProcessInstance.STATE_COMPLETED,
                  processInstance.getState() );
    // Reset the system property so that automatic conversion should not happen
    System.setProperty("drools.ruleflow.port", "false");
}
 
Example 10
Source File: StandaloneBPMNProcessTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testReceiveTask() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-ReceiveTask.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    ReceiveTaskHandler receiveTaskHandler = new ReceiveTaskHandler(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler);
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("ReceiveTask");
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    ksession = restoreSession(ksession);
    receiveTaskHandler.messageReceived("HelloMessage", "Hello john!");
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
 
Example 11
Source File: StandaloneBPMNProcessTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiInstanceLoopCharacteristicsProcess() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-MultiInstanceLoopCharacteristicsProcess.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    Map<String, Object> params = new HashMap<String, Object>();
    List<String> myList = new ArrayList<String>();
    myList.add("First Item");
    myList.add("Second Item");
    params.put("list", myList);
    ProcessInstance processInstance = ksession.startProcess("MultiInstanceLoopCharacteristicsProcess", params);
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
 
Example 12
Source File: CompensationTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void compensationInvokingSubProcess() throws Exception {
	KieSession ksession = createKnowledgeSession("compensation/BPMN2-UserTaskCompensation.bpmn2");
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
    
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("compensation", "True");
    ProcessInstance processInstance = ksession.startProcess("UserTaskCompensation", params);
    
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    assertProcessVarValue(processInstance, "compensation", "compensation");
}
 
Example 13
Source File: StandaloneBPMNProcessTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoneIntermediateThrow() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateThrowEventNone.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession.startProcess("NoneIntermediateEvent", null);
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
 
Example 14
Source File: WorkflowEngineImpl.java    From tutorials with MIT License 4 votes vote down vote up
private ProcessInstance executeProcessInstance(String processId, RuntimeManager manager, Context<String> initialContext, RuntimeEngine engine) {
    KieSession ksession = engine.getKieSession();
    ProcessInstance pInstance = ksession.startProcess(processId);
    return pInstance;
}
 
Example 15
Source File: ProcessEventTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@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.addRuleFlow(source);
    KieSession session = createKieSession(builder.getPackages());
    
    ProcessInstance processInstance = session.startProcess("org.drools.core.event");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    assertEquals("SomeText", ((VariableScopeInstance) 
		((org.jbpm.process.instance.ProcessInstance) processInstance).getContextInstance(
VariableScope.VARIABLE_SCOPE)).getVariable("MyVar"));

    session = JbpmSerializationHelper.getSerialisedStatefulKnowledgeSession(session);
    processInstance = session.getProcessInstance(processInstance.getId());
    ((InternalWorkingMemory) session).getProcessRuntime().signalEvent("MyEvent", "MyValue");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
}
 
Example 16
Source File: ProcessForEachTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testForEachNullList() {
    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);
    ProcessInstance processInstance = ( ProcessInstance )
        workingMemory.startProcess("org.drools.ForEach");
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
 
Example 17
Source File: ProcessWorkItemTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testWorkItemImmediateCompletion() {
	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" +
		"    <variables>\n" +
		"      <variable name=\"UserName\" >\n" +
		"        <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" +
		"        <value>John Doe</value>\n" +
		"      </variable>\n" +
 		"      <variable name=\"Person\" >\n" +
		"        <type name=\"org.jbpm.process.core.datatype.impl.type.ObjectDataType\" className=\"org.jbpm.integrationtests.test.Person\" />\n" +
		"      </variable>\n" +
		"      <variable name=\"MyObject\" >\n" +
		"        <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" +
		"      </variable>\n" +
		"      <variable name=\"Number\" >\n" +
		"        <type name=\"org.jbpm.process.core.datatype.impl.type.IntegerDataType\" />\n" +
		"      </variable>\n" +
		"    </variables>\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>#{UserName}</value>\n" +
        "        </parameter>\n" +
        "        <parameter name=\"Content\" >\n" +
        "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" +
        "          <value>#{Person.name}</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" +
        "        <parameter name=\"Attachment\" >\n" +
        "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" +
        "        </parameter>\n" +
        "      </work>\n" +
        "      <mapping type=\"in\" from=\"MyObject\" to=\"Attachment\" />" +
        "      <mapping type=\"in\" from=\"Person.name\" to=\"Comment\" />" +
        "      <mapping type=\"out\" from=\"Result\" to=\"MyObject\" />" +
        "      <mapping type=\"out\" from=\"Result.length()\" to=\"Number\" />" +
        "    </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( ResourceFactory.newReaderResource( source ), ResourceType.DRF );
    
    Collection<KiePackage> kpkgs = kbuilder.getKnowledgePackages();
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages( kpkgs );        
    KieSession ksession = kbase.newKieSession();
	
    ImmediateTestWorkItemHandler handler = new ImmediateTestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("UserName", "John Doe");
    Person person = new Person();
    person.setName("John Doe");
    parameters.put("Person", person);
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance)
    	ksession.startProcess("org.drools.actions", parameters);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
 
Example 18
Source File: ProcessFlowControlTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testRuleFlowConstraintDialects() throws Exception {
    builder.addRuleFlow( new InputStreamReader( getClass().getResourceAsStream( "test_ConstraintDialects.rfm" ) ) );

    logger.error( builder.getErrors().toString() );

    assertEquals( 0,
                  builder.getErrors().getErrors().length );

    KieSession session = createKieSession(true, builder.getPackages());
    List<Integer> inList = new ArrayList<Integer>();
    List<Integer> outList = new ArrayList<Integer>();
    session.setGlobal( "inList",
                       inList );
    session.setGlobal( "outList",
                       outList );

    inList.add( 1 );
    inList.add( 3 );
    inList.add( 6 );
    inList.add( 25 );

    FactHandle handle = session.insert( inList );
    session.startProcess( "ConstraintDialects" );
    assertEquals( 4,
                  outList.size() );
    assertEquals( "MVELCodeConstraint was here",
                  outList.get( 0 ) );
    assertEquals( "JavaCodeConstraint was here",
                  outList.get( 1 ) );
    assertEquals( "MVELRuleConstraint was here",
                  outList.get( 2 ) );
    assertEquals( "JavaRuleConstraint was here",
                  outList.get( 3 ) );

    outList.clear();
    inList.remove( new Integer( 1 ) );
    session.update( handle,
                    inList );
    session.startProcess( "ConstraintDialects" );
    assertEquals( 3,
                  outList.size() );
    assertEquals( "JavaCodeConstraint was here",
                  outList.get( 0 ) );
    assertEquals( "MVELRuleConstraint was here",
                  outList.get( 1 ) );
    assertEquals( "JavaRuleConstraint was here",
                  outList.get( 2 ) );

    outList.clear();
    inList.remove( new Integer( 6 ) );
    session.update( handle,
                    inList );
    session.startProcess( "ConstraintDialects" );
    assertEquals( 2,
                  outList.size() );
    assertEquals( "JavaCodeConstraint was here",
                  outList.get( 0 ) );
    assertEquals( "JavaRuleConstraint was here",
                  outList.get( 1 ) );

    outList.clear();
    inList.remove( new Integer( 3 ) );
    session.update( handle,
                    inList );
    session.startProcess( "ConstraintDialects" );
    assertEquals( 1,
                  outList.size() );
    assertEquals( "JavaRuleConstraint was here",
                  outList.get( 0 ) );

    outList.clear();
    inList.remove( new Integer( 25 ) );
    session.update( handle,
                    inList );
    ProcessInstance processInstance = session.startProcess( "ConstraintDialects" );
    
    assertEquals( ProcessInstance.STATE_ERROR,
                  processInstance.getState() );
}
 
Example 19
Source File: ForEachTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void test() {
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("ParentProcess");
    factory.variable("x", new ObjectDataType("java.lang.String"));
    factory.variable("y", new ObjectDataType("java.lang.String"));
    factory.variable("list", new ObjectDataType("java.util.List"));
    factory.variable("listOut", new ObjectDataType("java.util.List"));
    factory.name("Parent Process");
    factory.packageName("org.drools.bpmn2");
    factory.dynamic(false);
    factory.version("1.0");
    factory.visibility("Private");
    factory.metaData("TargetNamespace", "http://www.example.org/MinimalExample");
    org.jbpm.ruleflow.core.factory.StartNodeFactory startNode1 = factory.startNode(1);
    startNode1.name("StartProcess");
    startNode1.done();
    org.jbpm.ruleflow.core.factory.ForEachNodeFactory forEachNode2 = factory.forEachNode(2);        
    forEachNode2.metaData("UniqueId", "_2");
    forEachNode2.metaData("MICollectionOutput", "_2_listOutOutput");
    forEachNode2.metaData("x", 96);
    forEachNode2.metaData("width", 110);
    forEachNode2.metaData("y", 16);
    forEachNode2.metaData("MICollectionInput", "_2_input");
    forEachNode2.metaData("height", 48);
    forEachNode2.collectionExpression("list");
    forEachNode2.variable("x", new ObjectDataType("java.lang.String"));
    forEachNode2.outputCollectionExpression("listOut");
    forEachNode2.outputVariable("y", new ObjectDataType("java.lang.String"));
    
    forEachNode2.actionNode(5).action((kcontext) -> System.out.println(kcontext.getVariable("x"))).done();
    forEachNode2.linkIncomingConnections(5);
    forEachNode2.linkOutgoingConnections(5);
    
    forEachNode2.done();
    org.jbpm.ruleflow.core.factory.EndNodeFactory endNode3 = factory.endNode(3);
    endNode3.name("EndProcess");
    endNode3.terminate(true);
    endNode3.done();
    factory.connection(1, 2, "_1-_2");
    factory.connection(2, 3, "_2-_3");
    factory.validate();
    
    List<String> list = new ArrayList<String>();
    list.add("first");
    list.add("second");
    List<String> listOut = new ArrayList<String>();
    
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("x", "oldValue");
    parameters.put("list", list);
    parameters.put("listOut", listOut);
    
    KieSession ksession = createKieSession(factory.getProcess());
    
    ksession.startProcess("ParentProcess", parameters);
}
 
Example 20
Source File: ProcessHumanTaskTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testHumanTaskCancel2() {
    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.humantask\" package-name=\"org.drools\" version=\"1\" >\n" +
        "\n" +
        "  <header>\n" +
        "  </header>\n" +
        "\n" +
        "  <nodes>\n" +
        "    <start id=\"1\" name=\"Start\" />\n" +
        "    <humanTask 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" +
        "      <onExit>\n" +
        "        <action type=\"expression\" name=\"Cancel\" dialect=\"java\" >((org.jbpm.workflow.instance.NodeInstance) kcontext.getNodeInstance()).cancel();</action>\n" +
        "      </onExit>\n" +
        "    </humanTask>\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());
    
    TestWorkItemHandler handler = new TestWorkItemHandler();
    workingMemory.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ( ProcessInstance )
        workingMemory.startProcess("org.drools.humantask");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    workingMemory.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertFalse(handler.isAborted());
}