Search in sources :

Example 6 with RuleFlowProcessFactory

use of org.jbpm.ruleflow.core.RuleFlowProcessFactory in project jbpm by kiegroup.

the class ProcessFactoryTest method testProcessFactory.

@Test
public void testProcessFactory() throws Exception {
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.drools.core.process");
    factory.name("My process").packageName("org.drools").startNode(1).name("Start").done().actionNode(2).name("Action").action("java", "System.out.println(\"Action\");").done().endNode(3).name("End").done().connection(1, 2).connection(2, 3);
    factory.validate().getProcess();
}
Also used : RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 7 with RuleFlowProcessFactory

use of org.jbpm.ruleflow.core.RuleFlowProcessFactory in project jbpm by kiegroup.

the class ProcessFactoryTest method testCompositeNode.

@Test
public void testCompositeNode() throws Exception {
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
    factory.name("My process").packageName("org.jbpm").startNode(1).name("Start").done().compositeNode(2).name("SubProcess").startNode(1).name("SubProcess Start").done().actionNode(2).name("SubProcess Action").action("java", "System.out.println(\"SubProcess Action\");").done().endNode(3).name("SubProcess End").terminate(true).done().connection(1, 2).connection(2, 3).done().endNode(3).name("End").done().connection(1, 2).connection(2, 3);
    RuleFlowProcess process = factory.validate().getProcess();
    assertEquals("SubProcess", process.getNode(2).getName());
    Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
    // source path or target path must be set to be added into kbase
    res.setSourcePath("/tmp/processFactory.bpmn2");
    KieBase kbase = createKnowledgeBaseFromResources(res);
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ProcessInstance pi = ksession.startProcess("org.jbpm.process");
    assertEquals(ProcessInstance.STATE_COMPLETED, pi.getState());
    ksession.dispose();
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Resource(org.kie.api.io.Resource) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) Test(org.junit.Test)

Example 8 with RuleFlowProcessFactory

use of org.jbpm.ruleflow.core.RuleFlowProcessFactory in project jbpm by kiegroup.

the class ProcessFactoryTest method testActionNodeIsDroolsAction.

@Test(timeout = 10000)
public void testActionNodeIsDroolsAction() throws Exception {
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
    factory.name("ActionNodeActionProcess").version("1").startNode(1).name("Start").done().endNode(3).name("End").done().actionNode(2).name("printTextActionNode").action("java", "System.out.println(\"test print\");", true).done().connection(1, 2).connection(2, 3);
    RuleFlowProcess process = factory.validate().getProcess();
    assertNotNull(process);
    Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
    res.setSourcePath("/tmp/processFactory.bpmn2");
    KieBase kbase = createKnowledgeBaseFromResources(res);
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ProcessInstance pi = ksession.startProcess("org.jbpm.process");
    assertNotNull(pi);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi.getState());
    ksession.dispose();
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Resource(org.kie.api.io.Resource) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) Test(org.junit.Test)

Example 9 with RuleFlowProcessFactory

use of org.jbpm.ruleflow.core.RuleFlowProcessFactory in project jbpm by kiegroup.

the class DynamicProcessTest method testDynamicProcess.

@Test
public void testDynamicProcess() throws Exception {
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.HelloWorld");
    factory.name("HelloWorldProcess").version("1.0").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task1").actorId("krisv").taskName("MyTask").done().endNode(3).name("End").done().connection(1, 2).connection(2, 3);
    final RuleFlowProcess process = factory.validate().getProcess();
    Resource resource = ResourceFactory.newByteArrayResource(XmlRuleFlowProcessDumper.INSTANCE.dump(process).getBytes());
    // source path or target path must be set to be added into kbase
    resource.setSourcePath("/tmp/dynamicProcess.bpmn2");
    KieBase kbase = createKnowledgeBaseFromResources(resource);
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler testHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
    ksession.addEventListener(new ProcessEventListener() {

        public void beforeVariableChanged(ProcessVariableChangedEvent arg0) {
        }

        public void beforeProcessStarted(ProcessStartedEvent arg0) {
            logger.info("{}", arg0);
        }

        public void beforeProcessCompleted(ProcessCompletedEvent arg0) {
            logger.info("{}", arg0);
        }

        public void beforeNodeTriggered(ProcessNodeTriggeredEvent arg0) {
            logger.info("{}", arg0);
        }

        public void beforeNodeLeft(ProcessNodeLeftEvent arg0) {
            logger.info("{}", arg0);
        }

        public void afterVariableChanged(ProcessVariableChangedEvent arg0) {
        }

        public void afterProcessStarted(ProcessStartedEvent arg0) {
        }

        public void afterProcessCompleted(ProcessCompletedEvent arg0) {
        }

        public void afterNodeTriggered(ProcessNodeTriggeredEvent arg0) {
        }

        public void afterNodeLeft(ProcessNodeLeftEvent arg0) {
        }
    });
    final ProcessInstanceImpl processInstance = (ProcessInstanceImpl) ksession.startProcess("org.jbpm.HelloWorld");
    HumanTaskNode node = new HumanTaskNode();
    node.setName("Task2");
    node.setId(4);
    insertNodeInBetween(process, 2, 3, node);
    ((CommandBasedStatefulKnowledgeSession) ksession).getRunner().execute(new ExecutableCommand<Void>() {

        public Void execute(Context context) {
            StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
            ((ProcessInstanceImpl) ksession.getProcessInstance(processInstance.getId())).updateProcess(process);
            return null;
        }
    });
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
    assertProcessInstanceActive(processInstance);
    ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
    ksession.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) RegistryContext(org.drools.core.command.impl.RegistryContext) Context(org.kie.api.runtime.Context) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) Resource(org.kie.api.io.Resource) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) KieBase(org.kie.api.KieBase) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) Test(org.junit.Test)

Aggregations

RuleFlowProcessFactory (org.jbpm.ruleflow.core.RuleFlowProcessFactory)9 Test (org.junit.Test)9 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)8 KieBase (org.kie.api.KieBase)7 Resource (org.kie.api.io.Resource)7 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)7 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)5 TestWorkItemHandler (org.jbpm.persistence.session.objects.TestWorkItemHandler)3 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)2 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)1 RegistryContext (org.drools.core.command.impl.RegistryContext)1 ProcessInstanceImpl (org.jbpm.process.instance.impl.ProcessInstanceImpl)1 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)1 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)1 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)1 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)1 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)1 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)1 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)1 ProcessVariableChangedEvent (org.kie.api.event.process.ProcessVariableChangedEvent)1