use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DRLIncompleteCodeTest method testIncompleteCode7.
@Test
public void testIncompleteCode7() throws DroolsParserException, RecognitionException {
String input = "package a.b.c imrt a.b.c.*" + " rule MyRule when Class ( property memberOf collection ) then end " + " query MyQuery Class ( property memberOf collection ) end ";
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
PackageDescr descr = parser.parse(true, input);
assertNotNull(descr);
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DRLIncompleteCodeTest method testIncompleteCode8.
@Test
public void testIncompleteCode8() throws DroolsParserException, RecognitionException {
String input = "package a.b.c import a.1111.c.*" + " rule MyRule when Class ( property memberOf collection ) then end " + " query MyQuery Class ( property memberOf collection ) end ";
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
PackageDescr descr = parser.parse(true, input);
System.out.println(parser.getErrors());
assertEquals("a.b.c", descr.getNamespace());
// FIXME: assertEquals(2, descr.getRules().size());
assertEquals(true, parser.hasErrors());
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DRLIncompleteCodeTest method testIncompleteCode13.
@Test
public void testIncompleteCode13() throws DroolsParserException, RecognitionException {
String input = "package com.sample " + "import com.sample.DroolsTest.Message; " + "rule \"Hello World\"" + " when " + " then" + " \\\" " + "end ";
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
PackageDescr descr = parser.parse(true, input);
assertNotNull(descr);
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DRLIncompleteCodeTest method testIncompleteCode11.
@Test
public void testIncompleteCode11() throws DroolsParserException, RecognitionException {
String input = "package a.b.c import a.b.c.*" + " rule MyRule when Class ( property memberOf collection ) then end " + " qzzzzuery MyQuery Class ( property ";
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
PackageDescr descr = parser.parse(true, input);
assertEquals("a.b.c", descr.getNamespace());
assertEquals("a.b.c.*", descr.getImports().get(0).getTarget());
assertNotNull(descr);
assertEquals("MyRule", descr.getRules().get(0).getName());
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DRLDumperTest method testDumpers.
@Test
public void testDumpers() throws Exception {
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
final Resource resource = new InputStreamResource(getClass().getResourceAsStream("drl/test_Dumpers.drl"));
final PackageDescr pkg = parser.parse(resource);
if (parser.hasErrors()) {
for (final DroolsError error : parser.getErrors()) {
logger.warn(error.toString());
}
fail(parser.getErrors().toString());
}
final Resource descrResource = KieServices.Factory.get().getResources().newDescrResource(pkg);
descrResource.setSourcePath(TestConstants.TEST_RESOURCES_FOLDER + "test_Dumpers.descr");
KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, descrResource);
KieSession ksession = kbase.newKieSession();
List list = new ArrayList();
ksession.setGlobal("list", list);
final Cheese brie = new Cheese("brie", 12);
ksession.insert(brie);
ksession.fireAllRules();
assertEquals(3, list.size());
assertEquals("3 1", list.get(0));
assertEquals("MAIN", list.get(1));
assertEquals("1 1", list.get(2));
// ---------------------------
final DrlDumper drlDumper = new DrlDumper();
final String drlResult = drlDumper.dump(pkg);
System.out.println(drlResult);
kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drlResult);
ksession = kbase.newKieSession();
list = new ArrayList();
ksession.setGlobal("list", list);
ksession.insert(brie);
ksession.fireAllRules();
assertEquals(3, list.size());
assertEquals("3 1", list.get(0));
assertEquals("MAIN", list.get(1));
assertEquals("1 1", list.get(2));
}
Aggregations