org.kie.internal.runtime.StatefulKnowledgeSession

Here are the examples of the java api class org.kie.internal.runtime.StatefulKnowledgeSession taken from open source projects.

1. SessionInspectorTest#testGetSessionInfo()

Project: drools
Source File: SessionInspectorTest.java
View license
@Test
public void testGetSessionInfo() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_SubNetworks.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_AccumulateWithFromChaining.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_CollectResultsBetaConstraint.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_QueryMemoryLeak.drl"), ResourceType.DRL);
    assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    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);
}

2. SessionInspectorTest#testGetSessionInfoWithCustomTemplate()

Project: drools
Source File: SessionInspectorTest.java
View license
@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;
    }
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_SubNetworks.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_AccumulateWithFromChaining.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_CollectResultsBetaConstraint.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_QueryMemoryLeak.drl"), ResourceType.DRL);
    assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    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);
}

3. MiscTest#testUnbalancedTrees()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testUnbalancedTrees() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_UnbalancedTrees.drl"));
    StatefulKnowledgeSession wm = createKnowledgeSession(kbase);
    wm.insert(new Cheese("a", 10));
    wm.insert(new Cheese("b", 10));
    wm.insert(new Cheese("c", 10));
    wm.insert(new Cheese("d", 10));
    final Cheese e = new Cheese("e", 10);
    wm.insert(e);
    wm.fireAllRules();
    assertEquals("Rule should have fired twice, seting the price to 30", 30, e.getPrice());
// success
}

4. MiscTest#testJBRules2055()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testJBRules2055() {
    KnowledgeBase kbase = loadKnowledgeBase("test_JBRules2055.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    List<String> results = new ArrayList<String>();
    ksession.setGlobal("results", results);
    ksession.insert(new Cheese("stilton"));
    ksession.insert(new Cheese("brie"));
    ksession.insert(new Cheese("muzzarella"));
    ksession.insert(new Person("bob", "stilton"));
    ksession.fireAllRules();
    assertEquals(2, results.size());
    assertEquals("stilton", results.get(0));
    assertEquals("brie", results.get(1));
}

5. MiscTest#testUnbalancedTrees()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testUnbalancedTrees() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_UnbalancedTrees.drl"));
    StatefulKnowledgeSession wm = createKnowledgeSession(kbase);
    wm.insert(new Cheese("a", 10));
    wm.insert(new Cheese("b", 10));
    wm.insert(new Cheese("c", 10));
    wm.insert(new Cheese("d", 10));
    final Cheese e = new Cheese("e", 10);
    wm.insert(e);
    wm.fireAllRules();
    assertEquals("Rule should have fired twice, seting the price to 30", 30, e.getPrice());
// success
}

6. MiscTest#testJBRules2055()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testJBRules2055() {
    KnowledgeBase kbase = loadKnowledgeBase("test_JBRules2055.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    List<String> results = new ArrayList<String>();
    ksession.setGlobal("results", results);
    ksession.insert(new Cheese("stilton"));
    ksession.insert(new Cheese("brie"));
    ksession.insert(new Cheese("muzzarella"));
    ksession.insert(new Person("bob", "stilton"));
    ksession.fireAllRules();
    assertEquals(2, results.size());
    assertEquals("stilton", results.get(0));
    assertEquals("brie", results.get(1));
}

7. AccumulateTest#testAccumulateZeroParams()

Project: drools
Source File: AccumulateTest.java
View license
@Test(timeout = 10000)
public void testAccumulateZeroParams() {
    String rule = "global java.util.List list;\n" + "rule fromIt\n" + "when\n" + "    Number( $c: intValue ) from accumulate( Integer(), count( ) )\n" + "then\n" + "    list.add( $c );\n" + "end";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(rule);
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.insert(new Integer(1));
    ksession.insert(new Integer(2));
    ksession.insert(new Integer(3));
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals(3, list.get(0));
}

8. BranchTest#executeTestWithDRL()

Project: drools
Source File: BranchTest.java
View license
private List<String> executeTestWithDRL(String drl) {
    KnowledgeBase kbase = loadKnowledgeBaseFromString(drl);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    List<String> results = new ArrayList<String>();
    ksession.setGlobal("results", results);
    Cheese stilton = new Cheese("stilton", 5);
    Cheese cheddar = new Cheese("cheddar", 7);
    Cheese brie = new Cheese("brie", 5);
    ksession.insert(stilton);
    ksession.insert(cheddar);
    ksession.insert(brie);
    ksession.fireAllRules();
    return results;
}

9. IndexingTest#testRangeIndex()

Project: drools
Source File: IndexingTest.java
View license
@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";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    ksession.insert("cheddar");
    ksession.insert("gorgonzola");
    ksession.insert("stilton");
    ksession.insert(new Cheese("gorgonzola", 10));
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
}

10. IndexingTest#testRangeIndex2()

Project: drools
Source File: IndexingTest.java
View license
@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";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    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();
}

11. MarshallingTest#testAccumulate2()

Project: drools
Source File: MarshallingTest.java
View license
@Test
public void testAccumulate2() throws Exception {
    String str = "package org.drools\n" + "\n" + "import org.drools.compiler.Message\n" + "\n" + "rule MyRule\n" + "  when\n" + "    Number( intValue >= 5 ) from accumulate ( m: Message( ), count( m ) )\n" + "  then\n" + "    System.out.println(\"Found messages\");\n" + "end\n";
    KnowledgeBase kBase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kBase.newStatefulKnowledgeSession();
    ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
    ksession.insert(new Message());
    ksession.insert(new Message());
    ksession.insert(new Message());
    ksession.insert(new Message());
    ksession.insert(new Message());
    ((InternalWorkingMemory) ksession).flushPropagations();
    assertEquals(1, ((InternalAgenda) ksession.getAgenda()).agendaSize());
}

12. Misc2Test#testContainsOnString()

Project: drools
Source File: Misc2Test.java
View license
@Test
public void testContainsOnString() {
    // DROOLS-388
    String str = "global java.util.List list;\n" + "rule R1 when\n" + "    $s : String( this contains 'bcd' )\n" + "then\n" + "    list.add( $s );\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    List<Integer> list = new ArrayList<Integer>();
    ksession.setGlobal("list", list);
    ksession.insert("abcde");
    ksession.insert("bcdef");
    ksession.insert("cdefg");
    ksession.fireAllRules();
    assertEquals(2, list.size());
    assertTrue(list.containsAll(Arrays.asList("abcde", "bcdef")));
}

13. MiscTest#testExplicitAnd()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testExplicitAnd() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase("test_ExplicitAnd.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.insert(new Message("hola"));
    ksession.fireAllRules();
    assertEquals(0, list.size());
    ksession.insert(new Cheese("brie", 33));
    ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
    ksession.fireAllRules();
    assertEquals(1, ((List) ksession.getGlobal("list")).size());
}

