use of org.drools.testcoverage.common.model.Cheese in project drools by kiegroup.
the class EvalTest method testEvalException.
@Test
public void testEvalException() {
final String drl = "package org.drools.compiler.integrationtests.operators;\n" + "import " + Cheese.class.getCanonicalName() + ";\n" + "function boolean throwException(Object object) {\n" + " throw new Exception( \"this should throw an exception\" );\n" + "}\n" + "\n" + "rule \"Throw Eval Exception\"\n" + " when\n" + " cheese : Cheese( )\n" + " eval( throwException( cheese ) )\n" + " then\n" + "\n" + "end";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("eval-test", kieBaseTestConfiguration, drl);
final KieSession ksession = kbase.newKieSession();
try {
final Cheese brie = new Cheese("brie", 12);
try {
ksession.insert(brie);
ksession.fireAllRules();
fail("Should throw an Exception from the Eval");
} catch (final Exception e) {
assertTrue(e.getCause().getMessage().contains("this should throw an exception"));
}
} finally {
ksession.dispose();
}
}
use of org.drools.testcoverage.common.model.Cheese in project drools by kiegroup.
the class MatchesTest method testMatchesNotMatchesCheese.
@Test
public void testMatchesNotMatchesCheese() {
final String drl = "package org.drools.compiler.integrationtests.operators;\n" + "import " + Cheese.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "\n" + "rule \"Cheese matches stilton\"\n" + " salience 10\n" + " when\n" + " stilton : Cheese( type matches \"[Ss]tilto[^0-9]\" )\n" + " then\n" + " list.add( stilton );\n" + "end \n" + "\n" + "rule \"Cheese not matches\"\n" + " when\n" + " brie : Cheese( type not matches \"(stil.*|mu\\\\w*|brie\\\\d|aged.*|.*prov.*)\" )\n" + " then\n" + " list.add( brie );\n" + "end \n" + "\n" + "rule \"Cheese matches with space\"\n" + " salience -10\n" + " when\n" + " stilton : Cheese( type matches \"aged stilton\" )\n" + " then\n" + " list.add( stilton );\n" + "end \n" + "\n" + "rule \"Cheese matches with ^ and escaped s\"\n" + " salience -20\n" + " when\n" + " prov : Cheese( type matches \"^provolone\\\\s*\" )\n" + " then\n" + " list.add( prov );\n" + "end";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("matches-test", kieBaseTestConfiguration, drl);
final KieSession ksession = kbase.newKieSession();
try {
final List list = new ArrayList();
ksession.setGlobal("list", list);
final Cheese stilton = new Cheese("stilton", 12);
final Cheese stilton2 = new Cheese("stilton2", 12);
final Cheese agedStilton = new Cheese("aged stilton", 12);
final Cheese brie = new Cheese("brie", 10);
final Cheese brie2 = new Cheese("brie2", 10);
final Cheese muzzarella = new Cheese("muzzarella", 10);
final Cheese muzzarella2 = new Cheese("muzzarella2", 10);
final Cheese provolone = new Cheese("provolone", 10);
final Cheese provolone2 = new Cheese("another cheese (provolone)", 10);
ksession.insert(stilton);
ksession.insert(stilton2);
ksession.insert(agedStilton);
ksession.insert(brie);
ksession.insert(brie2);
ksession.insert(muzzarella);
ksession.insert(muzzarella2);
ksession.insert(provolone);
ksession.insert(provolone2);
ksession.fireAllRules();
assertEquals(4, list.size());
assertEquals(stilton, list.get(0));
assertEquals(brie, list.get(1));
assertEquals(agedStilton, list.get(2));
assertEquals(provolone, list.get(3));
} finally {
ksession.dispose();
}
}
Aggregations