use of org.kie.api.KieBase in project drools by kiegroup.
the class PatternTest method testParentheses.
@Test
public void testParentheses() throws Exception {
final KieBase kbase = loadKnowledgeBase("test_ParenthesisUsage.drl");
final List<Person> results = new ArrayList<>();
final KieSession session = createKnowledgeSession(kbase);
session.setGlobal("results", results);
final Person bob = new Person("Bob", 20);
bob.setAlive(true);
final Person foo = new Person("Foo", 0);
foo.setAlive(false);
session.insert(bob);
session.fireAllRules();
assertEquals(1, results.size());
assertEquals(bob, results.get(0));
session.insert(foo);
session.fireAllRules();
assertEquals(2, results.size());
assertEquals(foo, results.get(1));
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class RemoveRuleTest method testRuleRemovalWithJoinedRootPattern.
@Test
public void testRuleRemovalWithJoinedRootPattern() {
String str = "";
str += "package org.drools.compiler \n";
str += "rule rule1 \n";
str += "when \n";
str += " String() \n";
str += " Person() \n";
str += "then \n";
str += "end \n";
str += "rule rule2 \n";
str += "when \n";
str += " String() \n";
str += " Cheese() \n";
str += "then \n";
str += "end \n";
final KieBase kbase = loadKnowledgeBaseFromString(str);
final KieSession ksession = createKnowledgeSession(kbase);
final DefaultFactHandle handle = (DefaultFactHandle) ksession.insert("hello");
ksession.fireAllRules();
LeftTuple leftTuple = handle.getFirstLeftTuple();
assertNotNull(leftTuple);
assertNotNull(leftTuple.getPeer());
kbase.removeRule("org.drools.compiler", "rule2");
leftTuple = handle.getFirstLeftTuple();
assertNotNull(leftTuple);
assertNull(leftTuple.getHandleNext());
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class MarshallingIssuesTest method testJBRULES_1946_2.
@Test
public void testJBRULES_1946_2() {
KieBase kbase = loadKnowledgeBase("../Sample.drl");
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DroolsObjectOutputStream oos = new DroolsObjectOutputStream(baos);
oos.writeObject(kbase);
oos.flush();
oos.close();
baos.flush();
baos.close();
byte[] serializedKb = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(serializedKb);
DroolsObjectInputStream ois = new DroolsObjectInputStream(bais);
KieBase kb2 = (KieBase) ois.readObject();
} catch (OptionalDataException ode) {
ode.printStackTrace();
fail("EOF? " + ode.eof);
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception: " + e.getMessage());
}
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class MarshallingIssuesTest method testJBRULES_1946_3.
@Test
public void testJBRULES_1946_3() {
KieBase kbase = loadKnowledgeBase("../Sample.drl");
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DroolsObjectOutputStream oos = new DroolsObjectOutputStream(baos);
oos.writeObject(kbase);
oos.flush();
oos.close();
baos.flush();
baos.close();
byte[] serializedKb = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(serializedKb);
ObjectInputStream ois = new ObjectInputStream(bais);
KieBase kb2 = (KieBase) ois.readObject();
fail("Should have raised an IllegalArgumentException since the kbase was serialized with a Drools Stream but deserialized with a regular stream");
} catch (IllegalArgumentException ode) {
// success
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception: " + e.getMessage());
}
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class MarshallingIssuesTest method testJBRULES_1946.
@Test
public void testJBRULES_1946() {
KieBase kbase = loadKnowledgeBase("../Sample.drl");
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(kbase);
oos.flush();
oos.close();
baos.flush();
baos.close();
byte[] serializedKb = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(serializedKb);
ObjectInputStream ois = new ObjectInputStream(bais);
KieBase kb2 = (KieBase) ois.readObject();
} catch (OptionalDataException ode) {
ode.printStackTrace();
fail("EOF? " + ode.eof);
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception: " + e.getMessage());
}
}
Aggregations