use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DrlParserTest method testDeclaredSuperType.
@Test
public void testDeclaredSuperType() throws Exception {
String drl = "package foo \n" + "declare Bean1 \n" + "age: int \n" + "name : String \n" + "end \n" + "declare Bean2 extends Bean1\n" + "cheese : String \n" + "end";
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
PackageDescr pkgDescr = parser.parse(null, drl);
TypeDeclarationDescr bean1Type = pkgDescr.getTypeDeclarations().get(0);
assertNull(bean1Type.getSuperTypeName());
TypeDeclarationDescr bean2Type = pkgDescr.getTypeDeclarations().get(1);
assertEquals("Bean1", bean2Type.getSuperTypeName());
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class RuleParserTest method testExpanderMultipleConstraints.
@Test
public void testExpanderMultipleConstraints() throws Exception {
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
final PackageDescr pkg = parser.parse(this.getReader("expander_multiple_constraints.dslr"), this.getReader("multiple_constraints.dsl"));
assertFalse(parser.getErrors().toString(), parser.hasErrors());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(2, rule.getLhs().getDescrs().size());
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Person", pattern.getObjectType());
assertEquals(2, pattern.getConstraint().getDescrs().size());
assertEquals("age < 42", ((ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0)).getExpression());
assertEquals("location==atlanta", ((ExprConstraintDescr) pattern.getConstraint().getDescrs().get(1)).getExpression());
pattern = (PatternDescr) rule.getLhs().getDescrs().get(1);
assertEquals("Bar", pattern.getObjectType());
assertNotNull((String) rule.getConsequence());
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class RuleParserTest method testExpanderLineSpread.
@Test
public void testExpanderLineSpread() throws Exception {
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
final PackageDescr pkg = parser.parse(this.getReader("expander_spread_lines.dslr"), this.getReader("complex.dsl"));
assertFalse(parser.getErrors().toString(), parser.hasErrors());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(0);
assertEquals(2, or.getDescrs().size());
assertNotNull((String) rule.getConsequence());
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class RuleParserTest method testPackage.
@Test
public void testPackage() throws Exception {
final String source = "package foo.bar.baz";
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
final PackageDescr pkg = parser.parse(new StringReader(source));
assertFalse(parser.hasErrors());
assertEquals("foo.bar.baz", pkg.getName());
}
use of org.drools.drl.parser.DrlParser in project drools by kiegroup.
the class DRLIncompleteCodeTest method testIncompleteCode12.
@Test
public void testIncompleteCode12() throws DroolsParserException, RecognitionException {
String input = "package a.b.c " + "import a.b.c.* " + "rule MyRule" + " when " + " m: Message( ) " + " " + " then" + "end ";
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
PackageDescr descr = parser.parse(true, input);
assertNotNull(descr);
assertEquals("a.b.c", descr.getNamespace());
assertEquals("a.b.c.*", descr.getImports().get(0).getTarget());
}
Aggregations