use of org.kie.api.KieBase in project drools by kiegroup.
the class DeclareTest method testDeclareAndFrom.
@Test
public void testDeclareAndFrom() throws Exception {
final KieBase kbase = loadKnowledgeBase("test_DeclareWithFrom.drl");
final FactType profileType = kbase.getFactType("org.drools.compiler", "Profile");
final KieSession ksession = createKnowledgeSession(kbase);
final Object profile = profileType.newInstance();
final Map<String, Integer> map = new HashMap<String, Integer>();
map.put("internet", Integer.valueOf(2));
profileType.set(profile, "pageFreq", map);
ksession.insert(profile);
ksession.fireAllRules();
ksession.dispose();
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class DeclareTest method testDeclaredTypesDefaultHashCode.
@Test
public void testDeclaredTypesDefaultHashCode() {
// JBRULES-3481
final String str = "package com.sample\n" + "\n" + "global java.util.List list; \n" + "" + "declare Bean\n" + " id : int \n" + "end\n" + "\n" + "declare KeyedBean\n" + " id : int @key \n" + "end\n" + "\n" + "\n" + "rule Create\n" + "when\n" + "then\n" + " list.add( new Bean(1) ); \n" + " list.add( new Bean(2) ); \n" + " list.add( new KeyedBean(1) ); \n" + " list.add( new KeyedBean(1) ); \n" + "end\n";
final KieBase kbase = loadKnowledgeBaseFromString(str);
final KieSession ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
ksession.fireAllRules();
ksession.dispose();
assertFalse(list.get(0).hashCode() == 34);
assertFalse(list.get(1).hashCode() == 34);
assertFalse(list.get(0).hashCode() == list.get(1).hashCode());
assertNotSame(list.get(0), list.get(1));
assertFalse(list.get(0).equals(list.get(1)));
assertTrue(list.get(2).hashCode() == 32);
assertTrue(list.get(3).hashCode() == 32);
assertNotSame(list.get(2), list.get(3));
assertTrue(list.get(2).equals(list.get(3)));
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class LiteralTest method testLiteral.
@Test
public void testLiteral() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("literal_rule_test.drl"));
KieSession session = createKnowledgeSession(kbase);
final List list = new ArrayList();
session.setGlobal("list", list);
final Cheese stilton = new Cheese("stilton", 5);
session.insert(stilton);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
session.fireAllRules();
assertEquals("stilton", ((List) session.getGlobal("list")).get(0));
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class LiteralTest method testLiteralWithEscapes.
@Test
public void testLiteralWithEscapes() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_literal_with_escapes.drl"));
KieSession session = createKnowledgeSession(kbase);
final List list = new ArrayList();
session.setGlobal("list", list);
final String expected = "s\tti\"lto\nn";
final Cheese stilton = new Cheese(expected, 5);
session.insert(stilton);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
final int fired = session.fireAllRules();
assertEquals(1, fired);
assertEquals(expected, ((List) session.getGlobal("list")).get(0));
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class LiteralTest method testBigDecimalIntegerLiteral.
@Test
public void testBigDecimalIntegerLiteral() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("big_decimal_and_literal.drl"));
KieSession session = createKnowledgeSession(kbase);
final List list = new ArrayList();
session.setGlobal("list", list);
final PersonInterface bill = new Person("bill", null, 12);
bill.setBigDecimal(new BigDecimal("42"));
bill.setBigInteger(new BigInteger("42"));
session.insert(bill);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
session.fireAllRules();
assertEquals(6, ((List) session.getGlobal("list")).size());
}
Aggregations