Search in sources :

Example 51 with KnowledgeBuilder

use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.

the class NamedConsequencesTest method testNonCompilingDuplicatedNamedConsequence.

@Test
public void testNonCompilingDuplicatedNamedConsequence() {
    String str = "import org.drools.compiler.Cheese;\n " + "global java.util.List results;\n" + "\n" + "rule R1 when\n" + "    $a: Cheese ( type == \"stilton\" )\n" + "    do[t1]\n" + "    $b: Cheese ( type == \"cheddar\" )\n" + "then\n" + "    results.add( $b.getType() );\n" + "then[t1]\n" + "    results.add( $a.getType() );\n" + "then[t1]\n" + "    results.add( $a.getType() );\n" + "end\n";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
    assertTrue(kbuilder.hasErrors());
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) Test(org.junit.Test)

Example 52 with KnowledgeBuilder

use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.

the class NamedConsequencesTest method testOutOfScopeNamedConsequences.

@Test
public void testOutOfScopeNamedConsequences() {
    String str = "import org.drools.compiler.Cheese;\n " + "global java.util.List results;\n" + "\n" + "rule R1 when\n" + "    $a: Cheese ( type == \"stilton\" )\n" + "    do[t1]\n" + "    $b: Cheese ( type == \"cheddar\" )\n" + "then\n" + "    results.add( $b.getType() );\n" + "then[t1]\n" + "    results.add( $b.getType() );\n" + "end\n";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
    assertTrue(kbuilder.hasErrors());
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) Test(org.junit.Test)

Example 53 with KnowledgeBuilder

use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.

the class NamedConsequencesTest method testNonCompilingBreakingConsequences.

@Test
public void testNonCompilingBreakingConsequences() {
    String str = "import org.drools.compiler.Cheese;\n " + "global java.util.List results;\n" + "\n" + "rule R1 when\n" + "    $a: Cheese ( type == \"stilton\" )\n" + "    break[t1]\n" + "    $b: Cheese ( type == \"cheddar\" )\n" + "then\n" + "    results.add( $b.getType() );\n" + "then[t1]\n" + "    results.add( $a.getType() );\n" + "end\n";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
    assertTrue(kbuilder.hasErrors());
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) Test(org.junit.Test)

Example 54 with KnowledgeBuilder

use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.

the class NamedConsequencesTest method testNonCompilingIFAfterOR.

@Test
public void testNonCompilingIFAfterOR() {
    String str = "import org.drools.compiler.Cheese;\n " + "global java.util.List results;\n" + "\n" + "rule R1 when\n" + "    ( $a: Cheese ( type == \"stilton\" )\n" + "    or\n" + "    $a: Cheese ( type == \"gorgonzola\" ) )\n" + "    if ( price > 10 ) do[t1]\n" + "    $b: Cheese ( type == \"cheddar\" )\n" + "then\n" + "    results.add( $b.getType() );\n" + "then[t1]\n" + "    results.add( $a.getType() );\n" + "end\n";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
    assertTrue(kbuilder.hasErrors());
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) Test(org.junit.Test)

Example 55 with KnowledgeBuilder

use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.

the class NamedConsequencesTest method testOutOfScopeNamedConsequencesWithOr2.

@Test
public void testOutOfScopeNamedConsequencesWithOr2() {
    String str = "import org.drools.compiler.Cheese;\n " + "global java.util.List results;\n" + "\n" + "rule R1 when\n" + "    ( $a: Cheese ( type == \"stilton\" )\n" + "    or\n" + "    $b: Cheese ( type == \"gorgonzola\" ) do[t1] )\n" + "    $c: Cheese ( type == \"cheddar\" )\n" + "then\n" + "    results.add( $c.getType() );\n" + "then[t1]\n" + "    results.add( $c.getType() );\n" + "end\n";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
    assertTrue(kbuilder.hasErrors());
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) Test(org.junit.Test)

Aggregations

KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)376 Test (org.junit.Test)302 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)231 KieSession (org.kie.api.runtime.KieSession)149 ArrayList (java.util.ArrayList)112 List (java.util.List)65 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)52 KiePackage (org.kie.api.definition.KiePackage)39 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)38 FactHandle (org.kie.api.runtime.rule.FactHandle)36 FactType (org.kie.api.definition.type.FactType)27 KieBaseConfiguration (org.kie.api.KieBaseConfiguration)24 Person (org.drools.compiler.Person)23 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)23 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)22 InternalFactHandle (org.drools.core.common.InternalFactHandle)19 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)17 TraitableBean (org.drools.core.factmodel.traits.TraitableBean)17 StringReader (java.io.StringReader)15 Resource (org.kie.api.io.Resource)15