14. MiscTest#testNullHashing()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testNullHashing() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_NullHashing.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List results = new ArrayList();
    ksession.setGlobal("results", results);
    ksession.insert(new Cheese("stilton", 15));
    ksession.insert(new Cheese("", 10));
    ksession.insert(new Cheese(null, 8));
    ksession.fireAllRules();
    assertEquals(3, results.size());
}

15. MiscTest#testImportColision()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testImportColision() throws Exception {
    Collection<KnowledgePackage> kpkgs1 = loadKnowledgePackages("nested1.drl");
    Collection<KnowledgePackage> kpkgs2 = loadKnowledgePackages("nested2.drl");
    KnowledgeBase kbase = loadKnowledgeBase();
    kbase.addKnowledgePackages(kpkgs1);
    kbase.addKnowledgePackages(kpkgs2);
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    kbase = SerializationHelper.serializeObject(kbase);
    ksession.insert(new FirstClass());
    ksession.insert(new SecondClass());
    ksession.insert(new FirstClass.AlternativeKey());
    ksession.insert(new SecondClass.AlternativeKey());
    ksession.fireAllRules();
}

16. MiscTest#testAlphaEvalWithOrCE()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testAlphaEvalWithOrCE() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_AlphaEvalWithOrCE.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    FactA a = new FactA();
    a.setField1("a value");
    ksession.insert(a);
    ksession.insert(new FactB());
    ksession.insert(new FactC());
    ksession.fireAllRules();
    assertEquals("should not have fired", 0, list.size());
}

17. MiscTest#testModifyRetractAndModifyInsert()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testModifyRetractAndModifyInsert() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_ModifyRetractInsert.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    Person bob = new Person("Bob");
    bob.setStatus("hungry");
    ksession.insert(bob);
    ksession.insert(new Cheese());
    ksession.insert(new Cheese());
    ksession.fireAllRules(2);
    assertEquals("should have fired only once", 1, list.size());
}

18. MiscTest#testDeepNestedConstraints()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testDeepNestedConstraints() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_DeepNestedConstraints.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    ksession.insert(new Person("bob", "muzzarela"));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("muzzarela", 80));
    ksession.fireAllRules();
    assertEquals("should have fired twice", 2, list.size());
}

19. MiscTest#testModifyWithLockOnActive()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testModifyWithLockOnActive() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_ModifyWithLockOnActive.drl"));
    StatefulKnowledgeSession session = createKnowledgeSession(kbase);
    final List results = new ArrayList();
    session.setGlobal("results", results);
    final Person bob = new Person("Bob", 15);
    final Person mark = new Person("Mark", 16);
    final Person michael = new Person("Michael", 14);
    session.insert(bob);
    session.insert(mark);
    session.insert(michael);
    session.getAgenda().getAgendaGroup("feeding").setFocus();
    session.fireAllRules(5);
    assertEquals(2, ((List) session.getGlobal("results")).size());
}

20. MiscTest#testAddRemoveListeners()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testAddRemoveListeners() throws Exception {
    final KnowledgeBase kbase = loadKnowledgeBase("test_AddRemoveListeners.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    // creating listener as a jmock proxy
    final RuleRuntimeEventListener wmeListener = mock(RuleRuntimeEventListener.class);
    ksession.addEventListener(wmeListener);
    // listener will be notified of both facts insertion
    ksession.insert(new Cheese("stilton"));
    ksession.insert(wmeListener);
    // firing rules will remove listener
    ksession.fireAllRules();
    // inserting another object into the working memory, listener should NOT be notified,
    // since it is no longer listening.
    ksession.insert(new Cheese("brie"));
    verify(wmeListener, times(2)).objectInserted(any(org.kie.api.event.rule.ObjectInsertedEvent.class));
}

21. NamedConsequencesTest#executeTestWithDRL()

Project: drools
Source File: NamedConsequencesTest.java
View license
private List<String> executeTestWithDRL(String drl) {
    KnowledgeBase kbase = loadKnowledgeBaseFromString(drl);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    List<String> results = new ArrayList<String>();
    ksession.setGlobal("results", results);
    Cheese stilton = new Cheese("stilton", 5);
    Cheese cheddar = new Cheese("cheddar", 7);
    Cheese brie = new Cheese("brie", 5);
    ksession.insert(stilton);
    ksession.insert(cheddar);
    ksession.insert(brie);
    ksession.fireAllRules();
    return results;
}

22. AccumulateTest#testAccumulateZeroParams()

Project: drools
Source File: AccumulateTest.java
View license
@Test(timeout = 10000)
public void testAccumulateZeroParams() {
    String rule = "global java.util.List list;\n" + "rule fromIt\n" + "when\n" + "    Number( $c: intValue ) from accumulate( Integer(), count( ) )\n" + "then\n" + "    list.add( $c );\n" + "end";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(rule);
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.insert(new Integer(1));
    ksession.insert(new Integer(2));
    ksession.insert(new Integer(3));
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals(3, list.get(0));
}

23. MiscTest#testExplicitAnd()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testExplicitAnd() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase("test_ExplicitAnd.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.insert(new Message("hola"));
    ksession.fireAllRules();
    assertEquals(0, list.size());
    ksession.insert(new Cheese("brie", 33));
    ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
    ksession.fireAllRules();
    assertEquals(1, ((List) ksession.getGlobal("list")).size());
}

24. MiscTest#testNullHashing()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testNullHashing() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_NullHashing.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List results = new ArrayList();
    ksession.setGlobal("results", results);
    ksession.insert(new Cheese("stilton", 15));
    ksession.insert(new Cheese("", 10));
    ksession.insert(new Cheese(null, 8));
    ksession.fireAllRules();
    assertEquals(3, results.size());
}

25. MiscTest#testImportColision()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testImportColision() throws Exception {
    Collection<KnowledgePackage> kpkgs1 = loadKnowledgePackages("nested1.drl");
    Collection<KnowledgePackage> kpkgs2 = loadKnowledgePackages("nested2.drl");
    KnowledgeBase kbase = loadKnowledgeBase();
    kbase.addKnowledgePackages(kpkgs1);
    kbase.addKnowledgePackages(kpkgs2);
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    kbase = SerializationHelper.serializeObject(kbase);
    ksession.insert(new FirstClass());
    ksession.insert(new SecondClass());
    ksession.insert(new FirstClass.AlternativeKey());
    ksession.insert(new SecondClass.AlternativeKey());
    ksession.fireAllRules();
}

26. MiscTest#testAlphaEvalWithOrCE()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testAlphaEvalWithOrCE() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_AlphaEvalWithOrCE.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    FactA a = new FactA();
    a.setField1("a value");
    ksession.insert(a);
    ksession.insert(new FactB());
    ksession.insert(new FactC());
    ksession.fireAllRules();
    assertEquals("should not have fired", 0, list.size());
}

