use of org.drools.compiler.State 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.drools.compiler.State in project drools by kiegroup.
the class PropertyReactivityTest method testPropertyChangeSupportNewAPI.
@Test
public void testPropertyChangeSupportNewAPI() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_PropertyChangeTypeDecl.drl"));
final KieSession session = createKnowledgeSession(kbase);
final List list = new ArrayList();
session.setGlobal("list", list);
final State state = new State("initial");
session.insert(state);
session.fireAllRules();
assertEquals(1, ((List) session.getGlobal("list")).size());
state.setFlag(true);
assertEquals(1, ((List) session.getGlobal("list")).size());
session.fireAllRules();
assertEquals(2, ((List) session.getGlobal("list")).size());
state.setState("finished");
session.dispose();
// checks that the session removed itself from the bean listeners list
assertEquals(0, state.getPropertyChangeListeners().length);
}
use of org.drools.compiler.State in project drools by kiegroup.
the class FirstOrderLogicTest method testForall.
@Test
public void testForall() throws Exception {
KieBase kbase = loadKnowledgeBase("test_Forall.drl");
KieSession workingMemory = createKnowledgeSession(kbase);
final List list = new ArrayList();
workingMemory.setGlobal("results", list);
final State state = new State("SP");
workingMemory.insert(state);
final Person bob = new Person("Bob");
bob.setStatus(state.getState());
bob.setLikes("stilton");
workingMemory.insert(bob);
workingMemory.fireAllRules();
assertEquals(0, list.size());
workingMemory.insert(new Cheese(bob.getLikes(), 10));
workingMemory.fireAllRules();
assertEquals(1, list.size());
}
use of org.drools.compiler.State in project drools by kiegroup.
the class FirstOrderLogicTest method testForall2.
@Test
public void testForall2() throws Exception {
KieBase kbase = loadKnowledgeBase("test_Forall2.drl");
KieSession ksession = createKnowledgeSession(kbase);
final List<String> list = new ArrayList<String>();
ksession.setGlobal("results", list);
final State state = new State("SP");
ksession.insert(state);
final Person bob = new Person("Bob");
bob.setStatus(state.getState());
bob.setAlive(true);
ksession.insert(bob);
ksession.fireAllRules();
assertEquals(0, list.size());
final State qc = new State("QC");
ksession.insert(qc);
final Person john = new Person("John");
john.setStatus(qc.getState());
john.setAlive(false);
ksession.fireAllRules();
assertEquals(1, list.size());
}
Aggregations