Search in sources :

Example 1 with SpecialString

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

the class FirstOrderLogicTest method testNestedCorelatedRulesWithForall.

@Test
public void testNestedCorelatedRulesWithForall() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_NestedCorrelatedRulesWithForall.drl");
    KieSession session = kbase.newKieSession();
    List list1 = new ArrayList();
    List list2 = new ArrayList();
    List list3 = new ArrayList();
    List list4 = new ArrayList();
    session.setGlobal("list1", list1);
    session.setGlobal("list2", list2);
    session.setGlobal("list3", list3);
    session.setGlobal("list4", list4);
    SpecialString first42 = new SpecialString("42");
    SpecialString second42 = new SpecialString("42");
    SpecialString world = new SpecialString("World");
    // System.out.println( "Inserting ..." );
    session.insert(world);
    session.insert(first42);
    session.insert(second42);
    // System.out.println( "Done." );
    // System.out.println( "Firing rules ..." );
    // check all lists are empty
    assertTrue(list1.isEmpty());
    assertTrue(list2.isEmpty());
    assertTrue(list3.isEmpty());
    assertTrue(list4.isEmpty());
    session.fireAllRules();
    // System.out.println( "Done." );
    // check first list is populated correctly
    assertEquals(0, list1.size());
    // check second list is populated correctly
    assertEquals(0, list2.size());
    // check third list is populated correctly
    assertEquals(1, list3.size());
    // check fourth list is populated correctly
    assertEquals(0, list4.size());
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) SpecialString(org.drools.mvel.compiler.SpecialString) KieSession(org.kie.api.runtime.KieSession) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with SpecialString

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

the class CrossProductTest method testCrossProductRemovingIdentityEquals.

@Test
public void testCrossProductRemovingIdentityEquals() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_CrossProductRemovingIdentityEquals.drl");
    KieSession session = kbase.newKieSession();
    final List list1 = new ArrayList();
    session.setGlobal("list1", list1);
    final SpecialString first42 = new SpecialString("42");
    final SpecialString second43 = new SpecialString("43");
    final SpecialString world = new SpecialString("World");
    session.insert(world);
    session.insert(first42);
    session.insert(second43);
    session.fireAllRules();
    assertEquals(6, list1.size());
    final List list2 = Arrays.asList("42:43", "43:42", "World:42", "42:World", "World:43", "43:World");
    Collections.sort(list1);
    Collections.sort(list2);
    assertEquals(list2, list1);
}
Also used : KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) SpecialString(org.drools.mvel.compiler.SpecialString) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 SpecialString (org.drools.mvel.compiler.SpecialString)2 Test (org.junit.Test)2 KieBase (org.kie.api.KieBase)2 KieSession (org.kie.api.runtime.KieSession)2