27. MiscTest#testModifyRetractAndModifyInsert()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testModifyRetractAndModifyInsert() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_ModifyRetractInsert.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    Person bob = new Person("Bob");
    bob.setStatus("hungry");
    ksession.insert(bob);
    ksession.insert(new Cheese());
    ksession.insert(new Cheese());
    ksession.fireAllRules(2);
    assertEquals("should have fired only once", 1, list.size());
}

28. MiscTest#testDeepNestedConstraints()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testDeepNestedConstraints() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_DeepNestedConstraints.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    ksession.insert(new Person("bob", "muzzarela"));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("muzzarela", 80));
    ksession.fireAllRules();
    assertEquals("should have fired twice", 2, list.size());
}

29. MiscTest#testModifyWithLockOnActive()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testModifyWithLockOnActive() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_ModifyWithLockOnActive.drl"));
    StatefulKnowledgeSession session = createKnowledgeSession(kbase);
    final List results = new ArrayList();
    session.setGlobal("results", results);
    final Person bob = new Person("Bob", 15);
    final Person mark = new Person("Mark", 16);
    final Person michael = new Person("Michael", 14);
    session.insert(bob);
    session.insert(mark);
    session.insert(michael);
    session.getAgenda().getAgendaGroup("feeding").setFocus();
    session.fireAllRules(5);
    assertEquals(2, ((List) session.getGlobal("results")).size());
}

30. MiscTest#testAddRemoveListeners()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testAddRemoveListeners() throws Exception {
    final KnowledgeBase kbase = loadKnowledgeBase("test_AddRemoveListeners.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    // creating listener as a jmock proxy
    final RuleRuntimeEventListener wmeListener = mock(RuleRuntimeEventListener.class);
    ksession.addEventListener(wmeListener);
    // listener will be notified of both facts insertion
    ksession.insert(new Cheese("stilton"));
    ksession.insert(wmeListener);
    // firing rules will remove listener
    ksession.fireAllRules();
    // inserting another object into the working memory, listener should NOT be notified,
    // since it is no longer listening.
    ksession.insert(new Cheese("brie"));
    verify(wmeListener, times(2)).objectInserted(any(org.kie.api.event.rule.ObjectInsertedEvent.class));
}

31. TraitTest#traitDeclared()

Project: drools
Source File: TraitTest.java
View license
@Test(timeout = 10000)
public void traitDeclared() {
    List<Integer> trueTraits = new ArrayList<Integer>();
    List<Integer> untrueTraits = new ArrayList<Integer>();
    StatefulKnowledgeSession ks = getSession("org/drools/compiler/factmodel/traits/testDeclaredFactTrait.drl");
    TraitFactory.setMode(mode, ks.getKieBase());
    ks.setGlobal("trueTraits", trueTraits);
    ks.setGlobal("untrueTraits", untrueTraits);
    ks.fireAllRules();
    ks.dispose();
    assertTrue(trueTraits.contains(1));
    assertFalse(trueTraits.contains(2));
    assertTrue(untrueTraits.contains(2));
    assertFalse(untrueTraits.contains(1));
}

32. TraitTest#traitPojo()

Project: drools
Source File: TraitTest.java
View license
@Test(timeout = 10000)
public void traitPojo() {
    List<Integer> trueTraits = new ArrayList<Integer>();
    List<Integer> untrueTraits = new ArrayList<Integer>();
    StatefulKnowledgeSession session = getSession("org/drools/compiler/factmodel/traits/testPojoFactTrait.drl");
    TraitFactory.setMode(mode, session.getKieBase());
    session.setGlobal("trueTraits", trueTraits);
    session.setGlobal("untrueTraits", untrueTraits);
    session.fireAllRules();
    session.dispose();
    assertTrue(trueTraits.contains(1));
    assertFalse(trueTraits.contains(2));
    assertTrue(untrueTraits.contains(2));
    assertFalse(untrueTraits.contains(1));
}

33. TraitTest#isAWithBackChaining()

Project: drools
Source File: TraitTest.java
View license
@Test(timeout = 10000)
public void isAWithBackChaining() {
    String source = "org/drools/compiler/factmodel/traits/testTraitIsAWithBC.drl";
    StatefulKnowledgeSession ksession = getSession(source);
    TraitFactory.setMode(mode, ksession.getKieBase());
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.fireAllRules();
    ksession.insert("Como");
    ksession.fireAllRules();
    assertTrue(list.contains("Italy"));
}

34. InlineCastTest#testInlineCast()

Project: drools
Source File: InlineCastTest.java
View license
@Test
public void testInlineCast() throws Exception {
    String str = "import org.drools.compiler.*;\n" + "rule R1 when\n" + "   Person( name == \"mark\", address#LongAddress.country == \"uk\" )\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    Person mark1 = new Person("mark");
    mark1.setAddress(new LongAddress("uk"));
    ksession.insert(mark1);
    Person mark2 = new Person("mark");
    ksession.insert(mark2);
    Person mark3 = new Person("mark");
    mark3.setAddress(new Address());
    ksession.insert(mark3);
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
}

35. InlineCastTest#testInlineCastWithBinding()

Project: drools
Source File: InlineCastTest.java
View license
@Test
public void testInlineCastWithBinding() throws Exception {
    String str = "import org.drools.compiler.*;\n" + "rule R1 when\n" + "   Person( name == \"mark\", $country : address#LongAddress.country == \"uk\" )\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    Person mark1 = new Person("mark");
    mark1.setAddress(new LongAddress("uk"));
    ksession.insert(mark1);
    Person mark2 = new Person("mark");
    ksession.insert(mark2);
    Person mark3 = new Person("mark");
    mark3.setAddress(new Address());
    ksession.insert(mark3);
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
}

36. InlineCastTest#testInlineCastOnlyBinding()

Project: drools
Source File: InlineCastTest.java
View license
@Test
public void testInlineCastOnlyBinding() throws Exception {
    String str = "import org.drools.compiler.*;\n" + "rule R1 when\n" + "   Person( name == \"mark\", $country : address#LongAddress.country )\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    Person mark1 = new Person("mark");
    mark1.setAddress(new LongAddress("uk"));
    ksession.insert(mark1);
    Person mark2 = new Person("mark");
    ksession.insert(mark2);
    Person mark3 = new Person("mark");
    mark3.setAddress(new Address());
    ksession.insert(mark3);
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
}

37. InlineCastTest#testInferredCast()

Project: drools
Source File: InlineCastTest.java
View license
@Test
public void testInferredCast() throws Exception {
    String str = "import org.drools.compiler.*;\n" + "rule R1 when\n" + "   Person( name == \"mark\", address instanceof LongAddress, address.country == \"uk\" )\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    Person mark1 = new Person("mark");
    mark1.setAddress(new LongAddress("uk"));
    ksession.insert(mark1);
    Person mark2 = new Person("mark");
    ksession.insert(mark2);
    Person mark3 = new Person("mark");
    mark3.setAddress(new Address());
    ksession.insert(mark3);
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
}

38. InlineCastTest#testInlineCastWithNestedAcccesAndNullSafeDereferencing()

