use of org.kie.internal.builder.KnowledgeBuilderErrors in project drools by kiegroup.
the class StrEvaluatorTest method readKnowledgeBase.
private KieBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newInputStreamResource(getClass().getResourceAsStream("strevaluator_test.drl")), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge." + errors.toArray());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
return kbase;
}
use of org.kie.internal.builder.KnowledgeBuilderErrors in project drools by kiegroup.
the class RHSTest method testRHSClone.
@Test
public void testRHSClone() {
// JBRULES-3539
final String str = "import java.util.Map;\n" + "dialect \"mvel\"\n" + "rule \"RHSClone\"\n" + "when\n" + " Map($valOne : this['keyOne'] !=null)\n" + "then\n" + " System.out.println( $valOne.clone() );\n" + "end\n";
final KnowledgeBuilderConfigurationImpl pkgBuilderCfg = new KnowledgeBuilderConfigurationImpl();
final MVELDialectConfiguration mvelConf = (MVELDialectConfiguration) pkgBuilderCfg.getDialectConfiguration("mvel");
mvelConf.setStrict(false);
mvelConf.setLangLevel(5);
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pkgBuilderCfg);
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
final KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (final KnowledgeBuilderError error : errors) {
System.err.println(error);
}
fail("Could not parse knowledge");
}
}
use of org.kie.internal.builder.KnowledgeBuilderErrors in project drools by kiegroup.
the class KnowledgeBuilderImpl method newKnowledgeBase.
public KieBase newKnowledgeBase(KieBaseConfiguration conf) {
KnowledgeBuilderErrors errors = getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
logger.error(error.toString());
}
throw new IllegalArgumentException("Could not parse knowledge. See the logs for details.");
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(conf);
kbase.addPackages(Arrays.asList(getPackages()));
return kbase;
}
use of org.kie.internal.builder.KnowledgeBuilderErrors in project drools by kiegroup.
the class JavaDialectTest method testEvalDetectionInBetaNode.
@Test
public void testEvalDetectionInBetaNode() {
// Tests evals are generated and executed with Java dialect
String drl = "";
drl += "package org.drools.compiler.test\n";
drl += "import org.drools.compiler.Person\n";
drl += "global java.util.List list\n";
drl += "rule test1\n";
drl += "when\n";
drl += " $s : String()\n";
drl += " $p1 : Person( eval( name \n != $s ), name == ( new String($s+\"xxx\") ) )\n";
drl += "then\n";
drl += "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newReaderResource(new StringReader(drl)), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
assertFalse(kbuilder.hasErrors());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
List<ObjectTypeNode> nodes = ((KnowledgeBaseImpl) kbase).getRete().getObjectTypeNodes();
ObjectTypeNode node = null;
for (ObjectTypeNode n : nodes) {
if (((ClassObjectType) n.getObjectType()).getClassType() == Person.class) {
node = n;
break;
}
}
BetaNode betaanode = (BetaNode) node.getObjectSinkPropagator().getSinks()[0];
BetaNodeFieldConstraint[] constraint = betaanode.getConstraints();
PredicateConstraint c = (PredicateConstraint) constraint[0];
assertTrue(c.getPredicateExpression() instanceof PredicateExpression);
assertTrue(c.getPredicateExpression() instanceof CompiledInvoker);
}
use of org.kie.internal.builder.KnowledgeBuilderErrors in project drools by kiegroup.
the class DynamicEvalTest method loadPackages.
public void loadPackages(Resource res, ResourceType type) {
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(res, type);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
}
Aggregations