use of org.kie.internal.builder.KnowledgeBuilderErrors in project drools by kiegroup.
the class DrlParserTest method assertHasNoErrors.
private void assertHasNoErrors(KnowledgeBuilder kbuilder) {
KnowledgeBuilderErrors errors = kbuilder.getErrors();
assertEquals("Expected no build errors, but got: " + errors.toString(), 0, errors.size());
}
use of org.kie.internal.builder.KnowledgeBuilderErrors in project drools by kiegroup.
the class JBRULESTest method testJBRULES2872.
@Test
public void testJBRULES2872() {
final String str = "package org.drools.compiler.test\n" + "import org.drools.compiler.FactA\n" + "rule X\n" + "when\n" + " FactA( enumVal == TestEnum.ONE || == TestEnum.TWO )\n" + "then\n" + "end\n";
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertTrue(kbuilder.hasErrors());
final KnowledgeBuilderErrors errors = kbuilder.getErrors();
assertEquals(1, errors.size());
final KnowledgeBuilderError error = errors.iterator().next();
assertEquals(5, error.getLines()[0]);
}
use of org.kie.internal.builder.KnowledgeBuilderErrors in project drools by kiegroup.
the class MapPersistenceTest method createPersistentSessionWithRules.
@Test
public void createPersistentSessionWithRules() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
String rule = "package org.drools.persistence.map.impl\n";
rule += "import org.drools.persistence.map.impl.Buddy;\n";
rule += "rule \"echo2\" \n";
rule += "dialect \"mvel\"\n";
rule += "when\n";
rule += " $m : Buddy()\n";
rule += "then\n";
rule += " System.out.println(\"buddy inserted\")";
rule += "end\n";
kbuilder.add(new ByteArrayResource(rule.getBytes()), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors != null && errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
logger.warn("Error: " + error.getMessage());
}
Assert.fail("KnowledgeBase did not build");
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = createSession(kbase);
FactHandle buddyFactHandle = ksession.insert(new Buddy());
ksession.fireAllRules();
Assert.assertEquals(1, ksession.getObjects().size());
ksession = disposeAndReloadSession(ksession, kbase);
Assert.assertNotNull(ksession);
Assert.assertEquals(1, ksession.getObjects().size());
Assert.assertNull("An object can't be retrieved with a FactHandle from a disposed session", ksession.getObject(buddyFactHandle));
}
use of org.kie.internal.builder.KnowledgeBuilderErrors in project drools by kiegroup.
the class TimerAndCalendarTest method buildKnowledgePackage.
private Collection<KiePackage> buildKnowledgePackage(Resource resource, ResourceType resourceType) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(resource, resourceType);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors != null && errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println("Error: " + error.getMessage());
}
Assert.fail("KnowledgeBase did not build");
}
Collection<KiePackage> packages = kbuilder.getKnowledgePackages();
return packages;
}
use of org.kie.internal.builder.KnowledgeBuilderErrors in project drools by kiegroup.
the class CommonTestMethodBase method genSession.
public KieSession genSession(String[] sources, int numerrors) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
for (String source : sources) kbuilder.add(ResourceFactory.newClassPathResource(source, getClass()), ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (kbuilder.getErrors().size() > 0) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
System.err.println(error);
}
}
assertEquals(numerrors, errors.size());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
return createKnowledgeSession(kbase);
}
Aggregations