Project: drools
Source File: InlineCastTest.java
View license
@Test
public void testInlineCastWithNestedAcccesAndNullSafeDereferencing() throws Exception {
    String str = "import org.drools.compiler.*;\n" + "rule R1 when\n" + " Person( name == \"mark\", address#LongAddress.country!.length == 2 )\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    Person mark1 = new Person("mark");
    mark1.setAddress(new LongAddress("uk"));
    ksession.insert(mark1);
    Person mark2 = new Person("mark");
    ksession.insert(mark2);
    Person mark3 = new Person("mark");
    mark3.setAddress(new LongAddress(null));
    ksession.insert(mark3);
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
}

39. DeclarativeAgendaTest#testApplyBlockerFirst()

Project: drools
Source File: DeclarativeAgendaTest.java
View license
//(timeout=10000)
@Test
public void testApplyBlockerFirst() {
    StatefulKnowledgeSession ksession = getStatefulKnowledgeSession();
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    FactHandle go2 = ksession.insert("go2");
    //((InternalWorkingMemory) ksession).flushPropagations();
    FactHandle go1 = ksession.insert("go1");
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertTrue(list.contains("rule1:go2"));
    list.clear();
    ksession.retract(go2);
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertTrue(list.contains("rule1:go1"));
}

40. DeclarativeAgendaTest#testApplyBlockerSecond()

Project: drools
Source File: DeclarativeAgendaTest.java
View license
@Test(timeout = 10000)
public void testApplyBlockerSecond() {
    StatefulKnowledgeSession ksession = getStatefulKnowledgeSession();
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    FactHandle go1 = ksession.insert("go1");
    FactHandle go2 = ksession.insert("go2");
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertTrue(list.contains("rule1:go2"));
    list.clear();
    ksession.retract(go2);
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertTrue(list.contains("rule1:go1"));
}

41. DslTest#doTest()

Project: drools
Source File: DslTest.java
View license
private List doTest(String dsl, String drl) {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(dsl.getBytes()), ResourceType.DSL);
    kbuilder.add(ResourceFactory.newByteArrayResource(drl.getBytes()), ResourceType.DSLR);
    assertFalse(kbuilder.hasErrors());
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.insert(new Person("Mario", 38));
    ksession.fireAllRules();
    ksession.dispose();
    return list;
}

42. DynamicRulesTest#testDynamicRules()

Project: drools
Source File: DynamicRulesTest.java
View license
@Test(timeout = 10000)
public void testDynamicRules() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase();
    StatefulKnowledgeSession session = createKnowledgeSession(kbase);
    final Cheese a = new Cheese("stilton", 10);
    final Cheese b = new Cheese("stilton", 15);
    final Cheese c = new Cheese("stilton", 20);
    session.insert(a);
    session.insert(b);
    session.insert(c);
    Collection<KnowledgePackage> kpkgs = SerializationHelper.serializeObject(loadKnowledgePackages("test_DynamicRules.drl"));
    kbase.addKnowledgePackages(kpkgs);
    kbase = SerializationHelper.serializeObject(kbase);
    session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
    session.fireAllRules();
}

43. FirstOrderLogicTest#testExistsWithBinding()

Project: drools
Source File: FirstOrderLogicTest.java
View license
@Test
public void testExistsWithBinding() throws Exception {
    KieBase kbase = loadKnowledgeBase("test_ExistsWithBindings.drl");
    StatefulKnowledgeSession wm = createKnowledgeSession((KnowledgeBase) kbase);
    final List list = new ArrayList();
    wm.setGlobal("results", list);
    final Cheese c = new Cheese("stilton", 10);
    final Person p = new Person("Mark", "stilton");
    wm.insert(c);
    wm.insert(p);
    wm.fireAllRules();
    assertTrue(list.contains(c.getType()));
    assertEquals(1, list.size());
}

44. AddRemoveRulesTest#testRemoveWithSplitStartAtLianAndFollowedBySubNetworkNoSharing()

Project: drools
Source File: AddRemoveRulesTest.java
View license
@Test
public void testRemoveWithSplitStartAtLianAndFollowedBySubNetworkNoSharing() {
    final String packageName = "pk1";
    final String rule1 = "package " + packageName + ";" + "global java.util.concurrent.atomic.AtomicInteger globalInt\n" + "rule R1 when\n" + "    $s : String()\n" + "    Integer()\n" + "    exists Integer() from globalInt.get()\n" + "then\n" + "end\n";
    final StatefulKnowledgeSession session = buildSessionInSteps(rule1);
    session.setGlobal("globalInt", new AtomicInteger(0));
    session.insert(1);
    session.insert("1");
    session.fireAllRules();
    session.getKieBase().removeKnowledgePackage(packageName);
}

45. IndexingTest#testNotNodeModifyRight()

Project: drools
Source File: IndexingTest.java
View license
@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";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    ksession.insert(new Person("A", 10));
    ksession.insert(new Cheese("C1", 20));
    ksession.insert(new Cheese("C2", 8));
    assertEquals(2, ksession.fireAllRules());
    ksession.dispose();
}

46. IndexingTest#testRange()

Project: drools
Source File: IndexingTest.java
View license
@Test(timeout = 10000)
public void testRange() {
    String str = "import org.drools.compiler.*;\n" + "rule R1 salience 10 when\n" + "   Person( $age : age, $doubleAge : doubleAge )\n" + "   not Cheese( this.price > $age && < $doubleAge )\n" + "then\n" + "   System.out.println( $age );\n" + "end\n" + "rule R3 salience 5 when\n" + "   $c : Cheese( price == 15 )\n" + "then\n" + "   System.out.println( \"modify\" );\n" + "   modify($c) { setPrice(8); }\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    ksession.insert(new Person("A", 10));
    ksession.insert(new Cheese("C1", 30));
    ksession.insert(new Cheese("C2", 15));
    assertEquals(2, ksession.fireAllRules());
    ksession.dispose();
}

47. IntegrationInterfacesTest#testGlobals()

View license
@SuppressWarnings("unchecked")
@Test
public void testGlobals() throws Exception {
    final KnowledgeBase kbase = getKnowledgeBase("globals_rule_test.drl");
    StatefulKnowledgeSession 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));
}

48. IntegrationInterfacesTest#testChannels()

