use of org.drools.compiler.Cheese in project drools by kiegroup.
the class SequentialTest method testBasicOperation.
@Test
public void testBasicOperation() throws Exception {
KieBase kbase = loadKnowledgeBase(kconf, "simpleSequential.drl");
StatelessKieSession ksession = createStatelessKnowledgeSession(kbase);
final List list = new ArrayList();
ksession.setGlobal("list", list);
final Person p1 = new Person("p1", "stilton");
final Person p2 = new Person("p2", "cheddar");
final Person p3 = new Person("p3", "stilton");
final Cheese stilton = new Cheese("stilton", 15);
final Cheese cheddar = new Cheese("cheddar", 15);
ksession.execute(CommandFactory.newInsertElements(Arrays.asList(new Object[] { p1, stilton, p2, cheddar, p3 })));
assertEquals(3, list.size());
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class LocaleTest method testLatinLocale.
@Test
public void testLatinLocale() throws Exception {
final Locale defaultLoc = Locale.getDefault();
try {
// setting a locale that uses COMMA as decimal separator
Locale.setDefault(new Locale("pt", "BR"));
final KieBase kbase = loadKnowledgeBase("test_LatinLocale.drl");
final KieSession ksession = createKnowledgeSession(kbase);
final List<String> results = new ArrayList<String>();
ksession.setGlobal("results", results);
final Cheese mycheese = new Cheese("cheddar", 4);
final FactHandle handle = ksession.insert(mycheese);
ksession.fireAllRules();
assertEquals(1, results.size());
assertEquals("1", results.get(0));
mycheese.setPrice(8);
mycheese.setDoublePrice(8.50);
ksession.update(handle, mycheese);
ksession.fireAllRules();
assertEquals(2, results.size());
assertEquals("3", results.get(1));
} finally {
Locale.setDefault(defaultLoc);
}
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class RuleRuntimeEventTest method testEventModel.
@Test
public void testEventModel() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_EventModel.drl"));
final KieSession wm = createKnowledgeSession(kbase);
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.compiler.Cheese in project drools by kiegroup.
the class StatefulSessionTest method testIterateObjects.
@Test
public void testIterateObjects() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_IterateObjects.drl"));
final KieSession ksession = createKnowledgeSession(kbase);
final List results = new ArrayList();
ksession.setGlobal("results", results);
ksession.insert(new Cheese("stilton", 10));
ksession.fireAllRules();
final Iterator events = ksession.getObjects(new ClassObjectFilter(PersonInterface.class)).iterator();
assertTrue(events.hasNext());
assertEquals(1, results.size());
assertEquals(results.get(0), events.next());
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class StatelessSessionTest method testCollectionObjectAssert.
@Test
public void testCollectionObjectAssert() throws Exception {
final StatelessKieSession session = getSession2("statelessSessionTest.drl");
final Cheese stilton = new Cheese("stilton", 5);
final List collection = new ArrayList();
collection.add(stilton);
session.execute(collection);
assertEquals("stilton", list.get(0));
}
Aggregations