Search in sources :

Example 21 with ProcessInstance

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

the class ProcessHumanTaskTest method testHumanTask.

@Test
public void testHumanTask() {
    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" + "    </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);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : TestWorkItemHandler(org.jbpm.integrationtests.handler.TestWorkItemHandler) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.jbpm.process.instance.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 22 with ProcessInstance

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

the class ProcessMilestoneTest method testMilestoneWithProcessInstanceConstraint.

@Test
public void testMilestoneWithProcessInstanceConstraint() {
    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.milestone\" package-name=\"org.jbpm\" version=\"1\" >\n" + "\n" + "  <header>\n" + "    <imports>\n" + "      <import name=\"org.jbpm.integrationtests.test.Person\" />\n" + "      <import name=\"org.jbpm.integrationtests.ProcessMilestoneTest.ProcessUtils\" />\n" + "    </imports>\n" + "    <variables>\n" + "      <variable name=\"name\" >\n" + "        <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "      </variable>\n" + "    </variables>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <milestone id=\"2\" name=\"Milestone\" >\n" + "      <constraint type=\"rule\" dialect=\"mvel\" >processInstance: org.jbpm.ruleflow.instance.RuleFlowProcessInstance()\n" + "Person( name == (ProcessUtils.getValue(processInstance, \"name\")) )</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);
    for (DroolsError error : builder.getErrors().getErrors()) {
        logger.error(error.toString());
    }
    KieSession workingMemory = createKieSession(builder.getPackages());
    Person john = new Person("John Doe", 20);
    Person jane = new Person("Jane Doe", 20);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("name", john.getName());
    ProcessInstance processInstanceJohn = (ProcessInstance) workingMemory.startProcess("org.drools.milestone", params);
    workingMemory.insert(processInstanceJohn);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstanceJohn.getState());
    params = new HashMap<String, Object>();
    params.put("name", jane.getName());
    ProcessInstance processInstanceJane = (ProcessInstance) workingMemory.startProcess("org.drools.milestone", params);
    workingMemory.insert(processInstanceJane);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstanceJane.getState());
    workingMemory.insert(jane);
    workingMemory.fireAllRules();
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstanceJohn.getState());
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstanceJane.getState());
    workingMemory.insert(john);
    workingMemory.fireAllRules();
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstanceJohn.getState());
}
Also used : DroolsError(org.drools.compiler.compiler.DroolsError) HashMap(java.util.HashMap) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessInstance(org.jbpm.process.instance.ProcessInstance) Person(org.jbpm.integrationtests.test.Person) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 23 with ProcessInstance

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

the class ProcessMilestoneTest method testMilestone.

@Test
public void testMilestone() {
    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.milestone\" package-name=\"org.jbpm\" version=\"1\" >\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=\"Milestone\" >\n" + "      <constraint type=\"rule\" dialect=\"mvel\" >Person( name == \"John Doe\" )</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());
    ProcessInstance processInstance = (ProcessInstance) workingMemory.startProcess("org.drools.milestone");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    workingMemory.insert(new Person("Jane Doe", 20));
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    workingMemory.insert(new Person("John Doe", 50));
    workingMemory.fireAllRules();
    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) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessInstance(org.jbpm.process.instance.ProcessInstance) Person(org.jbpm.integrationtests.test.Person) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 24 with ProcessInstance

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

the class ProcessTimerTest method testOnEntryTimerExecuted.

@Test
public void testOnEntryTimerExecuted() 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.timer\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + "  <header>\n" + "    <globals>\n" + "      <global identifier=\"myList\" type=\"java.util.List\" />\n" + "    </globals>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <milestone id=\"2\" name=\"Wait\" >\n" + "      <timers>\n" + "        <timer id=\"1\" delay=\"300\" >\n" + "          <action type=\"expression\" dialect=\"java\" >myList.add(\"Executing timer\");</action>\n" + "        </timer>\n" + "      </timers>\n" + "      <constraint type=\"rule\" dialect=\"mvel\" >eval(false)</constraint>\n" + "    </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 session = createKieSession(builder.getPackages());
    List<String> myList = new ArrayList<String>();
    session.setGlobal("myList", myList);
    ProcessInstance processInstance = (ProcessInstance) session.startProcess("org.drools.timer");
    assertEquals(0, myList.size());
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    assertEquals(1, ((InternalProcessRuntime) ((InternalWorkingMemory) session).getProcessRuntime()).getTimerManager().getTimers().size());
    try {
        Thread.sleep(400);
    } catch (InterruptedException e) {
    // do nothing
    }
    assertEquals(1, myList.size());
    session.dispose();
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) 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 25 with ProcessInstance

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

the class ProcessTimerTest method testOnEntryTimerExecutedMultipleTimes.

@Test
public void testOnEntryTimerExecutedMultipleTimes() 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.timer\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + "  <header>\n" + "    <globals>\n" + "      <global identifier=\"myList\" type=\"java.util.List\" />\n" + "    </globals>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <milestone id=\"2\" name=\"Wait\" >\n" + "      <timers>\n" + "        <timer id=\"1\" delay=\"300\" period =\"200\" >\n" + "          <action type=\"expression\" dialect=\"java\" >myList.add(\"Executing timer\");</action>\n" + "        </timer>\n" + "      </timers>\n" + "      <constraint type=\"rule\" dialect=\"mvel\" >eval(false)</constraint>\n" + "    </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 session = createKieSession(builder.getPackages());
    List<String> myList = new ArrayList<String>();
    session.setGlobal("myList", myList);
    ProcessInstance processInstance = (ProcessInstance) session.startProcess("org.drools.timer");
    assertEquals(0, myList.size());
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    assertEquals(1, ((InternalProcessRuntime) ((InternalWorkingMemory) session).getProcessRuntime()).getTimerManager().getTimers().size());
    session.halt();
    try {
        Thread.sleep(600);
    } catch (InterruptedException e) {
    // do nothing
    }
    assertEquals(2, myList.size());
    session.dispose();
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) 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