use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class KnowledgeBuilderTest method testErrorReset.
@Test
public void testErrorReset() throws Exception {
final KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
builder.addPackageFromDrl(new StringReader("package foo \n rule ORB"));
assertTrue(builder.hasErrors());
builder.resetErrors();
assertFalse(builder.hasErrors());
builder.addPackageFromDrl(new StringReader("package foo \n rule ORB"));
assertTrue(builder.hasErrors());
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class KnowledgeBuilderTest method createLiteralRule.
private void createLiteralRule(final BaseDescr descr) {
final KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
final PackageDescr packageDescr = new PackageDescr("p1");
final RuleDescr ruleDescr = new RuleDescr("rule-1");
packageDescr.addRule(ruleDescr);
final AndDescr lhs = new AndDescr();
ruleDescr.setLhs(lhs);
final PatternDescr pattern = new PatternDescr(Primitives.class.getName());
lhs.addDescr(pattern);
pattern.addConstraint(descr);
ruleDescr.setConsequence("");
builder.addPackage(packageDescr);
assertLength(0, builder.getErrors().getErrors());
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class KnowledgeBuilderTest method testWarnings.
@Test
public void testWarnings() {
System.setProperty("drools.kbuilder.severity." + DuplicateRule.KEY, "WARNING");
final KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
final PackageDescr packageDescr1 = createBasicPackageWithOneRule(11, 1);
final PackageDescr packageDescr2 = createBasicPackageWithOneRule(22, 2);
builder.addPackage(packageDescr1);
builder.addPackage(packageDescr2);
assertFalse(builder.hasErrors());
assertTrue(builder.hasWarnings());
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class KnowledgeBuilderTest method testResetWarningsButNotErrors.
@Test
public void testResetWarningsButNotErrors() throws DroolsParserException, IOException {
System.setProperty("drools.kbuilder.severity." + DuplicateRule.KEY, "WARNING");
System.setProperty("drools.kbuilder.severity." + DuplicateFunction.KEY, "ERROR");
final KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
final PackageDescr packageDescr1 = createBasicPackageWithOneRule(11, 1);
final PackageDescr packageDescr2 = createBasicPackageWithOneRule(22, 2);
builder.addPackage(packageDescr1);
builder.addPackage(packageDescr2);
builder.addPackageFromDrl(new StringReader("package foo \n rule ORB"));
builder.addPackageFromDrl(new StringReader("package org.drools\n" + "function boolean testIt() {\n" + " return true;\n" + "}\n"));
builder.addPackageFromDrl(new StringReader("package org.drools\n" + "function boolean testIt() {\n" + " return false;\n" + "}\n"));
assertTrue(builder.hasWarnings());
assertTrue(builder.hasErrors());
builder.resetWarnings();
assertFalse(builder.hasWarnings());
assertTrue(builder.hasErrors());
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class KnowledgeBuilderTest method testReturnValue.
@Test
public void testReturnValue() throws Exception {
final KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
final PackageDescr packageDescr = new PackageDescr("p1");
final RuleDescr ruleDescr = new RuleDescr("rule-1");
packageDescr.addRule(ruleDescr);
final AndDescr lhs = new AndDescr();
ruleDescr.setLhs(lhs);
final PatternDescr pattern = new PatternDescr(Cheese.class.getName(), "stilton");
lhs.addDescr(pattern);
BindingDescr fieldBindingDescr = new BindingDescr("x", "price");
pattern.addConstraint(fieldBindingDescr);
fieldBindingDescr = new BindingDescr("y", "price");
pattern.addConstraint(fieldBindingDescr);
packageDescr.addGlobal(new GlobalDescr("map", "java.util.Map"));
pattern.addConstraint(new ExprConstraintDescr("price == (( (Integer) map.get( new Integer( x )) ).intValue() * y)"));
ruleDescr.setConsequence("update(stilton);");
builder.addPackage(packageDescr);
assertEquals("Should not have any errors", 0, builder.getErrors().getErrors().length);
}
Aggregations