Search in sources :

Example 1 with AfterRuleAddedEvent

use of org.kie.api.event.kiebase.AfterRuleAddedEvent in project jbpm by kiegroup.

the class BusinessRuleTaskHandlerTest method testDrlStatefulBusinessRuleTaskWithScanner.

@Ignore("ignored as it is unstable on jenkins for unknown reason")
@Test
public void testDrlStatefulBusinessRuleTaskWithScanner() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    BusinessRuleTaskHandler handler = new BusinessRuleTaskHandler(GROUP_ID, ARTIFACT_ID, VERSION, 2000);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setId(999);
    Person person = new Person("john");
    workItem.setParameter("person", person);
    workItem.setParameter("KieSessionType", BusinessRuleTaskHandler.STATEFULL_TYPE);
    handler.executeWorkItem(workItem, manager);
    Map<String, Object> results = manager.getResults(workItem.getId());
    assertNotNull(results);
    assertEquals(1, results.size());
    assertEquals(35, ((Person) results.get("person")).getAge().intValue());
    // build and deploy new version
    createAndDeployJar(ks, ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION), ks.getResources().newClassPathResource("businessRule2.drl"));
    // setup waiting mechanism to wait for scanner update
    CountDownLatch latch = new CountDownLatch(1);
    handler.getKieContainer().getKieBase().addEventListener(new DefaultKieBaseEventListener() {

        @Override
        public void afterRuleAdded(AfterRuleAddedEvent event) {
            latch.countDown();
        }
    });
    latch.await(10, TimeUnit.SECONDS);
    person = new Person("john");
    workItem.setParameter("person", person);
    workItem.setParameter("KieSessionType", BusinessRuleTaskHandler.STATEFULL_TYPE);
    handler.executeWorkItem(workItem, manager);
    results = manager.getResults(workItem.getId());
    assertNotNull(results);
    assertEquals(1, results.size());
    assertEquals(45, ((Person) results.get("person")).getAge().intValue());
}
Also used : DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) AfterRuleAddedEvent(org.kie.api.event.kiebase.AfterRuleAddedEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Person(org.jbpm.process.workitem.bpmn2.objects.Person) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with AfterRuleAddedEvent

use of org.kie.api.event.kiebase.AfterRuleAddedEvent in project drools by kiegroup.

the class KieBaseEventSupport method fireAfterRuleAdded.

public void fireAfterRuleAdded(final RuleImpl rule) {
    if (hasListeners()) {
        AfterRuleAddedEvent event = new AfterRuleAddedEventImpl(this.kBase, rule);
        notifyAllListeners(event, (l, e) -> l.afterRuleAdded(e));
    }
}
Also used : AfterRuleAddedEvent(org.kie.api.event.kiebase.AfterRuleAddedEvent) AfterRuleAddedEventImpl(org.drools.core.event.knowlegebase.impl.AfterRuleAddedEventImpl)

Aggregations

AfterRuleAddedEvent (org.kie.api.event.kiebase.AfterRuleAddedEvent)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 AfterRuleAddedEventImpl (org.drools.core.event.knowlegebase.impl.AfterRuleAddedEventImpl)1 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)1 Person (org.jbpm.process.workitem.bpmn2.objects.Person)1 TestWorkItemManager (org.jbpm.process.workitem.core.TestWorkItemManager)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 DefaultKieBaseEventListener (org.kie.api.event.kiebase.DefaultKieBaseEventListener)1