Search in sources :

Example 61 with Cheese

use of org.drools.compiler.Cheese in project drools by kiegroup.

the class IndexingTest method testRangeIndex2.

@Test(timeout = 10000)
public void testRangeIndex2() {
    String str = "import org.drools.compiler.*;\n" + "rule R1\n" + "when\n" + "   $s : String()" + "   exists Cheese( type < $s )\n" + "then\n" + "   System.out.println( $s );\n" + "end\n";
    KieBase kbase = loadKnowledgeBaseFromString(str);
    KieSession ksession = kbase.newKieSession();
    ksession.insert("gorgonzola");
    ksession.insert(new Cheese("cheddar", 10));
    ksession.insert(new Cheese("gorgonzola", 10));
    ksession.insert(new Cheese("stilton", 10));
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Cheese(org.drools.compiler.Cheese) Test(org.junit.Test)

Example 62 with Cheese

use of org.drools.compiler.Cheese in project drools by kiegroup.

the class IndexingTest method testNotNodeModifyRight.

@Test(timeout = 10000)
public void testNotNodeModifyRight() {
    String str = "import org.drools.compiler.*;\n" + "rule R1 salience 10 when\n" + "   Person( $age : age )\n" + "   not Cheese( price < $age )\n" + "then\n" + "   System.out.println( $age );\n" + "end\n" + "rule R3 salience 5 when\n" + "   $c : Cheese( price == 8 )\n" + "then\n" + "   modify($c) { setPrice(15); }\n" + "end\n";
    KieBase kbase = loadKnowledgeBaseFromString(str);
    KieSession ksession = kbase.newKieSession();
    ksession.insert(new Person("A", 10));
    ksession.insert(new Cheese("C1", 20));
    ksession.insert(new Cheese("C2", 8));
    assertEquals(2, ksession.fireAllRules());
    ksession.dispose();
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Cheese(org.drools.compiler.Cheese) Person(org.drools.compiler.Person) Test(org.junit.Test)

Example 63 with Cheese

use of org.drools.compiler.Cheese in project drools by kiegroup.

the class IndexingTest method testRangeIndex.

@Test(timeout = 10000)
public void testRangeIndex() {
    String str = "import org.drools.compiler.*;\n" + "rule R1\n" + "when\n" + "   $s : String()" + "   exists Cheese( type > $s )\n" + "then\n" + "   System.out.println( $s );\n" + "end\n";
    KieBase kbase = loadKnowledgeBaseFromString(str);
    KieSession ksession = kbase.newKieSession();
    ksession.insert("cheddar");
    ksession.insert("gorgonzola");
    ksession.insert("stilton");
    ksession.insert(new Cheese("gorgonzola", 10));
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Cheese(org.drools.compiler.Cheese) Test(org.junit.Test)

Example 64 with Cheese

use of org.drools.compiler.Cheese in project drools by kiegroup.

the class IntegrationInterfacesTest method testGlobals.

@SuppressWarnings("unchecked")
@Test
public void testGlobals() throws Exception {
    final KieBase kbase = getKnowledgeBase("globals_rule_test.drl");
    KieSession ksession = createKnowledgeSession(kbase);
    final List<Object> list = mock(List.class);
    ksession.setGlobal("list", list);
    ksession.setGlobal("string", "stilton");
    final Cheese stilton = new Cheese("stilton", 5);
    ksession.insert(stilton);
    ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
    ksession.fireAllRules();
    verify(list, times(1)).add(new Integer(5));
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Cheese(org.drools.compiler.Cheese) Test(org.junit.Test)

Example 65 with Cheese

use of org.drools.compiler.Cheese in project drools by kiegroup.

the class ExecutionFlowControlTest method testNoLoop.

@Test
public void testNoLoop() throws Exception {
    KieBase kbase = loadKnowledgeBase("no-loop.drl");
    KieSession ksession = kbase.newKieSession();
    ;
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    final Cheese brie = new Cheese("brie", 12);
    ksession.insert(brie);
    ksession.fireAllRules();
    assertEquals("Should not loop  and thus size should be 1", 1, list.size());
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) Cheese(org.drools.compiler.Cheese) Test(org.junit.Test)

Aggregations

Cheese (org.drools.compiler.Cheese)222 Test (org.junit.Test)204 KieSession (org.kie.api.runtime.KieSession)195 ArrayList (java.util.ArrayList)152 KieBase (org.kie.api.KieBase)138 List (java.util.List)100 Person (org.drools.compiler.Person)92 FactHandle (org.kie.api.runtime.rule.FactHandle)53 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)36 KiePackage (org.kie.api.definition.KiePackage)22 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)21 InternalFactHandle (org.drools.core.common.InternalFactHandle)20 Cheesery (org.drools.compiler.Cheesery)14 IteratorToList (org.drools.compiler.integrationtests.IteratorToList)14 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)13 HashMap (java.util.HashMap)10 Command (org.kie.api.command.Command)8 ExecutionResults (org.kie.api.runtime.ExecutionResults)8 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)7 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)7