use of org.drools.compiler.compiler.DrlParser in project drools by kiegroup.
the class MVELDebugTest method testDebug.
@Test
public void testDebug() throws Exception {
String rule = "package com.sample; dialect \"mvel\" rule myRule when then\n System.out.println( \"test\" ); end";
KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
PackageDescr packageDescr = parser.parse(null, rule);
RuleDescr ruleDescr = packageDescr.getRules().get(0);
builder = new KnowledgeBuilderImpl();
builder.addPackage(packageDescr);
InternalKnowledgePackage pkg = builder.getPackage("com.sample");
MVELConsequence consequence = (MVELConsequence) pkg.getRule("myRule").getConsequence();
String sourceName = ((CompiledExpression) consequence.getCompExpr()).getSourceName();
System.out.println(sourceName);
String ruleName = ruleDescr.getNamespace() + "." + ruleDescr.getClassName();
System.out.println(ruleName);
assertEquals(sourceName, ruleName);
}
use of org.drools.compiler.compiler.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.compiler.compiler.DrlParser in project drools by kiegroup.
the class RuleParserTest method testPackageWithError2.
@Test
public void testPackageWithError2() throws Exception {
final String source = "package 12 12312 231";
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
final PackageDescr pkg = parser.parse(true, new StringReader(source));
assertTrue(parser.hasErrors());
assertEquals("", pkg.getName());
}
use of org.drools.compiler.compiler.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.compiler.compiler.DrlParser in project drools by kiegroup.
the class RuleParserTest method testExpanderMultipleConstraintsFlush.
@Test
public void testExpanderMultipleConstraintsFlush() throws Exception {
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
// this is similar to the other test, but it requires a flush to add the
// constraints
final PackageDescr pkg = parser.parse(this.getReader("expander_multiple_constraints_flush.dslr"), this.getReader("multiple_constraints.dsl"));
assertFalse(parser.getErrors().toString(), parser.hasErrors());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final 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());
assertNotNull((String) rule.getConsequence());
}
Aggregations