@Test public void testInsertObject() throws Exception { String str = ""; str += "package org.drools \n"; str += "import org.drools.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); StatelessKnowledgeSession ksession = getSession2(ResourceFactory.newByteArrayResource(str.getBytes())); GenericCommand cmd = (GenericCommand) CommandFactory.newInsert(stilton, "outStilton"); BatchExecutionCommandImpl batch = new BatchExecutionCommandImpl(Arrays.asList(new GenericCommand<?>[] {cmd})); ExecutionResults result = (ExecutionResults) ksession.execute(batch); stilton = (Cheese) result.getValue("outStilton"); assertEquals(30, stilton.getPrice()); }
@Test public void testSetGlobal() throws Exception { String str = ""; str += "package org.drools \n"; str += "import org.drools.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"; Cheese stilton = new Cheese("stilton", 5); List list1 = new ArrayList(); List list2 = new ArrayList(); List list3 = new ArrayList(); StatelessKnowledgeSession ksession = getSession2(ResourceFactory.newByteArrayResource(str.getBytes())); Command setGlobal1 = CommandFactory.newSetGlobal("list1", list1); Command setGlobal2 = CommandFactory.newSetGlobal("list2", list2, true); Command setGlobal3 = CommandFactory.newSetGlobal("list3", list3, "outList3"); Command insert = CommandFactory.newInsert(stilton); List cmds = new ArrayList(); cmds.add(setGlobal1); cmds.add(setGlobal2); cmds.add(setGlobal3); cmds.add(insert); 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)); }
public boolean equals(final Object object) { if (object == this) { return true; } if (object == null || !(object instanceof Cheese)) { return false; } final Cheese other = (Cheese) object; return (this.type.equals(other.getType()) && this.price == other.getPrice()); }