Search in sources :

Example 1 with Cheesery

use of org.drools.mvel.compiler.Cheesery in project drools by kiegroup.

the class ShadowProxyTest method testShadowProxyOnCollections.

@Test
public void testShadowProxyOnCollections() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_ShadowProxyOnCollections.drl");
    KieSession ksession = kbase.newKieSession();
    try {
        final List results = new ArrayList();
        ksession.setGlobal("results", results);
        final Cheesery cheesery = new Cheesery();
        ksession.insert(cheesery);
        ksession.fireAllRules();
        assertEquals(1, results.size());
        assertEquals(1, cheesery.getCheeses().size());
        assertEquals(results.get(0), cheesery.getCheeses().get(0));
    } finally {
        ksession.dispose();
    }
}
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) Cheesery(org.drools.mvel.compiler.Cheesery) Test(org.junit.Test)

Example 2 with Cheesery

use of org.drools.mvel.compiler.Cheesery in project drools by kiegroup.

the class SessionInspectorTest method testGetSessionInfo.

@Test
public void testGetSessionInfo() {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(this.getClass(), kieBaseTestConfiguration, "org/drools/mvel/integrationtests/test_SubNetworks.drl", "org/drools/mvel/integrationtests/test_AccumulateWithFromChaining.drl", "org/drools/mvel/integrationtests/test_CollectResultsBetaConstraint.drl", "org/drools/mvel/integrationtests/test_QueryMemoryLeak.drl");
    KieSession ksession = kbase.newKieSession();
    ksession.setGlobal("results", new ArrayList<Object>());
    ksession.insert(new Dimension(100, 50));
    ksession.insert(new Dimension(130, 80));
    ksession.insert(new Dimension(50, 40));
    ksession.insert(new Dimension(50, 40));
    Cheesery cheesery = new Cheesery();
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    ksession.insert(cheesery);
    ksession.insert(new Person("Bob", "muzzarella"));
    ksession.insert(new Person("Mark", "brie"));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("Stilton", 10));
    ksession.insert(new Cheese("Stilton", 10));
    ksession.insert(new Cheese("Stilton", 10));
    ksession.insert(new Double(10));
    ksession.insert(new Double(11));
    ksession.insert(new Double(12));
    ksession.insert(new Double(13));
    ksession.insert(new Double(14));
    ksession.insert(new Integer(15));
    ksession.insert(new Integer(16));
    ksession.insert(new Integer(17));
    ksession.insert(new Integer(18));
    FactHandle handle = ksession.insert(new Worker());
    ksession.retract(handle);
    SessionInspector inspector = new SessionInspector(ksession);
    StatefulKnowledgeSessionInfo info = inspector.getSessionInfo();
    String report = SessionReporter.generateReport("simple", info, null);
    assertNotNull(report);
}
Also used : StatefulKnowledgeSessionInfo(org.drools.kiesession.debug.StatefulKnowledgeSessionInfo) FactHandle(org.kie.api.runtime.rule.FactHandle) Cheese(org.drools.mvel.compiler.Cheese) Dimension(java.awt.Dimension) Cheesery(org.drools.mvel.compiler.Cheesery) KieBase(org.kie.api.KieBase) Worker(org.drools.mvel.compiler.Worker) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.mvel.compiler.Person) SessionInspector(org.drools.kiesession.debug.SessionInspector) Test(org.junit.Test)

Example 3 with Cheesery

use of org.drools.mvel.compiler.Cheesery in project drools by kiegroup.

the class SessionInspectorTest method testGetSessionInfoWithCustomTemplate.

