use of org.jbpm.integrationtests.test.Person in project jbpm by kiegroup.
the class ProcessWorkItemTest method testWorkItem.
@Test
public void testWorkItem() {
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);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = kbase.newKieSession();
TestWorkItemHandler handler = new TestWorkItemHandler();
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_ACTIVE, processInstance.getState());
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
assertEquals("John Doe", workItem.getParameter("ActorId"));
assertEquals("John Doe", workItem.getParameter("Content"));
assertEquals("John Doe", workItem.getParameter("Comment"));
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
parameters = new HashMap<String, Object>();
parameters.put("UserName", "Jane Doe");
parameters.put("MyObject", "SomeString");
person = new Person();
person.setName("Jane Doe");
parameters.put("Person", person);
processInstance = (WorkflowProcessInstance) ksession.startProcess("org.drools.actions", parameters);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
workItem = handler.getWorkItem();
assertNotNull(workItem);
assertEquals("Jane Doe", workItem.getParameter("ActorId"));
assertEquals("SomeString", workItem.getParameter("Attachment"));
assertEquals("Jane Doe", workItem.getParameter("Content"));
assertEquals("Jane Doe", workItem.getParameter("Comment"));
Map<String, Object> results = new HashMap<String, Object>();
results.put("Result", "SomeOtherString");
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), results);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
assertEquals("SomeOtherString", processInstance.getVariable("MyObject"));
assertEquals(15, processInstance.getVariable("Number"));
}
use of org.jbpm.integrationtests.test.Person in project jbpm by kiegroup.
the class ProcessMarshallingTest method testVariablePersistenceMarshallingStrategies.
@Test
public void testVariablePersistenceMarshallingStrategies() throws Exception {
String process = "<?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.test.ruleflow\" package-name=\"org.test\" >\n" + " <header>\n" + " <variables>\n" + " <variable name=\"myVariable\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>OldValue</value>\n" + " </variable>\n" + " <variable name=\"myPerson\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.ObjectDataType\" className=\"org.jbpm.integrationtests.test.Person\"/>\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <workItem id=\"2\" name=\"Email\" >\n" + " <work name=\"Report\" >\n" + " <parameter name=\"Subject\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>Mail</value>\n" + " </parameter>\n" + " <parameter name=\"Subject\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>Mail</value>\n" + " </parameter>\n" + " </work>\n" + " </workItem>\n" + " <end id=\"3\" name=\"End\" />\n" + " </nodes>\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\"/>\n" + " <connection from=\"2\" to=\"3\"/>\n" + " </connections>\n" + "</process>";
builder.addProcessFromXml(new StringReader(process));
KieSession session = createKieSession(builder.getPackages());
TestWorkItemHandler handler = new TestWorkItemHandler();
session.getWorkItemManager().registerWorkItemHandler("Report", handler);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("myVariable", "ThisIsMyValue");
Person myPerson = new Person("Nikola Tesla", 156);
variables.put("myPerson", myPerson);
session.startProcess("org.test.ruleflow", variables);
assertEquals(1, session.getProcessInstances().size());
assertTrue(handler.getWorkItem() != null);
session = getSerialisedStatefulKnowledgeSession(session);
assertEquals(1, session.getProcessInstances().size());
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ProcessInstance) session.getProcessInstances().iterator().next()).getContextInstance(VariableScope.VARIABLE_SCOPE);
assertEquals("ThisIsMyValue", variableScopeInstance.getVariable("myVariable"));
assertEquals(myPerson, variableScopeInstance.getVariable("myPerson"));
session.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
assertEquals(0, session.getProcessInstances().size());
}
use of org.jbpm.integrationtests.test.Person in project jbpm by kiegroup.
the class ProcessRuleFlowGroupTest method testRuleSetProcessContext.
@Test
public void testRuleSetProcessContext() 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.ruleset\" package-name=\"org.jbpm\" version=\"1\" >\n" + "\n" + " <header>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <ruleSet id=\"2\" name=\"RuleSet\" ruleFlowGroup=\"MyGroup\" >\n" + " </ruleSet>\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>");
Reader source2 = new StringReader("package org.jbpm;\n" + "\n" + "import org.jbpm.integrationtests.test.Person;\n" + "import org.kie.api.runtime.process.ProcessContext;\n" + "\n" + "rule MyRule ruleflow-group \"MyGroup\" dialect \"mvel\" \n" + " when\n" + " Person( age > 25 )\n" + " then\n" + " System.out.println(drools.getContext(ProcessContext).getProcessInstance().getProcessName());\n" + "end");
builder.addRuleFlow(source);
builder.addPackageFromDrl(source2);
KieSession workingMemory = createKieSession(builder.getPackages());
workingMemory.getEnvironment().set("org.jbpm.rule.task.waitstate", "true");
Person person = new Person();
person.setAge(30);
workingMemory.insert(person);
// start process
RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) workingMemory.startProcess("org.drools.ruleset");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
workingMemory.fireAllRules();
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.jbpm.integrationtests.test.Person in project jbpm by kiegroup.
the class ProcessSplitTest method testSplitWithMVELContextConstraint.
@Test
public void testSplitWithMVELContextConstraint() {
Reader source = new StringReader("<process xmlns=\"http://drools.org/drools-5.0/process\"" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"" + " type=\"RuleFlow\" name=\"ruleflow\" id=\"org.jbpm.process-split\" package-name=\"org.jbpm\" >" + "" + " <header>" + " <imports>" + " <import name=\"org.jbpm.integrationtests.test.Person\" />" + " <import name=\"org.jbpm.integrationtests.ProcessSplitTest.ProcessUtils\" />" + " </imports>" + " <globals>" + " <global identifier=\"list\" type=\"java.util.List\" />" + " </globals>" + " <variables>\n" + " <variable name=\"person\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.ObjectDataType\" className=\"org.jbpm.integrationtests.test.Person\" />\n" + " </variable>\n" + " </variables>\n" + " </header>" + "" + " <nodes>" + " <actionNode id=\"2\" name=\"Action\" >" + " <action type=\"expression\" dialect=\"mvel\" >insert(kcontext.getProcessInstance());</action>" + " </actionNode>" + " <split id=\"4\" name=\"Split\" type=\"2\" >" + " <constraints>" + " <constraint toNodeId=\"8\" toType=\"DROOLS_DEFAULT\" priority=\"2\" type=\"code\" dialect=\"mvel\" >return true;</constraint>" + " <constraint toNodeId=\"6\" toType=\"DROOLS_DEFAULT\" priority=\"1\" type=\"code\" dialect=\"mvel\" >return kcontext.getVariable(\"person\") != null && ((Person) kcontext.getVariable(\"person\")).name != null;</constraint>" + " </constraints>" + " </split>" + " <end id=\"8\" name=\"End\" />" + " <actionNode id=\"6\" name=\"Action\" >" + " <action type=\"expression\" dialect=\"mvel\" >list.add(kcontext.getProcessInstance().getId());</action>" + " </actionNode>" + " <start id=\"1\" name=\"Start\" />" + " <end id=\"3\" name=\"End\" />" + " </nodes>" + " <connections>" + " <connection from=\"1\" to=\"2\" />" + " <connection from=\"2\" to=\"4\" />" + " <connection from=\"4\" to=\"8\" />" + " <connection from=\"4\" to=\"6\" />" + " <connection from=\"6\" to=\"3\" />" + " </connections>" + "" + "</process>");
builder.addRuleFlow(source);
KieSession workingMemory = createKieSession(builder.getPackages());
List<Long> list = new ArrayList<Long>();
workingMemory.setGlobal("list", list);
Map<String, Object> params = new HashMap<String, Object>();
params.put("person", new Person("John Doe"));
ProcessInstance processInstance = (ProcessInstance) workingMemory.startProcess("org.jbpm.process-split", params);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
assertEquals(1, list.size());
}
use of org.jbpm.integrationtests.test.Person in project jbpm by kiegroup.
the class ProcessSplitTest method testSplitWithProcessInstanceConstraint.
@Test
public void testSplitWithProcessInstanceConstraint() {
Reader source = new StringReader("<process xmlns=\"http://drools.org/drools-5.0/process\"" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"" + " type=\"RuleFlow\" name=\"ruleflow\" id=\"org.jbpm.process-split\" package-name=\"org.jbpm\" >" + "" + " <header>" + " <imports>" + " <import name=\"org.jbpm.integrationtests.test.Person\" />" + " <import name=\"org.jbpm.integrationtests.ProcessSplitTest.ProcessUtils\" />" + " </imports>" + " <globals>" + " <global identifier=\"list\" type=\"java.util.List\" />" + " </globals>" + " <variables>\n" + " <variable name=\"name\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </variable>\n" + " </variables>\n" + " </header>" + "" + " <nodes>" + " <actionNode id=\"2\" name=\"Action\" >" + " <action type=\"expression\" dialect=\"mvel\" >insert(kcontext.getProcessInstance());</action>" + " </actionNode>" + " <split id=\"4\" name=\"Split\" type=\"2\" >" + " <constraints>" + " <constraint toNodeId=\"8\" priority=\"2\" type=\"rule\" dialect=\"mvel\" >eval(true)</constraint>" + " <constraint toNodeId=\"6\" name=\"constraint\" priority=\"1\" type=\"rule\" dialect=\"mvel\" >processInstance: org.jbpm.ruleflow.instance.RuleFlowProcessInstance()" + "Person( name == (ProcessUtils.getValue(processInstance, \"name\")) )</constraint>" + " </constraints>" + " </split>" + " <end id=\"8\" name=\"End\" />" + " <actionNode id=\"6\" name=\"Action\" >" + " <action type=\"expression\" dialect=\"mvel\" >list.add(kcontext.getProcessInstance().getId());</action>" + " </actionNode>" + " <start id=\"1\" name=\"Start\" />" + " <end id=\"3\" name=\"End\" />" + " </nodes>" + " <connections>" + " <connection from=\"1\" to=\"2\" />" + " <connection from=\"2\" to=\"4\" />" + " <connection from=\"4\" to=\"8\" />" + " <connection from=\"4\" to=\"6\" />" + " <connection from=\"6\" to=\"3\" />" + " </connections>" + "" + "</process>");
builder.addRuleFlow(source);
KieSession workingMemory = createKieSession(builder.getPackages());
List<Long> list = new ArrayList<Long>();
workingMemory.setGlobal("list", list);
Person john = new Person("John Doe", 20);
Person jane = new Person("Jane Doe", 20);
Person julie = new Person("Julie Doe", 20);
workingMemory.insert(john);
workingMemory.insert(jane);
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", john.getName());
ProcessInstance processInstance1 = (ProcessInstance) workingMemory.startProcess("org.jbpm.process-split", params);
params = new HashMap<String, Object>();
params.put("name", jane.getName());
ProcessInstance processInstance2 = (ProcessInstance) workingMemory.startProcess("org.jbpm.process-split", params);
params = new HashMap<String, Object>();
params.put("name", julie.getName());
ProcessInstance processInstance3 = (ProcessInstance) workingMemory.startProcess("org.jbpm.process-split", params);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance1.getState());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance2.getState());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance3.getState());
assertEquals(2, list.size());
}
Aggregations