View license
@Test
public void testChannels() throws IOException, ClassNotFoundException {
    KnowledgeBase kbase = getKnowledgeBase("test_Channels.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    Channel someChannel = mock(Channel.class);
    ksession.registerChannel("someChannel", someChannel);
    ksession.insert(new Cheese("brie", 30));
    ksession.insert(new Cheese("stilton", 5));
    ksession.fireAllRules();
    verify(someChannel).send("brie");
    verify(someChannel, never()).send("stilton");
}

49. Misc2Test#testJoinNoLoop()

Project: drools
Source File: Misc2Test.java
View license
@Test
public void testJoinNoLoop() {
    // BZ-1034094
    String str = "import org.drools.compiler.Person\n" + "rule R no-loop\n" + "when\n" + "  String()\n" + "  $p : Person( $age : age )\n" + "then\n" + "    modify($p) { setAge( $age + 1 ) }\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    Person mario = new Person("Mario", 38);
    ksession.insert("a");
    ksession.insert("b");
    ksession.insert(mario);
    ksession.fireAllRules();
    assertEquals(40, mario.getAge());
}

50. Misc2Test#testFieldPrecedenceOverGlobal()

Project: drools
Source File: Misc2Test.java
View license
@Test
public void testFieldPrecedenceOverGlobal() throws Exception {
    String str = "import " + EvallerBean.class.getCanonicalName() + ";\n" + "global " + Evaller.class.getCanonicalName() + " evaller;\n" + "global java.util.List list;\n" + "rule R1 when\n" + "    $s : EvallerBean( evaller.size() == 1 )\n" + "then\n" + "    list.add( 42 );\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    List<Integer> list = new ArrayList<Integer>();
    ksession.setGlobal("list", list);
    ksession.setGlobal("evaller", new Evaller());
    ksession.insert(new EvallerBean());
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals(42, (int) list.get(0));
}

51. MiscTest#testNullFieldOnCompositeSink()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testNullFieldOnCompositeSink() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase("test_NullFieldOnCompositeSink.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.insert(new Attribute());
    ksession.insert(new Message());
    ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
    ksession.fireAllRules();
    assertEquals(1, ((List) ksession.getGlobal("list")).size());
    assertEquals("X", ((List) ksession.getGlobal("list")).get(0));
}

52. MiscTest#testHelloWorld()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testHelloWorld() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase("HelloWorld.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    // go !
    final Message message = new Message("hola");
    message.addToList("hello");
    message.setNumber(42);
    ksession.insert(message);
    ksession.insert("boo");
    //        ksession    = SerializationHelper.serializeObject(ksession);
    ksession.fireAllRules();
    assertTrue(message.isFired());
    assertEquals(message, ((List) ksession.getGlobal("list")).get(0));
}

53. MiscTest#testEval()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testEval() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase("eval_rule_test.drl");
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    ksession.setGlobal("five", new Integer(5));
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    final Cheese stilton = new Cheese("stilton", 5);
    ksession.insert(stilton);
    ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
    ksession.fireAllRules();
    assertEquals(stilton, ((List) ksession.getGlobal("list")).get(0));
}

54. MiscTest#testNullConstraint()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testNullConstraint() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase("null_constraint.drl");
    StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();
    final List foo = new ArrayList();
    session.setGlobal("messages", foo);
    final PersonInterface p1 = new Person(null, "food", 40);
    final Primitives p2 = new Primitives();
    p2.setArrayAttribute(null);
    session.insert(p1);
    session.insert(p2);
    session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
    session.fireAllRules();
    assertEquals(2, ((List) session.getGlobal("messages")).size());
}

55. MiscTest#testEmptyIdentifier()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testEmptyIdentifier() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_emptyIdentifier.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List result = new ArrayList();
    ksession.setGlobal("results", result);
    final Person person = new Person("bob");
    final Cheese cheese = new Cheese("brie", 10);
    ksession.insert(person);
    ksession.insert(cheese);
    ksession.fireAllRules();
    assertEquals(4, result.size());
}

56. MiscTest#testImplicitDeclarations()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testImplicitDeclarations() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_implicitDeclarations.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List results = new ArrayList();
    ksession.setGlobal("results", results);
    ksession.setGlobal("factor", new Double(1.2));
    final Cheese cheese = new Cheese("stilton", 10);
    ksession.insert(cheese);
    ksession.fireAllRules();
    assertEquals(1, results.size());
}

57. MiscTest#testNullBinding()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testNullBinding() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_nullBindings.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    ksession.insert(new Person("bob"));
    ksession.insert(new Person(null));
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals("OK", list.get(0));
}

58. MiscTest#testAutomaticBindings()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testAutomaticBindings() throws Exception {
    final KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_AutoBindings.drl"));
    final StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    final Person bob = new Person("bob", "stilton");
    final Cheese stilton = new Cheese("stilton", 12);
    ksession.insert(bob);
    ksession.insert(stilton);
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals(bob, list.get(0));
}

59. MiscTest#testQualifiedFieldReference()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testQualifiedFieldReference() throws Exception {
    final KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_QualifiedFieldReference.drl"));
    final StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    final Person bob = new Person("bob", "stilton");
    final Cheese stilton = new Cheese("stilton", 12);
    ksession.insert(bob);
    ksession.insert(stilton);
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals(bob, list.get(0));
}

60. MiscTest#doModifyTest()

Project: drools
Source File: MiscTest.java
View license
private void doModifyTest(String drlResource) throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase(drlResource));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    Person bob = new Person("Bob");
    bob.setStatus("hungry");
    Cheese c = new Cheese();
    ksession.insert(bob);
    ksession.insert(c);
    ksession.fireAllRules();
    assertEquals(10, c.getPrice());
    assertEquals("fine", bob.getStatus());
}

61. MiscTest#testOrCE()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testOrCE() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_OrCE.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Person("bob"));
    ksession.fireAllRules();
    assertEquals("should have fired once", 1, list.size());
}

62. MiscTest#testJittingConstraintWithInvocationOnLiteral()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testJittingConstraintWithInvocationOnLiteral() {
    String str = "package com.sample\n" + "import org.drools.compiler.Person\n" + "rule XXX when\n" + "  Person( name.toString().toLowerCase().contains( \"mark\".toString().toLowerCase() ) )\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    ksession.insert(new Person("mark", 37));
    ksession.insert(new Person("mario", 38));
    ksession.fireAllRules();
    ksession.dispose();
}

63. MiscTest#testJittingMethodWithCharSequenceArg()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testJittingMethodWithCharSequenceArg() {
    String str = "package com.sample\n" + "import org.drools.compiler.Person\n" + "rule XXX when\n" + "  Person( $n : name, $n.contains( \"mark\" ) )\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    ksession.insert(new Person("mark", 37));
    ksession.insert(new Person("mario", 38));
    ksession.fireAllRules();
    ksession.dispose();
}

64. MiscTest#testFromNodeWithMultipleBetas()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testFromNodeWithMultipleBetas() throws Exception {
    String str = "import org.drools.compiler.*;\n" + "rule R1 when\n" + "   $p : Person( $name : name, $addresses : addresses )\n" + "   $c : Cheese( $type: type == $name )\n" + "   $a : Address( street == $type, suburb == $name ) from $addresses\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    Person p = new Person("x");
    p.addAddress(new Address("x", "x", "x"));
    p.addAddress(new Address("y", "y", "y"));
    ksession.insert(p);
    ksession.insert(new Cheese("x"));
    ksession.fireAllRules();
    ksession.dispose();
}

65. NestedAccessorsTest#testNestedAccessorWithInlineCast()

