use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class RuleParserTest method testOrWithBinding.
/**
* test basic foo : Fact() || Fact() stuff
*/
@Test
public void testOrWithBinding() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "or_binding.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(2, rule.getLhs().getDescrs().size());
final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get(0);
assertEquals(2, or.getDescrs().size());
final PatternDescr leftPattern = (PatternDescr) or.getDescrs().get(0);
assertEquals("Person", leftPattern.getObjectType());
assertEquals("foo", leftPattern.getIdentifier());
final PatternDescr rightPattern = (PatternDescr) or.getDescrs().get(1);
assertEquals("Person", rightPattern.getObjectType());
assertEquals("foo", rightPattern.getIdentifier());
final PatternDescr cheeseDescr = (PatternDescr) rule.getLhs().getDescrs().get(1);
assertEquals("Cheese", cheeseDescr.getObjectType());
assertEquals(null, cheeseDescr.getIdentifier());
assertEqualsIgnoreWhitespace("System.out.println( \"Mark and Michael\" + bar );", (String) rule.getConsequence());
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class RuleParserTest method testWithPredicate.
@Test
public void testWithPredicate() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "with_predicate.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(1, rule.getLhs().getDescrs().size());
final PatternDescr col = (PatternDescr) rule.getLhs().getDescrs().get(0);
AndDescr and = (AndDescr) col.getConstraint();
assertEquals(2, and.getDescrs().size());
final ExprConstraintDescr field = (ExprConstraintDescr) col.getDescrs().get(0);
final ExprConstraintDescr pred = (ExprConstraintDescr) and.getDescrs().get(1);
assertEquals("$age2:age", field.getExpression());
assertEqualsIgnoreWhitespace("$age2 == $age1+2", pred.getExpression());
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class RuleParserTest method testAttributes2.
@Test
public void testAttributes2() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "rule_attributes2.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
List<RuleDescr> rules = pkg.getRules();
assertEquals(3, rules.size());
RuleDescr rule = rules.get(0);
assertEquals("rule1", rule.getName());
Map<String, AttributeDescr> attrs = rule.getAttributes();
assertEquals(2, attrs.size());
AttributeDescr at = (AttributeDescr) attrs.get("salience");
assertEquals("salience", at.getName());
assertEquals("(42)", at.getValue());
at = (AttributeDescr) attrs.get("agenda-group");
assertEquals("agenda-group", at.getName());
assertEquals("my_group", at.getValue());
rule = rules.get(1);
assertEquals("rule2", rule.getName());
attrs = rule.getAttributes();
assertEquals(2, attrs.size());
at = (AttributeDescr) attrs.get("salience");
assertEquals("salience", at.getName());
assertEquals("(Integer.MIN_VALUE)", at.getValue());
at = (AttributeDescr) attrs.get("no-loop");
assertEquals("no-loop", at.getName());
rule = rules.get(2);
assertEquals("rule3", rule.getName());
attrs = rule.getAttributes();
assertEquals(2, attrs.size());
at = (AttributeDescr) attrs.get("enabled");
assertEquals("enabled", at.getName());
assertEquals("(Boolean.TRUE)", at.getValue());
at = (AttributeDescr) attrs.get("activation-group");
assertEquals("activation-group", at.getName());
assertEquals("my_activation_group", at.getValue());
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class VerifierImpl method addResourcesToVerify.
public void addResourcesToVerify(Resource resource, ResourceType type) {
verifierPackageBuilder.addKnowledgeResource(resource, type, null);
if (verifierPackageBuilder.hasErrors()) {
addVerifierErrors(verifierPackageBuilder.getErrors());
}
PackageDescr pkg = verifierPackageBuilder.getPackageDescr();
if (pkg != null) {
addPackageDescr(pkg);
} else {
errors.add(new VerifierError("Verifier could not form a PackageDescr from the resources that it was trying to verify."));
}
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class ExprConstraintDescrVisitorTest method testVisitVariableRestriction.
@Test
public void testVisitVariableRestriction() throws Exception {
PackageDescr packageDescr = getPackageDescr(getClass().getResourceAsStream("ExprConstraintDescr3.drl"));
assertNotNull(packageDescr);
packageDescrVisitor.visitPackageDescr(packageDescr);
Collection<StringRestriction> allRestrictions = verifierData.getAll(VerifierComponentType.RESTRICTION);
assertEquals(1, allRestrictions.size());
assertContainsFields(1);
assertContainsField("age");
assertContainsVariable("Test 1", "var");
assertContainsVariableRestriction(Operator.BuiltInOperator.EQUAL.getOperator(), "var");
}
Aggregations