use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class UpdateTest method doModifyTest.
private void doModifyTest(final String drlResource) throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, drlResource);
KieSession ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("results", list);
final Person bob = new Person("Bob");
bob.setStatus("hungry");
final Cheese c = new Cheese();
ksession.insert(bob);
ksession.insert(c);
ksession.fireAllRules();
assertEquals(10, c.getPrice());
assertEquals("fine", bob.getStatus());
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class UpdateTest method noDormantCheckOnModifies.
@Test
public void noDormantCheckOnModifies() throws Exception {
// Test case for BZ 862325
final String str = "package org.drools.mvel.compiler;\n" + " rule R1\n" + " salience 10\n" + " when\n" + " $c : Cheese( price == 10 ) \n" + " $p : Person( ) \n" + " then \n" + " modify($c) { setPrice( 5 ) }\n" + " modify($p) { setAge( 20 ) }\n" + "end\n" + "rule R2\n" + " when\n" + " $p : Person( )" + " then \n" + " // noop\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
final org.kie.api.event.rule.AgendaEventListener ael = mock(org.kie.api.event.rule.AgendaEventListener.class);
ksession.addEventListener(ael);
ksession.insert(new Person("Bob", 19));
ksession.insert(new Cheese("brie", 10));
ksession.fireAllRules();
// both rules should fire exactly once
verify(ael, times(2)).afterMatchFired(any(org.kie.api.event.rule.AfterMatchFiredEvent.class));
// no cancellations should have happened
verify(ael, never()).matchCancelled(any(org.kie.api.event.rule.MatchCancelledEvent.class));
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class UpdateTest method testInvalidModify2.
@Test
public void testInvalidModify2() throws Exception {
String str = "";
str += "package org.drools.compiler \n";
str += "import " + Cheese.class.getName() + "\n";
str += "global java.util.List list \n";
str += "rule rule1 \n";
str += " no-loop \n";
str += "when \n";
str += " $i : Cheese() \n";
str += "then \n";
str += " modify( $i ) { setType( \"stilton\" ); setType( \"stilton\" );}; ";
str += " list.add( $i ); \n";
str += "end \n";
KieBuilder kieBuilder = KieUtil.getKieBuilderFromDrls(kieBaseTestConfiguration, false, str);
List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
assertFalse("Should have an error", errors.isEmpty());
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class RuleRuntimeEventTest method testEventModel.
@Test
public void testEventModel() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_EventModel.drl");
KieSession wm = kbase.newKieSession();
final RuleRuntimeEventListener wmel = mock(RuleRuntimeEventListener.class);
wm.addEventListener(wmel);
final Cheese stilton = new Cheese("stilton", 15);
final FactHandle stiltonHandle = wm.insert(stilton);
final ArgumentCaptor<ObjectInsertedEvent> oic = ArgumentCaptor.forClass(org.kie.api.event.rule.ObjectInsertedEvent.class);
verify(wmel).objectInserted(oic.capture());
assertSame(stiltonHandle, oic.getValue().getFactHandle());
wm.update(stiltonHandle, stilton);
final ArgumentCaptor<org.kie.api.event.rule.ObjectUpdatedEvent> ouc = ArgumentCaptor.forClass(org.kie.api.event.rule.ObjectUpdatedEvent.class);
verify(wmel).objectUpdated(ouc.capture());
assertSame(stiltonHandle, ouc.getValue().getFactHandle());
wm.delete(stiltonHandle);
final ArgumentCaptor<ObjectDeletedEvent> orc = ArgumentCaptor.forClass(ObjectDeletedEvent.class);
verify(wmel).objectDeleted(orc.capture());
assertSame(stiltonHandle, orc.getValue().getFactHandle());
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class StatefulSessionTest method testGetFactHandleIdentityBehavior.
@Test
public void testGetFactHandleIdentityBehavior() throws Exception {
KieBaseTestConfiguration identityConfig = TestParametersUtil.getIdentityInstanceOf(kieBaseTestConfiguration);
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", identityConfig);
KieSession ksession = kbase.newKieSession();
final CheeseEqual cheese = new CheeseEqual("stilton", 10);
ksession.insert(cheese);
final FactHandle fh1 = ksession.getFactHandle(new Cheese("stilton", 10));
assertNull(fh1);
final FactHandle fh2 = ksession.getFactHandle(cheese);
assertNotNull(fh2);
}
Aggregations