Project: drools
Source File: NestedAccessorsTest.java
View license
@Test
public void testNestedAccessorWithInlineCast() throws Exception {
    String str = "import org.drools.compiler.*;\n" + "rule R1 when\n" + "   Person( name == \"mark\", address#LongAddress.(country == \"uk\", suburb == \"suburb\") )\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    Person mark1 = new Person("mark");
    mark1.setAddress(new LongAddress("street", "suburb", "zipCode", "uk"));
    ksession.insert(mark1);
    Person mark2 = new Person("mark");
    ksession.insert(mark2);
    Person mark3 = new Person("mark");
    mark3.setAddress(new Address("street", "suburb", "zipCode"));
    ksession.insert(mark3);
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
}

66. ExternalSpreadsheetCompilerTest#testIntegration()

View license
@Test
public void testIntegration() throws Exception {
    final ExternalSpreadsheetCompiler converter = new ExternalSpreadsheetCompiler();
    final String drl = converter.compile("/data/IntegrationExampleTest.xls", "/templates/test_integration.drl", 18, 3);
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(drl.getBytes()), ResourceType.DRL);
    assertFalse(kbuilder.hasErrors());
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    StatefulKnowledgeSession kSession = kbase.newStatefulKnowledgeSession();
    //ASSERT AND FIRE
    kSession.insert(new Cheese("stilton", 42));
    kSession.insert(new Person("michael", "stilton", 42));
    List<String> list = new ArrayList<String>();
    kSession.setGlobal("list", list);
    kSession.fireAllRules();
    assertEquals(1, list.size());
}

67. MapPersistenceTest#dontCreateMoreSessionsThanNecessary()

Project: drools
Source File: MapPersistenceTest.java
View license
@Test
public void dontCreateMoreSessionsThanNecessary() {
    long initialNumberOfSavedSessions = getSavedSessionsCount();
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    StatefulKnowledgeSession crmPersistentSession = createSession(kbase);
    long ksessionId = crmPersistentSession.getIdentifier();
    crmPersistentSession.fireAllRules();
    crmPersistentSession = disposeAndReloadSession(crmPersistentSession, kbase);
    Assert.assertEquals(ksessionId, crmPersistentSession.getIdentifier());
    ksessionId = crmPersistentSession.getIdentifier();
    crmPersistentSession.fireAllRules();
    crmPersistentSession = disposeAndReloadSession(crmPersistentSession, kbase);
    crmPersistentSession.fireAllRules();
    Assert.assertEquals(initialNumberOfSavedSessions + 1, getSavedSessionsCount());
    crmPersistentSession.dispose();
}

68. AccumulateTest#testAccumulateInnerClass()

Project: drools
Source File: AccumulateTest.java
View license
@Test(timeout = 10000)
public void testAccumulateInnerClass() throws Exception {
    // read in the source
    KnowledgeBase kbase = loadKnowledgeBase("test_AccumulateInnerClass.drl");
    StatefulKnowledgeSession wm = createKnowledgeSession(kbase);
    final List<?> results = new ArrayList<Object>();
    wm.setGlobal("results", results);
    wm.insert(new OuterClass.InnerClass(10));
    wm.insert(new OuterClass.InnerClass(5));
    wm.fireAllRules();
    assertEquals(15, results.get(0));
}

69. DeclarativeAgendaTest#testApplyBlockerFirst()

Project: drools
Source File: DeclarativeAgendaTest.java
View license
@Test(timeout = 10000)
public void testApplyBlockerFirst() {
    StatefulKnowledgeSession ksession = getStatefulKnowledgeSession();
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    FactHandle go2 = ksession.insert("go2");
    FactHandle go1 = ksession.insert("go1");
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertTrue(list.contains("rule1:go2"));
    list.clear();
    ksession.retract(go2);
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertTrue(list.contains("rule1:go1"));
}

70. DeclarativeAgendaTest#testApplyBlockerSecond()

Project: drools
Source File: DeclarativeAgendaTest.java
View license
//(timeout=10000)
@Test
public void testApplyBlockerSecond() {
    StatefulKnowledgeSession ksession = getStatefulKnowledgeSession();
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    FactHandle go1 = ksession.insert("go1");
    FactHandle go2 = ksession.insert("go2");
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertTrue(list.contains("rule1:go2"));
    list.clear();
    ksession.retract(go2);
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertTrue(list.contains("rule1:go1"));
}

71. DynamicRulesTest#testDynamicRules()

Project: drools
Source File: DynamicRulesTest.java
View license
@Test(timeout = 10000)
public void testDynamicRules() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase();
    StatefulKnowledgeSession session = createKnowledgeSession(kbase);
    final Cheese a = new Cheese("stilton", 10);
    final Cheese b = new Cheese("stilton", 15);
    final Cheese c = new Cheese("stilton", 20);
    session.insert(a);
    session.insert(b);
    session.insert(c);
    Collection<KnowledgePackage> kpkgs = SerializationHelper.serializeObject(loadKnowledgePackages("test_DynamicRules.drl"));
    kbase.addKnowledgePackages(kpkgs);
    kbase = SerializationHelper.serializeObject(kbase);
    session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
    session.fireAllRules();
}

72. MiscTest#testNullFieldOnCompositeSink()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testNullFieldOnCompositeSink() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase("test_NullFieldOnCompositeSink.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.insert(new Attribute());
    ksession.insert(new Message());
    ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
    ksession.fireAllRules();
    assertEquals(1, ((List) ksession.getGlobal("list")).size());
    assertEquals("X", ((List) ksession.getGlobal("list")).get(0));
}

73. MiscTest#testHelloWorld()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testHelloWorld() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase("HelloWorld.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    // go !
    final Message message = new Message("hola");
    message.addToList("hello");
    message.setNumber(42);
    ksession.insert(message);
    ksession.insert("boo");
    //        ksession    = SerializationHelper.serializeObject(ksession);
    ksession.fireAllRules();
    assertTrue(message.isFired());
    assertEquals(message, ((List) ksession.getGlobal("list")).get(0));
}

74. MiscTest#testEval()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testEval() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase("eval_rule_test.drl");
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    ksession.setGlobal("five", new Integer(5));
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    final Cheese stilton = new Cheese("stilton", 5);
    ksession.insert(stilton);
    ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
    ksession.fireAllRules();
    assertEquals(stilton, ((List) ksession.getGlobal("list")).get(0));
}

75. MiscTest#testNullConstraint()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testNullConstraint() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase("null_constraint.drl");
    StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();
    final List foo = new ArrayList();
    session.setGlobal("messages", foo);
    final PersonInterface p1 = new Person(null, "food", 40);
    final Primitives p2 = new Primitives();
    p2.setArrayAttribute(null);
    session.insert(p1);
    session.insert(p2);
    session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
    session.fireAllRules();
    assertEquals(2, ((List) session.getGlobal("messages")).size());
}

