Search in sources :

Example 16 with MatchCancelledEvent

use of org.kie.api.event.rule.MatchCancelledEvent in project jbpm by kiegroup.

the class ActivityTest method testRuleTaskWithFacts.

@Test
@RequirePersistence(false)
public void testRuleTaskWithFacts() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-RuleTaskWithFact.bpmn2", "BPMN2-RuleTask3.drl");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(new AgendaEventListener() {

        public void matchCreated(MatchCreatedEvent event) {
        }

        public void matchCancelled(MatchCancelledEvent event) {
        }

        public void beforeRuleFlowGroupDeactivated(org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent event) {
        }

        public void beforeRuleFlowGroupActivated(org.kie.api.event.rule.RuleFlowGroupActivatedEvent event) {
        }

        public void beforeMatchFired(BeforeMatchFiredEvent event) {
        }

        public void agendaGroupPushed(org.kie.api.event.rule.AgendaGroupPushedEvent event) {
        }

        public void agendaGroupPopped(org.kie.api.event.rule.AgendaGroupPoppedEvent event) {
        }

        public void afterRuleFlowGroupDeactivated(org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent event) {
        }

        public void afterRuleFlowGroupActivated(org.kie.api.event.rule.RuleFlowGroupActivatedEvent event) {
            ksession.fireAllRules();
        }

        public void afterMatchFired(AfterMatchFiredEvent event) {
        }
    });
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "SomeString");
    ProcessInstance processInstance = ksession.startProcess("RuleTask", params);
    assertProcessInstanceFinished(processInstance, ksession);
    params = new HashMap<String, Object>();
    try {
        processInstance = ksession.startProcess("RuleTask", params);
        fail("Should fail");
    } catch (Exception e) {
        e.printStackTrace();
    }
    params = new HashMap<String, Object>();
    params.put("x", "SomeString");
    processInstance = ksession.startProcess("RuleTask", params);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : HashMap(java.util.HashMap) AfterMatchFiredEvent(org.kie.api.event.rule.AfterMatchFiredEvent) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) KieBase(org.kie.api.KieBase) MatchCancelledEvent(org.kie.api.event.rule.MatchCancelledEvent) DebugAgendaEventListener(org.kie.api.event.rule.DebugAgendaEventListener) AgendaEventListener(org.kie.api.event.rule.AgendaEventListener) BeforeMatchFiredEvent(org.kie.api.event.rule.BeforeMatchFiredEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) MatchCreatedEvent(org.kie.api.event.rule.MatchCreatedEvent) Test(org.junit.Test) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Aggregations

Test (org.junit.Test)16 MatchCancelledEvent (org.kie.api.event.rule.MatchCancelledEvent)16 MatchCreatedEvent (org.kie.api.event.rule.MatchCreatedEvent)15 ArrayList (java.util.ArrayList)13 KieBase (org.kie.api.KieBase)13 KieSession (org.kie.api.runtime.KieSession)13 List (java.util.List)11 AfterMatchFiredEvent (org.kie.api.event.rule.AfterMatchFiredEvent)10 AgendaEventListener (org.kie.api.event.rule.AgendaEventListener)10 DefaultAgendaEventListener (org.kie.api.event.rule.DefaultAgendaEventListener)8 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)8 BeforeMatchFiredEvent (org.kie.api.event.rule.BeforeMatchFiredEvent)6 FactHandle (org.kie.api.runtime.rule.FactHandle)6 AgendaGroupPoppedEvent (org.kie.api.event.rule.AgendaGroupPoppedEvent)5 AgendaGroupPushedEvent (org.kie.api.event.rule.AgendaGroupPushedEvent)5 RuleFlowGroupActivatedEvent (org.kie.api.event.rule.RuleFlowGroupActivatedEvent)5 RuleFlowGroupDeactivatedEvent (org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent)5 Arrays.asList (java.util.Arrays.asList)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InternalAgenda (org.drools.core.common.InternalAgenda)2