Search in sources :

Example 6 with KnowledgeBuilderErrors

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());
}
Also used : KnowledgeBuilderErrors(org.kie.internal.builder.KnowledgeBuilderErrors)

Example 7 with KnowledgeBuilderErrors

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]);
}
Also used : KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KnowledgeBuilderErrors(org.kie.internal.builder.KnowledgeBuilderErrors) Test(org.junit.Test)

Example 8 with KnowledgeBuilderErrors

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));
}
Also used : KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KnowledgeBuilderErrors(org.kie.internal.builder.KnowledgeBuilderErrors) FactHandle(org.kie.api.runtime.rule.FactHandle) KieSession(org.kie.api.runtime.KieSession) ByteArrayResource(org.drools.core.io.impl.ByteArrayResource) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 9 with KnowledgeBuilderErrors

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;
}
Also used : KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KnowledgeBuilderErrors(org.kie.internal.builder.KnowledgeBuilderErrors) KiePackage(org.kie.api.definition.KiePackage)

Example 10 with KnowledgeBuilderErrors

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);
}
Also used : KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KnowledgeBuilderErrors(org.kie.internal.builder.KnowledgeBuilderErrors) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase)

Aggregations

KnowledgeBuilderErrors (org.kie.internal.builder.KnowledgeBuilderErrors)12 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)9 KnowledgeBuilderError (org.kie.internal.builder.KnowledgeBuilderError)9 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)7 Test (org.junit.Test)5 StringReader (java.io.StringReader)2 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)2 PredicateConstraint (org.drools.core.rule.PredicateConstraint)2 CompiledInvoker (org.drools.core.spi.CompiledInvoker)2 PredicateExpression (org.drools.core.spi.PredicateExpression)2 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)1 MVELDialectConfiguration (org.drools.compiler.rule.builder.dialect.mvel.MVELDialectConfiguration)1 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)1 AlphaNode (org.drools.core.reteoo.AlphaNode)1 BetaNode (org.drools.core.reteoo.BetaNode)1 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)1 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)1 BetaNodeFieldConstraint (org.drools.core.spi.BetaNodeFieldConstraint)1 FieldValue (org.drools.core.spi.FieldValue)1 KiePackage (org.kie.api.definition.KiePackage)1