Search in sources :

Example 1 with RuleAwareProcessEventLister

use of org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister in project jbpm by kiegroup.

the class IntermediateEventTest method testIntermediateCatchEventConditionSetVariableAfter.

@Test
public void testIntermediateCatchEventConditionSetVariableAfter() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventConditionSetVariableAfter.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(new RuleAwareProcessEventLister());
    ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    ksession.addEventListener(new RuleAwareProcessEventLister());
    Collection<? extends Object> processInstances = ksession.getObjects(new ObjectFilter() {

        @Override
        public boolean accept(Object object) {
            if (object instanceof ProcessInstance) {
                return true;
            }
            return false;
        }
    });
    assertThat(processInstances).isNotNull();
    assertThat(processInstances.size()).isEqualTo(1);
    // now activate condition
    Person person = new Person();
    person.setName("Jack");
    ksession.insert(person);
    assertProcessInstanceFinished(processInstance, ksession);
    processInstances = ksession.getObjects(new ObjectFilter() {

        @Override
        public boolean accept(Object object) {
            if (object instanceof ProcessInstance) {
                return true;
            }
            return false;
        }
    });
    assertThat(processInstances).isNotNull();
    assertThat(processInstances.size()).isEqualTo(0);
}
Also used : KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ObjectFilter(org.kie.api.runtime.ObjectFilter) Person(org.jbpm.bpmn2.objects.Person) RuleAwareProcessEventLister(org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister) Test(org.junit.Test)

Example 2 with RuleAwareProcessEventLister

use of org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister in project jbpm by kiegroup.

the class ErrorEventTest method testMultiErrorBoundaryEventsOnBusinessRuleTask.

@Test
public void testMultiErrorBoundaryEventsOnBusinessRuleTask() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-MultiErrorBoundaryEventsOnBusinessRuleTask.bpmn2", "BPMN2-MultiErrorBoundaryEventsOnBusinessRuleTask.drl");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(new RuleAwareProcessEventLister());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("person", new Person());
    ProcessInstance processInstance = ksession.startProcess("BPMN2-MultiErrorBoundaryEventeOnBusinessRuleTask", params);
    assertProcessInstanceFinished(processInstance, ksession);
    assertNodeTriggered(processInstance.getId(), "start", "business rule task error attached", "NPE Script Task", "error1");
    ksession.dispose();
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(new RuleAwareProcessEventLister());
    params = new HashMap<String, Object>();
    params.put("person", new Person("unsupported"));
    ProcessInstance processInstance2 = ksession.startProcess("BPMN2-MultiErrorBoundaryEventeOnBusinessRuleTask", params);
    assertProcessInstanceFinished(processInstance2, ksession);
    assertNodeTriggered(processInstance2.getId(), "start", "business rule task error attached", "UOE Script Task", "error2");
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Person(org.jbpm.bpmn2.objects.Person) RuleAwareProcessEventLister(org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister) Test(org.junit.Test)

Example 3 with RuleAwareProcessEventLister

use of org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister in project jbpm by kiegroup.

the class ActivityTest method testBusinessRuleTaskDynamic.

@Test
public void testBusinessRuleTaskDynamic() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-BusinessRuleTaskDynamic.bpmn2", "BPMN2-BusinessRuleTask.drl");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(new RuleAwareProcessEventLister());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("dynamicrule", "MyRuleFlow");
    ProcessInstance processInstance = ksession.startProcess("BPMN2-BusinessRuleTask", params);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) RuleAwareProcessEventLister(org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister) Test(org.junit.Test)

Example 4 with RuleAwareProcessEventLister

use of org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister in project jbpm by kiegroup.

the class SingletonRuntimeManagerTest method testBusinessRuleTaskWithRuleAwareListener.

@Test
public void testBusinessRuleTaskWithRuleAwareListener() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().addAsset(ResourceFactory.newClassPathResource("BPMN2-BusinessRuleTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-BusinessRuleTask.drl"), ResourceType.DRL).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    long sessionId = ksession.getIdentifier();
    assertTrue(sessionId == 1);
    runtime = manager.getRuntimeEngine(EmptyContext.get());
    ksession = runtime.getKieSession();
    assertEquals(sessionId, ksession.getIdentifier());
    // start process
    ksession.addEventListener(new RuleAwareProcessEventLister());
    ProcessInstance pi = ksession.startProcess("BPMN2-BusinessRuleTask");
    assertNull(ksession.getProcessInstance(pi.getId()));
    AuditService logService = runtime.getAuditService();
    List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("BPMN2-BusinessRuleTask");
    assertNotNull(logs);
    assertEquals(0, logs.size());
    logs = logService.findProcessInstances("BPMN2-BusinessRuleTask");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    // dispose session that should not have affect on the session at all
    manager.disposeRuntimeEngine(runtime);
    // close manager which will close session maintained by the manager
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) RuleAwareProcessEventLister(org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 5 with RuleAwareProcessEventLister

use of org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister in project jbpm by kiegroup.

the class ErrorEventTest method testErrorBoundaryEventOnBusinessRuleTask.

@Test
public void testErrorBoundaryEventOnBusinessRuleTask() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-ErrorBoundaryEventOnBusinessRuleTask.bpmn2", "BPMN2-ErrorBoundaryEventOnBusinessRuleTask.drl");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(new RuleAwareProcessEventLister());
    ProcessInstance processInstance = ksession.startProcess("BPMN2-ErrorBoundaryEventOnBusinessRuleTask");
    assertProcessInstanceFinished(processInstance, ksession);
    assertNodeTriggered(processInstance.getId(), "start", "business rule task error attached", "error1");
}
Also used : KieBase(org.kie.api.KieBase) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) RuleAwareProcessEventLister(org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister) Test(org.junit.Test)

Aggregations

RuleAwareProcessEventLister (org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister)8 Test (org.junit.Test)8 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)8 KieBase (org.kie.api.KieBase)7 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)5 Person (org.jbpm.bpmn2.objects.Person)3 HashMap (java.util.HashMap)2 RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)2 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)2 ObjectFilter (org.kie.api.runtime.ObjectFilter)2 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)1 KieSession (org.kie.api.runtime.KieSession)1 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)1 AuditService (org.kie.api.runtime.manager.audit.AuditService)1