use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class TestXml method testSimpleXml.
@Test
public void testSimpleXml() throws Exception {
SemanticModules modules = new SemanticModules();
modules.addSemanticModule(new ProcessSemanticModule());
XmlProcessReader reader = new XmlProcessReader(modules, getClass().getClassLoader());
reader.read(new InputStreamReader(TestXml.class.getResourceAsStream("XmlTest.xml")));
List<Process> processes = reader.getProcess();
assertNotNull(processes);
assertEquals(1, processes.size());
RuleFlowProcess process = (RuleFlowProcess) processes.get(0);
assertNotNull(process);
String output = XmlRuleFlowProcessDumper.INSTANCE.dump(process);
logger.info(output);
reader = new XmlProcessReader(new SemanticModules(), getClass().getClassLoader());
reader.read(new StringReader(output));
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class SubProcessTest method testAsynchronousSubProcess.
@Test
public void testAsynchronousSubProcess() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.process");
process.setName("Process");
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(2);
process.addNode(endNode);
SubProcessNode subProcessNode = new SubProcessNode();
subProcessNode.setName("SubProcessNode");
subProcessNode.setId(3);
subProcessNode.setProcessId("org.drools.core.process.subprocess");
process.addNode(subProcessNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, subProcessNode, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(subProcessNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
RuleFlowProcess subProcess = new RuleFlowProcess();
subProcess.setId("org.drools.core.process.subprocess");
subProcess.setName("SubProcess");
startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
subProcess.addNode(startNode);
endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(2);
subProcess.addNode(endNode);
WorkItemNode workItemNode = new WorkItemNode();
workItemNode.setName("WorkItem");
Work work = new WorkImpl();
work.setName("MyWork");
workItemNode.setWork(work);
workItemNode.setId(4);
subProcess.addNode(workItemNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, workItemNode, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(workItemNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
KieSession ksession = createKieSession(process, subProcess);
ksession.getWorkItemManager().registerWorkItemHandler("MyWork", new WorkItemHandler() {
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
logger.info("Executing work item");
SubProcessTest.this.workItem = workItem;
}
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
}
});
ksession.startProcess("org.drools.core.process.process");
TestProcessEventListener procEventListener = new TestProcessEventListener();
ksession.addEventListener(procEventListener);
assertNotNull(workItem);
assertEquals(2, ksession.getProcessInstances().size());
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertEquals(0, ksession.getProcessInstances().size());
verifyEventHistory(asyncEventOrder, procEventListener.getEventHistory());
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class WorkItemTest method testCancelNonRegisteredWorkItemHandler.
@Test
public void testCancelNonRegisteredWorkItemHandler() {
String processId = "org.drools.actions";
String workName = "Unnexistent Task";
RuleFlowProcess process = getWorkItemProcess(processId, workName);
KieSession ksession = createKieSession(process);
ksession.getWorkItemManager().registerWorkItemHandler(workName, new DoNothingWorkItemHandler());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Doe"));
ProcessInstance processInstance = ksession.startProcess("org.drools.actions", parameters);
long processInstanceId = processInstance.getId();
Assert.assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
ksession.getWorkItemManager().registerWorkItemHandler(workName, null);
try {
ksession.abortProcessInstance(processInstanceId);
Assert.fail("should fail if WorkItemHandler for" + workName + "is not registered");
} catch (WorkItemHandlerNotFoundException wihnfe) {
}
Assert.assertEquals(ProcessInstance.STATE_ABORTED, processInstance.getState());
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class RuleFlowProcessValidatorTest method testEmptyPackageName.
@Test
public void testEmptyPackageName() throws Exception {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process");
process.setName("Empty Package Name Process");
process.setPackageName("");
process.setDynamic(true);
ProcessValidationError[] errors = validator.validateProcess(process);
assertNotNull(errors);
assertEquals(0, errors.length);
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class NodeInnerClassesTest method testNodeReading.
@Test
public void testNodeReading() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.event");
process.setName("Event Process");
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("event");
ObjectDataType personDataType = new ObjectDataType();
personDataType.setClassName("org.drools.Person");
variable.setType(personDataType);
variables.add(variable);
process.getVariableScope().setVariables(variables);
CompositeNode compositeNode = new CompositeNode();
compositeNode.setName("CompositeNode");
compositeNode.setId(2);
ForEachNode forEachNode = new ForEachNode();
ForEachNode.ForEachSplitNode split = new ForEachNode.ForEachSplitNode();
split.setName("ForEachSplit");
split.setMetaData("hidden", true);
split.setMetaData("UniqueId", forEachNode.getMetaData("Uniqueid") + ":foreach:split");
forEachNode.internalAddNode(split);
forEachNode.linkIncomingConnections(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, new CompositeNode.NodeAndType(split, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE));
process.addNode(forEachNode);
KieSession ksession = createKieSession(process);
TestProcessEventListener procEventListener = new TestProcessEventListener();
ksession.addEventListener(procEventListener);
ProcessInstance processInstance = ksession.startProcess("org.drools.core.process.event");
Assert.assertNotNull(processInstance);
}
Aggregations