use of org.drools.compiler.Cheese in project drools by kiegroup.
the class StatelessSessionTest method testSingleObjectAssert.
@Test
public void testSingleObjectAssert() throws Exception {
final StatelessKieSession session = getSession2("statelessSessionTest.drl");
final Cheese stilton = new Cheese("stilton", 5);
session.execute(stilton);
assertEquals("stilton", list.get(0));
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class StatelessSessionTest method testSetGlobal.
@Test
public void testSetGlobal() throws Exception {
String str = "";
str += "package org.kie \n";
str += "import org.drools.compiler.Cheese \n";
str += "global java.util.List list1 \n";
str += "global java.util.List list2 \n";
str += "global java.util.List list3 \n";
str += "rule rule1 \n";
str += " when \n";
str += " $c : Cheese() \n";
str += " \n";
str += " then \n";
str += " $c.setPrice( 30 ); \n";
str += " list1.add( $c ); \n";
str += " list2.add( $c ); \n";
str += " list3.add( $c ); \n";
str += "end\n";
final Cheese stilton = new Cheese("stilton", 5);
final List list1 = new ArrayList();
List list2 = new ArrayList();
List list3 = new ArrayList();
final StatelessKieSession ksession = getSession2(ResourceFactory.newByteArrayResource(str.getBytes()));
final Command setGlobal1 = CommandFactory.newSetGlobal("list1", list1);
final Command setGlobal2 = CommandFactory.newSetGlobal("list2", list2, true);
final Command setGlobal3 = CommandFactory.newSetGlobal("list3", list3, "outList3");
final Command insert = CommandFactory.newInsert(stilton);
final List cmds = new ArrayList();
cmds.add(setGlobal1);
cmds.add(setGlobal2);
cmds.add(setGlobal3);
cmds.add(insert);
final ExecutionResults result = (ExecutionResults) ksession.execute(CommandFactory.newBatchExecution(cmds));
assertEquals(30, stilton.getPrice());
assertNull(result.getValue("list1"));
list2 = (List) result.getValue("list2");
assertEquals(1, list2.size());
assertSame(stilton, list2.get(0));
list3 = (List) result.getValue("outList3");
assertEquals(1, list3.size());
assertSame(stilton, list3.get(0));
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class StatelessSessionTest method testInsertObject.
@Test
public void testInsertObject() throws Exception {
String str = "";
str += "package org.kie \n";
str += "import org.drools.compiler.Cheese \n";
str += "rule rule1 \n";
str += " when \n";
str += " $c : Cheese() \n";
str += " \n";
str += " then \n";
str += " $c.setPrice( 30 ); \n";
str += "end\n";
Cheese stilton = new Cheese("stilton", 5);
final StatelessKieSession ksession = getSession2(ResourceFactory.newByteArrayResource(str.getBytes()));
final ExecutableCommand cmd = (ExecutableCommand) CommandFactory.newInsert(stilton, "outStilton");
final BatchExecutionCommandImpl batch = new BatchExecutionCommandImpl(Arrays.asList(new ExecutableCommand<?>[] { cmd }));
final ExecutionResults result = (ExecutionResults) ksession.execute(batch);
stilton = (Cheese) result.getValue("outStilton");
assertEquals(30, stilton.getPrice());
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class UpdateTest method testJavaModifyBlock.
// this test requires mvel 1.2.19. Leaving it commented until mvel is released.
@Test
public void testJavaModifyBlock() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_JavaModifyBlock.drl"));
final KieSession ksession = createKnowledgeSession(kbase);
final List list = new ArrayList();
ksession.setGlobal("results", list);
final Person bob = new Person("Bob", 30);
bob.setStatus("hungry");
ksession.insert(bob);
ksession.insert(new Cheese());
ksession.insert(new Cheese());
ksession.insert(new OuterClass.InnerClass(1));
ksession.fireAllRules();
assertEquals(2, list.size());
assertEquals("full", bob.getStatus());
assertEquals(31, bob.getAge());
assertEquals(2, ((OuterClass.InnerClass) list.get(1)).getIntAttr());
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class UpdateTest method doModifyTest.
private void doModifyTest(final String drlResource) throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase(drlResource));
final KieSession ksession = createKnowledgeSession(kbase);
final List list = new ArrayList();
ksession.setGlobal("results", list);
final Person bob = new Person("Bob");
bob.setStatus("hungry");
final Cheese c = new Cheese();
ksession.insert(bob);
ksession.insert(c);
ksession.fireAllRules();
assertEquals(10, c.getPrice());
assertEquals("fine", bob.getStatus());
}
Aggregations