76. MiscTest#testEmptyIdentifier()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testEmptyIdentifier() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_emptyIdentifier.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List result = new ArrayList();
    ksession.setGlobal("results", result);
    final Person person = new Person("bob");
    final Cheese cheese = new Cheese("brie", 10);
    ksession.insert(person);
    ksession.insert(cheese);
    ksession.fireAllRules();
    assertEquals(4, result.size());
}

77. MiscTest#testImplicitDeclarations()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testImplicitDeclarations() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_implicitDeclarations.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List results = new ArrayList();
    ksession.setGlobal("results", results);
    ksession.setGlobal("factor", new Double(1.2));
    final Cheese cheese = new Cheese("stilton", 10);
    ksession.insert(cheese);
    ksession.fireAllRules();
    assertEquals(1, results.size());
}

78. MiscTest#testNullBinding()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testNullBinding() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_nullBindings.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    ksession.insert(new Person("bob"));
    ksession.insert(new Person(null));
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals("OK", list.get(0));
}

79. MiscTest#testAutomaticBindings()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testAutomaticBindings() throws Exception {
    final KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_AutoBindings.drl"));
    final StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    final Person bob = new Person("bob", "stilton");
    final Cheese stilton = new Cheese("stilton", 12);
    ksession.insert(bob);
    ksession.insert(stilton);
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals(bob, list.get(0));
}

80. MiscTest#testQualifiedFieldReference()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testQualifiedFieldReference() throws Exception {
    final KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_QualifiedFieldReference.drl"));
    final StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    final Person bob = new Person("bob", "stilton");
    final Cheese stilton = new Cheese("stilton", 12);
    ksession.insert(bob);
    ksession.insert(stilton);
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals(bob, list.get(0));
}

81. MiscTest#doModifyTest()

Project: drools
Source File: MiscTest.java
View license
private void doModifyTest(String drlResource) throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase(drlResource));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    Person bob = new Person("Bob");
    bob.setStatus("hungry");
    Cheese c = new Cheese();
    ksession.insert(bob);
    ksession.insert(c);
    ksession.fireAllRules();
    assertEquals(10, c.getPrice());
    assertEquals("fine", bob.getStatus());
}

82. MiscTest#testOrCE()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testOrCE() throws Exception {
    KnowledgeBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_OrCE.drl"));
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List list = new ArrayList();
    ksession.setGlobal("results", list);
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Person("bob"));
    ksession.fireAllRules();
    assertEquals("should have fired once", 1, list.size());
}

83. MiscTest#testJittingConstraintWithInvocationOnLiteral()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testJittingConstraintWithInvocationOnLiteral() {
    String str = "package com.sample\n" + "import org.drools.compiler.Person\n" + "rule XXX when\n" + "  Person( name.toString().toLowerCase().contains( \"mark\".toString().toLowerCase() ) )\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    ksession.insert(new Person("mark", 37));
    ksession.insert(new Person("mario", 38));
    ksession.fireAllRules();
    ksession.dispose();
}

84. MiscTest#testJittingMethodWithCharSequenceArg()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testJittingMethodWithCharSequenceArg() {
    String str = "package com.sample\n" + "import org.drools.compiler.Person\n" + "rule XXX when\n" + "  Person( $n : name, $n.contains( \"mark\" ) )\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    ksession.insert(new Person("mark", 37));
    ksession.insert(new Person("mario", 38));
    ksession.fireAllRules();
    ksession.dispose();
}

85. MiscTest#testFromNodeWithMultipleBetas()

Project: drools
Source File: MiscTest.java
View license
@Test
public void testFromNodeWithMultipleBetas() throws Exception {
    String str = "import org.drools.compiler.*;\n" + "rule R1 when\n" + "   $p : Person( $name : name, $addresses : addresses )\n" + "   $c : Cheese( $type: type == $name )\n" + "   $a : Address( street == $type, suburb == $name ) from $addresses\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    Person p = new Person("x");
    p.addAddress(new Address("x", "x", "x"));
    p.addAddress(new Address("y", "y", "y"));
    ksession.insert(p);
    ksession.insert(new Cheese("x"));
    ksession.fireAllRules();
    ksession.dispose();
}

86. IntermediateEventTest#testSignalBoundaryEventOnSubprocessTakingDifferentPaths()

Project: jbpm
Source File: IntermediateEventTest.java
View license
@Test
public void testSignalBoundaryEventOnSubprocessTakingDifferentPaths() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-SignalBoundaryOnSubProcess.bpmn");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession.startProcess("jbpm.testing.signal");
    assertProcessInstanceActive(processInstance);
    ksession.signalEvent("continue", null, processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);
    ksession.dispose();
    ksession = createKnowledgeSession(kbase);
    processInstance = ksession.startProcess("jbpm.testing.signal");
    assertProcessInstanceActive(processInstance);
    ksession.signalEvent("forward", null);
    assertProcessInstanceFinished(processInstance, ksession);
    ksession.dispose();
}

87. AgendaFilterTest#testGetListeners()

Project: jbpm
Source File: AgendaFilterTest.java
View license
@Test
public void testGetListeners() {
    // JBRULES-3378
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    if (kbuilder.hasErrors()) {
        throw new RuntimeException(kbuilder.getErrors().toString());
    }
    StatefulKnowledgeSession ksession = kbuilder.newKnowledgeBase().newStatefulKnowledgeSession();
    ksession.getAgendaEventListeners();
    ksession.getProcessEventListeners();
    ksession.getRuleRuntimeEventListeners();
    ksession.dispose();
}

88. DefeasibilityTest#testRetractNegativeDefeaters()

Project: drools
Source File: DefeasibilityTest.java
View license
@Test(timeout = 10000)
public void testRetractNegativeDefeaters() {
    String drl = "declare Foo end " + "rule Def " + "  @Defeater " + "when " + "  String() " + "then " + "  insertLogical( new Foo(), 'neg' ); " + "end ";
    StatefulKnowledgeSession session = getSessionFromString(drl);
    FactHandle h = session.insert("foo");
    session.fireAllRules();
    assertEquals(1, session.getObjects().size());
    session.delete(h);
    session.fireAllRules();
    assertEquals(0, session.getObjects().size());
}

89. ChangeSetTest#testIntegregation()

Project: drools
Source File: ChangeSetTest.java
View license
@Test
public void testIntegregation() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("changeset1Test.xml", getClass()), ResourceType.CHANGE_SET);
    assertFalse(kbuilder.hasErrors());
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.fireAllRules();
    ksession.dispose();
    assertEquals(2, list.size());
    assertTrue(list.containsAll(Arrays.asList(new String[] { "rule1", "rule2" })));
}

90. TraitTest#traitManyTimes()

