Search in sources :

Example 76 with SystemOutWorkItemHandler

use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.

the class ActivityTest method testCallActivityWithBoundaryErrorEvent.

@Test
public void testCallActivityWithBoundaryErrorEvent() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-CallActivityProcessBoundaryError.bpmn2", "BPMN2-CallActivitySubProcessBoundaryError.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("task1", new SystemOutWorkItemHandler());
    ProcessInstance processInstance = ksession.startProcess("ParentProcess");
    assertProcessInstanceFinished(processInstance, ksession);
    assertNodeTriggered(processInstance.getId(), "StartProcess", "Call Activity 1", "Boundary event", "Task Parent", "End2");
    // then check child process executed nodes - is there better way to get child process id than simply increment?
    assertNodeTriggered(processInstance.getId() + 1, "StartProcess", "Task 1", "End");
}
Also used : KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 77 with SystemOutWorkItemHandler

use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.

the class StandaloneBPMNProcessTest method testEventBasedSplit5.

@Test
public void testEventBasedSplit5() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EventBasedSplit5.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    ReceiveTaskHandler receiveTaskHandler = new ReceiveTaskHandler(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler);
    // Yes
    ProcessInstance processInstance = ksession.startProcess("com.sample.test");
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    receiveTaskHandler.setKnowledgeRuntime(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler);
    receiveTaskHandler.messageReceived("YesMessage", "YesValue");
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    receiveTaskHandler.messageReceived("NoMessage", "NoValue");
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    receiveTaskHandler.setKnowledgeRuntime(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler);
    // No
    processInstance = ksession.startProcess("com.sample.test");
    receiveTaskHandler.messageReceived("NoMessage", "NoValue");
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    receiveTaskHandler.messageReceived("YesMessage", "YesValue");
}
Also used : KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ReceiveTaskHandler(org.jbpm.bpmn2.handler.ReceiveTaskHandler) Test(org.junit.Test)

Example 78 with SystemOutWorkItemHandler

use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.

the class StandaloneBPMNProcessTest method testEvaluationProcess2.

@Test
public void testEvaluationProcess2() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EvaluationProcess2.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("employee", "UserId-12345");
    ProcessInstance processInstance = ksession.startProcess("com.sample.evaluation", params);
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 79 with SystemOutWorkItemHandler

use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.

the class BPMN2DataServicesReferencesTest method testGlobal.

@Test
public void testGlobal() throws IOException {
    Assume.assumeTrue("Skip import/global tests", loadGlobalImportProcesses);
    String processId = PROC_ID_GLOBAL;
    ProcessDefinition procDef = bpmn2Service.getProcessDefinition(deploymentId, processId);
    assertNotNull(procDef);
    // check that process runs
    Person person = new Person();
    person.setName("Max Rockatansky");
    person.setId(1979l);
    person.setTime(3l);
    KieSession ksession = deploymentService.getRuntimeManager(deploymentId).getRuntimeEngine(null).getKieSession();
    ksession.setGlobal("person", person);
    ksession.getWorkItemManager().registerWorkItemHandler("MyTask", new SystemOutWorkItemHandler());
    Long procId = startProcess(deploymentId, processId);
    ProcessInstance procInst = processService.getProcessInstance(procId);
    assertNull(procInst);
    String log = person.getLog();
    assertFalse("Empty log", log == null || log.trim().isEmpty());
    assertEquals("Empty log", log.split(":").length, 4);
    // verify process information
    Collection<String> refClasses = bpmn2Service.getJavaClasses(deploymentId, processId);
    assertNotNull("Null set of referenced classes", refClasses);
    assertFalse("Empty set of referenced classes", refClasses.isEmpty());
    assertEquals("Number referenced classes", 1, refClasses.size());
    assertEquals("Imported class in process", refClasses.iterator().next(), Person.class.getName());
}
Also used : SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Person(org.jbpm.kie.test.objects.Person) OtherPerson(org.jbpm.kie.test.objects.OtherPerson) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 80 with SystemOutWorkItemHandler

use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.

the class PersistentStatefulSessionTest method testIntegrationWithEventManager3.

@Test
public void testIntegrationWithEventManager3() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(new ClassPathResource("WorkItemsProcess.rf"), ResourceType.DRF);
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
    ksession.getWorkItemManager().registerWorkItemHandler("MyWork", new SystemOutWorkItemHandler());
    ProcessInstance processInstance = ksession.startProcess("org.drools.test.TestProcess");
    ksession.insert("TestString");
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    List<InstanceView<?>> events = TestEventEmitter.getEvents();
    assertNotNull(events);
    assertEquals(1, events.size());
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ClassPathResource(org.drools.core.io.impl.ClassPathResource) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) InstanceView(org.jbpm.persistence.api.integration.InstanceView) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)87 Test (org.junit.Test)77 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)75 KieBase (org.kie.api.KieBase)59 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)45 HashMap (java.util.HashMap)39 KieSession (org.kie.api.runtime.KieSession)38 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)16 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)15 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)14 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)14 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)14 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)14 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener)13 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)13 ArrayList (java.util.ArrayList)10 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)6 Document (org.w3c.dom.Document)5 Map (java.util.Map)4 PersistenceUtil.createEnvironment (org.jbpm.persistence.util.PersistenceUtil.createEnvironment)4