@Test
public void testGetSessionInfoWithCustomTemplate() {
    if (System.getProperty("java.vendor").toUpperCase().contains("IBM")) {
        // Does not work in the IBM JDK due to a bug in MVEL
        return;
    }
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(this.getClass(), kieBaseTestConfiguration, "org/drools/mvel/integrationtests/test_SubNetworks.drl", "org/drools/mvel/integrationtests/test_AccumulateWithFromChaining.drl", "org/drools/mvel/integrationtests/test_CollectResultsBetaConstraint.drl", "org/drools/mvel/integrationtests/test_QueryMemoryLeak.drl");
    KieSession ksession = kbase.newKieSession();
    ksession.setGlobal("results", new ArrayList<Object>());
    ksession.insert(new Dimension(100, 50));
    ksession.insert(new Dimension(130, 80));
    ksession.insert(new Dimension(50, 40));
    ksession.insert(new Dimension(50, 40));
    Cheesery cheesery = new Cheesery();
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    ksession.insert(cheesery);
    ksession.insert(new Person("Bob", "muzzarella"));
    ksession.insert(new Person("Mark", "brie"));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("Stilton", 10));
    ksession.insert(new Cheese("Stilton", 10));
    ksession.insert(new Cheese("Stilton", 10));
    ksession.insert(new Double(10));
    ksession.insert(new Double(11));
    ksession.insert(new Double(12));
    ksession.insert(new Double(13));
    ksession.insert(new Double(14));
    ksession.insert(new Integer(15));
    ksession.insert(new Integer(16));
    ksession.insert(new Integer(17));
    ksession.insert(new Integer(18));
    FactHandle handle = ksession.insert(new Worker());
    ksession.retract(handle);
    SessionInspector inspector = new SessionInspector(ksession);
    StatefulKnowledgeSessionInfo info = inspector.getSessionInfo();
    SessionReporter.addNamedTemplate("topten", getClass().getResourceAsStream("customreports.mvel"));
    String report = SessionReporter.generateReport("topten", info, null);
    assertNotNull(report);
}
Also used : StatefulKnowledgeSessionInfo(org.drools.kiesession.debug.StatefulKnowledgeSessionInfo) FactHandle(org.kie.api.runtime.rule.FactHandle) Cheese(org.drools.mvel.compiler.Cheese) Dimension(java.awt.Dimension) Cheesery(org.drools.mvel.compiler.Cheesery) KieBase(org.kie.api.KieBase) Worker(org.drools.mvel.compiler.Worker) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.mvel.compiler.Person) SessionInspector(org.drools.kiesession.debug.SessionInspector) Test(org.junit.Test)

Example 4 with Cheesery

use of org.drools.mvel.compiler.Cheesery in project drools by kiegroup.

the class FirstOrderLogicTest method testCollectWithNestedFromWithParams.

@Test
public void testCollectWithNestedFromWithParams() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_CollectWithNestedFrom.drl");
    KieSession workingMemory = kbase.newKieSession();
    final List results = new ArrayList();
    workingMemory.setGlobal("results", results);
    final Person bob = new Person("bob", "stilton");
    Cheesery cheesery = new Cheesery();
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("brie", 20));
    cheesery.addCheese(new Cheese("muzzarela", 8));
    cheesery.addCheese(new Cheese("stilton", 5));
    cheesery.addCheese(new Cheese("provolone", 1));
    workingMemory.insert(bob);
    workingMemory.insert(cheesery);
    workingMemory.fireAllRules();
    assertEquals(1, results.size());
    List cheeses = (List) results.get(0);
    assertEquals(2, cheeses.size());
    assertEquals(bob.getLikes(), ((Cheese) cheeses.get(0)).getType());
    assertEquals(bob.getLikes(), ((Cheese) cheeses.get(1)).getType());
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) List(java.util.List) ArrayList(java.util.ArrayList) Cheese(org.drools.mvel.compiler.Cheese) Cheesery(org.drools.mvel.compiler.Cheesery) Person(org.drools.mvel.compiler.Person) Test(org.junit.Test)

Example 5 with Cheesery

use of org.drools.mvel.compiler.Cheesery in project drools by kiegroup.

the class FirstOrderLogicTest method testCollectAfterOrCE.

@Test
public void testCollectAfterOrCE() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_OrCEFollowedByCollect.drl");
    KieSession session = kbase.newKieSession();
    // Set up facts
    final Cheesery bonFromage = new Cheesery();
    bonFromage.addCheese(new Cheese("cheddar"));
    bonFromage.addCheese(new Cheese("cheddar"));
    session.insert(bonFromage);
    int rules = session.fireAllRules();
    assertEquals(2, rules);
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Cheese(org.drools.mvel.compiler.Cheese) Cheesery(org.drools.mvel.compiler.Cheesery) Test(org.junit.Test)

Aggregations

Cheesery (org.drools.mvel.compiler.Cheesery)7 Test (org.junit.Test)7 KieBase (org.kie.api.KieBase)7 KieSession (org.kie.api.runtime.KieSession)7 Cheese (org.drools.mvel.compiler.Cheese)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Person (org.drools.mvel.compiler.Person)3 FactHandle (org.kie.api.runtime.rule.FactHandle)3 Dimension (java.awt.Dimension)2 SessionInspector (org.drools.kiesession.debug.SessionInspector)2 StatefulKnowledgeSessionInfo (org.drools.kiesession.debug.StatefulKnowledgeSessionInfo)2 Worker (org.drools.mvel.compiler.Worker)2 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)1