use of org.drools.testcoverage.common.model.Cell in project drools by kiegroup.
the class AbstractCellTest method testCell.
@Test
public void testCell() throws IOException, ClassNotFoundException {
final String drl = "package evalmodify;\n" + "\n" + "import " + Cell.class.getCanonicalName() + "\n" + "import java.lang.Integer\n" + "\n" + "rule \"test eval\"\n" + " when\n" + " cell1 : Cell(value1:value != 0)\n" + " cell2 : Cell(value2:value < value1)\n" + " eval (true)\n" + " then\n" + " cell2.setValue(value2 + 1);\n" + " update(cell2);\n" + "end";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("cell-test", kieBaseTestConfiguration, drl);
final Environment env = EnvironmentFactory.newEnvironment();
env.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[] { new IdentityPlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) });
KieSession session = kbase.newKieSession(KieSessionTestConfiguration.STATEFUL_REALTIME.getKieSessionConfiguration(), env);
try {
final Cell cell1 = new Cell(9);
final Cell cell = new Cell(0);
session.insert(cell1);
session.insert(cell);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
session.fireAllRules();
if (kieBaseTestConfiguration.isIdentity()) {
assertEquals(9, cell.getValue());
} else {
assertEquals(0, cell.getValue());
}
} finally {
session.dispose();
}
}
use of org.drools.testcoverage.common.model.Cell in project drools by kiegroup.
the class CellTest method testFreeFormExpressions.
@Test
public void testFreeFormExpressions() {
final String drl = "package org.drools.compiler\n" + "import " + Cell.class.getCanonicalName() + "\n" + "rule r1\n" + "when\n" + " $p1 : Cell( row == 2 )\n" + " $p2 : Cell( row == $p1.row + 1, row == ($p1.row + 1), row == 1 + $p1.row, row == (1 + $p1.row) )\n" + "then\n" + "end\n";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("cell-test", kieBaseTestConfiguration, drl);
final KieSession ksession = kbase.newKieSession();
try {
final Cell c1 = new Cell(1, 2, 0);
final Cell c2 = new Cell(1, 3, 0);
ksession.insert(c1);
ksession.insert(c2);
final int rules = ksession.fireAllRules();
assertEquals(1, rules);
} finally {
ksession.dispose();
}
}
Aggregations