Project: drools
Source File: TraitTest.java
View license
@Test(timeout = 10000)
public void traitManyTimes() {
    StatefulKnowledgeSession ksession = getSession("org/drools/compiler/factmodel/traits/testTraitDonMultiple.drl");
    TraitFactory.setMode(mode, ksession.getKieBase());
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.fireAllRules();
    for (Object o : ksession.getObjects()) {
        System.err.println(o);
    }
    Collection x = ksession.getObjects();
    assertEquals(2, ksession.getObjects().size());
    assertEquals(5, list.size());
    assertEquals(0, list.get(0));
    assertTrue(list.contains(1));
    assertTrue(list.contains(2));
    assertTrue(list.contains(3));
    assertTrue(list.contains(4));
}

91. InlineCastTest#testInlineCastOnRightOperand()

Project: drools
Source File: InlineCastTest.java
View license
@Test
public void testInlineCastOnRightOperand() throws Exception {
    String str = "import org.drools.compiler.*;\n" + "rule R1 when\n" + "   $person : Person( )\n" + "   String( this == $person.address#LongAddress.country )\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    Person mark1 = new Person("mark");
    mark1.setAddress(new LongAddress("uk"));
    ksession.insert(mark1);
    ksession.insert("uk");
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
}

92. InlineCastTest#testInlineCastOnRightOperandWithFQN()

Project: drools
Source File: InlineCastTest.java
View license
@Test
public void testInlineCastOnRightOperandWithFQN() throws Exception {
    String str = "import org.drools.compiler.Person;\n" + "rule R1 when\n" + "   $person : Person( )\n" + "   String( this == $person.address#org.drools.compiler.LongAddress.country )\n" + "then\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    Person mark1 = new Person("mark");
    mark1.setAddress(new LongAddress("uk"));
    ksession.insert(mark1);
    ksession.insert("uk");
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
}

93. DynamicRulesTest#testDynamicRules2()

Project: drools
Source File: DynamicRulesTest.java
View license
@Test(timeout = 10000)
public void testDynamicRules2() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase();
    StatefulKnowledgeSession session = createKnowledgeSession(kbase);
    // Assert some simple facts
    final FactA a = new FactA("hello", new Integer(1), new Float(3.14));
    final FactB b = new FactB("hello", new Integer(2), new Float(6.28));
    session.insert(a);
    session.insert(b);
    Collection<KnowledgePackage> kpkgs = SerializationHelper.serializeObject(loadKnowledgePackages("test_DynamicRules2.drl"));
    kbase.addKnowledgePackages(kpkgs);
    kbase = SerializationHelper.serializeObject(kbase);
    session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
    session.fireAllRules();
}

94. EnumTest#testEnums()

Project: drools
Source File: EnumTest.java
View license
@Test
public void testEnums() throws Exception {
    StatefulKnowledgeSession ksession = genSession("test_Enums.drl");
    java.util.List list = new java.util.ArrayList();
    ksession.setGlobal("list", list);
    ksession.fireAllRules();
    assertTrue(list.contains(4));
    assertTrue(list.contains(5.976e+24));
    assertTrue(list.contains("Mercury"));
    ksession.dispose();
}

95. ExtendsTest#testExtends()

Project: drools
Source File: ExtendsTest.java
View license
@Test
public void testExtends() throws Exception {
    //Test Base Fact Type
    StatefulKnowledgeSession ksession = genSession("test_Extends.drl");
    FactType person = ksession.getKieBase().getFactType("defaultpkg", "Person");
    FactType eqPair = ksession.getKieBase().getFactType("defaultpkg", "EqualityPair");
    Object p = person.newInstance();
    assertNotNull(p);
    ksession.insert("Populate");
    ksession.fireAllRules();
    // A Rule will generate 3 Persons, one with default constructor, two with field constructor
    // and 3 Students, which extends Person. One with default, one with field constructor
    assertEquals(6, ksession.getObjects(new ClassObjectFilter(person.getFactClass())).size());
    assertEquals(1 + 4 + 1 + 4, ksession.getObjects(new ClassObjectFilter(eqPair.getFactClass())).size());
    ksession.dispose();
}

96. FirstOrderLogicTest#testForallSinglePattern2()

Project: drools
Source File: FirstOrderLogicTest.java
View license
@Test
public void testForallSinglePattern2() throws Exception {
    final KnowledgeBase kbase = loadKnowledgeBase("test_ForallSinglePattern2.drl");
    final StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    ksession.insert(new Triangle(3, 3, 3));
    ksession.insert(new Triangle(3, 3, 3));
    // no cheeses, so should fire 
    int fired = ksession.fireAllRules();
    assertEquals(1, fired);
    ksession.dispose();
}

97. FunctionsTest#testFunction()

Project: drools
Source File: FunctionsTest.java
View license
@SuppressWarnings("unchecked")
@Test
public void testFunction() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase("test_FunctionInConsequence.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List<Integer> list = new ArrayList<Integer>();
    ksession.setGlobal("list", list);
    final Cheese stilton = new Cheese("stilton", 5);
    ksession.insert(stilton);
    ksession.fireAllRules();
    assertEquals(new Integer(5), ((List<Integer>) ksession.getGlobal("list")).get(0));
}

98. FunctionsTest#testFunctionWithPrimitives()

Project: drools
Source File: FunctionsTest.java
View license
@Test
public void testFunctionWithPrimitives() throws Exception {
    KnowledgeBase kbase = loadKnowledgeBase("test_FunctionWithPrimitives.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    final List<Integer> list = new ArrayList<Integer>();
    ksession.setGlobal("list", list);
    final Cheese stilton = new Cheese("stilton", 5);
    ksession.insert(stilton);
    ksession.fireAllRules();
    assertEquals(new Integer(10), list.get(0));
}

99. IndexingTest#testNotNode()

Project: drools
Source File: IndexingTest.java
View license
@Test(timeout = 10000)
public void testNotNode() {
    String str = "import org.drools.compiler.*;\n" + "rule R1 salience 10\n" + "when\n" + "   Person( $age : age )" + "   not Cheese( price < $age )\n" + "then\n" + "   System.out.println( $age );\n" + "end\n" + "rule R2 salience 1\n" + "when\n" + "   $p : Person( age == 10 )" + "then\n" + "   modify($p) { setAge(15); }\n" + "end\n";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    ksession.insert(new Person("mario", 10));
    ksession.insert(new Cheese("gorgonzola", 20));
    assertEquals(3, ksession.fireAllRules());
    ksession.dispose();
}

100. Misc2Test#testMvelAssignmentToPublicField()

Project: drools
Source File: Misc2Test.java
View license
@Test
public void testMvelAssignmentToPublicField() {
    String str = "import " + Misc2Test.Foo.class.getCanonicalName() + "\n" + "rule R\n" + "dialect \"mvel\"\n" + "when\n" + "   $foo : Foo()\n" + "then\n" + "   $foo.x = 1;\n" + "end";
    KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    Foo foo1 = new Foo();
    Foo foo2 = new Foo();
    ksession.insert(foo1);
    ksession.insert(foo2);
    ksession.fireAllRules();
    assertEquals(1, foo1.x);
    assertEquals(1, foo2.x);
}