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());
}
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());
}
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());
}
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();
}
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();
}
Aggregations