use of org.jbpm.process.instance.ProcessInstance in project jbpm by kiegroup.
the class ProcessDynamicNodeTest method TODOtestDynamicActions.
@Test
@Ignore
public void TODOtestDynamicActions() {
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" + " <globals>\n" + " <global identifier=\"list\" type=\"java.util.List\" />\n" + " </globals>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <dynamic id=\"2\" name=\"DynamicNode\" >\n" + " <nodes>\n" + " <actionNode id=\"1\" name=\"Action1\" >\n" + " <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Action1\");\n" + "list.add(\"Action1\");</action>\n" + " </actionNode>\n" + " <actionNode id=\"2\" name=\"Action2\" >\n" + " <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Action2\");\n" + "list.add(\"Action2\");</action>\n" + " </actionNode>\n" + " <actionNode id=\"3\" name=\"Action3\" >\n" + " <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Action3\");\n" + "list.add(\"Action3\");</action>\n" + " </actionNode>\n" + " </nodes>\n" + " <connections>\n" + " <connection from=\"1\" to=\"3\" />\n" + " </connections>\n" + " <in-ports/>\n" + " <out-ports/>\n" + " </dynamic>\n" + " <actionNode id=\"3\" name=\"Action4\" >\n" + " <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Action4\");\n" + "list.add(\"Action4\");</action>\n" + " </actionNode>\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>");
builder.addRuleFlow(source);
for (DroolsError error : builder.getErrors().getErrors()) {
logger.error(error.toString());
}
KieSession ksession = createKieSession(builder.getPackages());
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ProcessInstance processInstance = (ProcessInstance) ksession.startProcess("org.drools.dynamic");
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
assertEquals(4, list.size());
}
use of org.jbpm.process.instance.ProcessInstance in project jbpm by kiegroup.
the class ProcessDynamicNodeTest method testAddDynamicSubProcess.
@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" + " <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();
}
use of org.jbpm.process.instance.ProcessInstance in project jbpm by kiegroup.
the class ProcessExceptionHandlerTest method testFaultWithoutHandler.
@Test
public void testFaultWithoutHandler() {
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.exception\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <fault id=\"2\" name=\"Fault\" faultName=\"myFault\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " </connections>\n" + "\n" + "</process>");
builder.addRuleFlow(source);
PackageBuilderErrors errors = builder.getErrors();
if (errors != null && !errors.isEmpty()) {
for (DroolsError error : errors.getErrors()) {
logger.error(error.toString());
}
fail("Package could not be compiled");
}
KieSession session = createKieSession(builder.getPackages());
ProcessInstance processInstance = (ProcessInstance) session.startProcess("org.drools.exception");
assertEquals(ProcessInstance.STATE_ABORTED, processInstance.getState());
}
use of org.jbpm.process.instance.ProcessInstance in project jbpm by kiegroup.
the class ProcessExceptionHandlerTest method testProcessExceptionHandlerAction.
@Test
public void testProcessExceptionHandlerAction() {
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.exception\" 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=\"SomeVar\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>SomeValue</value>\n" + " </variable>\n" + " <variable name=\"faultVar\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </variable>\n" + " </variables>\n" + " <exceptionHandlers>\n" + " <exceptionHandler faultName=\"myFault\" type=\"action\" faultVariable=\"faultVar\" >\n" + " <action type=\"expression\" name=\"Print\" dialect=\"java\" >list.add(context.getVariable(\"faultVar\"));</action>\n" + " </exceptionHandler>\n" + " </exceptionHandlers>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <fault id=\"2\" name=\"Fault\" faultName=\"myFault\" faultVariable=\"SomeVar\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " </connections>\n" + "\n" + "</process>");
builder.addRuleFlow(source);
KieSession session = createKieSession(builder.getPackages());
List<String> list = new ArrayList<String>();
session.setGlobal("list", list);
ProcessInstance processInstance = (ProcessInstance) session.startProcess("org.drools.exception");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
assertEquals(1, list.size());
assertEquals("SomeValue", list.get(0));
}
use of org.jbpm.process.instance.ProcessInstance in project jbpm by kiegroup.
the class ProcessExceptionHandlerTest method testNestedExceptionHandler.
@Test
public void testNestedExceptionHandler() {
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.exception\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <globals>\n" + " <global identifier=\"list\" type=\"java.util.List\" />\n" + " </globals>\n" + " <exceptionHandlers>\n" + " <exceptionHandler faultName=\"otherFault\" type=\"action\" >\n" + " <action type=\"expression\" name=\"Print\" dialect=\"java\" >list.add(\"Triggered global exception scope\");</action>\n" + " </exceptionHandler>\n" + " </exceptionHandlers>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <composite id=\"2\" name=\"Composite\" >\n" + " <variables>\n" + " <variable name=\"SomeVar\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>SomeValue</value>\n" + " </variable>\n" + " <variable name=\"FaultVariable\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " </variable>\n" + " </variables>\n" + " <exceptionHandlers>\n" + " <exceptionHandler faultName=\"MyFault\" type=\"action\" faultVariable=\"FaultVariable\" >\n" + " <action type=\"expression\" name=\"Trigger\" dialect=\"java\" >((org.jbpm.workflow.instance.node.CompositeNodeInstance) context.getNodeInstance()).signalEvent(\"MyEvent\", null);</action>\n" + " </exceptionHandler>\n" + " </exceptionHandlers>\n" + " <nodes>\n" + " <fault id=\"1\" name=\"Fault\" faultName=\"MyFault\" faultVariable=\"SomeVar\" />\n" + " <eventNode id=\"2\" name=\"Event\" >\n" + " <eventFilters>\n" + " <eventFilter type=\"eventType\" eventType=\"MyEvent\" />\n" + " </eventFilters>\n" + " </eventNode>\n" + " <fault id=\"3\" name=\"Fault\" faultName=\"otherFault\" />\n" + " </nodes>\n" + " <connections>\n" + " <connection from=\"2\" to=\"3\" />\n" + " </connections>\n" + " <in-ports>\n" + " <in-port type=\"DROOLS_DEFAULT\" nodeId=\"1\" nodeInType=\"DROOLS_DEFAULT\" />\n" + " </in-ports>\n" + " </composite>\n" + " <end id=\"3\" name=\"End\" />" + " </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> list = new ArrayList<String>();
session.setGlobal("list", list);
ProcessInstance processInstance = (ProcessInstance) session.startProcess("org.drools.exception");
assertEquals(1, list.size());
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
}
Aggregations