use of org.drools.compiler.compiler.DrlParser in project drools by kiegroup.
the class NestingTest method testNesting.
@Test
public void testNesting() throws Exception {
final Person p = new Person();
p.setName("Michael");
final Address add1 = new Address();
add1.setStreet("High");
final Address add2 = new Address();
add2.setStreet("Low");
final List l = new ArrayList();
l.add(add1);
l.add(add2);
p.setAddresses(l);
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
final PackageDescr desc = parser.parse(new InputStreamReader(getClass().getResourceAsStream("nested_fields.drl")));
final List packageAttrs = desc.getAttributes();
assertEquals(1, desc.getRules().size());
assertEquals(1, packageAttrs.size());
final RuleDescr rule = desc.getRules().get(0);
final Map<String, AttributeDescr> ruleAttrs = rule.getAttributes();
assertEquals(1, ruleAttrs.size());
assertEquals("mvel", ruleAttrs.get("dialect").getValue());
assertEquals("dialect", ruleAttrs.get("dialect").getName());
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase(desc));
KieSession session = createKnowledgeSession(kbase);
session.insert(p);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
session.fireAllRules();
}
use of org.drools.compiler.compiler.DrlParser in project drools by kiegroup.
the class DRLIncompleteCodeTest method testIncompleteCode5.
@Test
public void testIncompleteCode5() throws DroolsParserException, RecognitionException {
String input = "package a.b.c import 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.compiler.compiler.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.compiler.compiler.DrlParser in project drools by kiegroup.
the class DRLIncompleteCodeTest method testIncompleteCode2.
@Test
public void testIncompleteCode2() throws DroolsParserException, RecognitionException {
String input = "rule MyRule when Class ( property memberOf collection ";
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
PackageDescr descr = parser.parse(true, input);
assertNotNull(descr);
assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, getLastIntegerValue(parser.getEditorSentences().get(0).getContent()));
}
use of org.drools.compiler.compiler.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());
}
Aggregations