use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class ConsequenceTest method testConsequenceBuilderException.
@Test
public void testConsequenceBuilderException() throws Exception {
final KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
builder.add(ResourceFactory.newClassPathResource("test_ConsequenceBuilderException.drl", getClass()), ResourceType.DRL);
assertTrue(builder.hasErrors());
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class ConsequenceTest method testMVELConsequenceUsingFactConstructors.
// following test depends on MVEL: http://jira.codehaus.org/browse/MVEL-212
@Test
public void testMVELConsequenceUsingFactConstructors() throws Exception {
String drl = "";
drl += "package test\n";
drl += "import org.drools.compiler.Person\n";
drl += "global " + KieSession.class.getCanonicalName() + " ksession\n";
drl += "rule test dialect 'mvel'\n";
drl += "when\n";
drl += " $person:Person( name == 'mark' )\n";
drl += "then\n";
drl += " // below constructor for Person does not exist\n";
drl += " Person p = new Person( 'bob', 30, 555 )\n";
drl += " ksession.update(ksession.getFactHandle($person), new Person('bob', 30, 999, 453, 534, 534, 32))\n";
drl += "end\n";
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newReaderResource(new StringReader(drl)), ResourceType.DRL);
assertTrue(kbuilder.hasErrors());
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class ImportsTest method testMissingImports.
@Test
public void testMissingImports() {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("test_missing_import.drl", getClass()), ResourceType.DRL);
assertTrue(kbuilder.hasErrors());
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class TestUtil method buildSessionInSteps.
public static KieSession buildSessionInSteps(final boolean reuseKieBaseWhenAddingRules, final String... drls) {
if (drls == null || drls.length == 0) {
return KnowledgeBaseFactory.newKnowledgeBase().newKieSession();
} else {
String drl = drls[0];
final KnowledgeBuilder kbuilder = createKnowledgeBuilder(null, drl);
final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
final KieSession kSession = kbase.newKieSession();
for (int i = 1; i < drls.length; i++) {
drl = drls[i];
final KnowledgeBuilder kbuilder2;
if (reuseKieBaseWhenAddingRules) {
kbuilder2 = createKnowledgeBuilder(kSession.getKieBase(), drl);
} else {
kbuilder2 = createKnowledgeBuilder(null, drl);
}
((InternalKnowledgeBase) kSession.getKieBase()).addPackages(kbuilder2.getKnowledgePackages());
}
return kSession;
}
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class RuleExtensionTest method testRuleExtendsNonexistingRule.
@Test
public void testRuleExtendsNonexistingRule() {
// DROOLS-100
String str = "package org.drools.test;\n" + "\n" + "global java.util.List list;\n" + "\n" + "rule \"Base\"\n" + "when\n" + " String( this == \"go\" )\n" + "then\n" + "end\n" + "\n" + "rule \"ExtYes\" extends \"Bas\"\n" + "when\n" + "then\n" + " list.add( 1 );\n" + "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertTrue(kbuilder.hasErrors());
kbuilder.getErrors().iterator().next().toString().contains("Base");
}
Aggregations