use of org.kie.api.KieBase in project drools by kiegroup.
the class ExceptionTest method testReturnValueException.
@Test
public void testReturnValueException() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_ReturnValueException.drl"));
final KieSession ksession = kbase.newKieSession();
final Cheese brie = new Cheese("brie", 12);
try {
ksession.insert(brie);
ksession.fireAllRules();
fail("Should throw an Exception from the ReturnValue");
} catch (final Exception e) {
Throwable root = e;
while (root.getCause() != null) {
root = root.getCause();
}
root.getMessage().contains("this should throw an exception");
}
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class ImportsTest method testImportFunctions.
@Test
public void testImportFunctions() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_ImportFunctions.drl"));
KieSession session = createKnowledgeSession(kbase);
final Cheese cheese = new Cheese("stilton", 15);
session.insert(cheese);
List list = new ArrayList();
session.setGlobal("list", list);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
final int fired = session.fireAllRules();
list = (List) session.getGlobal("list");
assertEquals(4, fired);
assertEquals(4, list.size());
assertEquals("rule1", list.get(0));
assertEquals("rule2", list.get(1));
assertEquals("rule3", list.get(2));
assertEquals("rule4", list.get(3));
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class ImportsTest method testImportConflict.
@Test
public void testImportConflict() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_ImportConflict.drl"));
createKnowledgeSession(kbase);
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class NestingTest method testNestedConditionalElements.
@Test
public void testNestedConditionalElements() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_NestedConditionalElements.drl"));
final KieSession ksession = createKnowledgeSession(kbase);
final List list = new ArrayList();
ksession.setGlobal("results", list);
final State state = new State("SP");
ksession.insert(state);
final Person bob = new Person("Bob");
bob.setStatus(state.getState());
bob.setLikes("stilton");
ksession.insert(bob);
ksession.fireAllRules();
assertEquals(0, list.size());
ksession.insert(new Cheese(bob.getLikes(), 10));
ksession.fireAllRules();
assertEquals(1, list.size());
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class NestingTest method testNesting.
@Test
public void testNesting() throws Exception {
final Person p = new Person();
p.setName("Michael");
final Address add1 = new Address();
add1.setStreet("High");
final Address add2 = new Address();
add2.setStreet("Low");
final List l = new ArrayList();
l.add(add1);
l.add(add2);
p.setAddresses(l);
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
final PackageDescr desc = parser.parse(new InputStreamReader(getClass().getResourceAsStream("nested_fields.drl")));
final List packageAttrs = desc.getAttributes();
assertEquals(1, desc.getRules().size());
assertEquals(1, packageAttrs.size());
final RuleDescr rule = desc.getRules().get(0);
final Map<String, AttributeDescr> ruleAttrs = rule.getAttributes();
assertEquals(1, ruleAttrs.size());
assertEquals("mvel", ruleAttrs.get("dialect").getValue());
assertEquals("dialect", ruleAttrs.get("dialect").getName());
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase(desc));
KieSession session = createKnowledgeSession(kbase);
session.insert(p);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
session.fireAllRules();
}
Aggregations