Search in sources :

Example 1 with RoutingMessage

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

the class StrEvaluatorTest method testStrStartsWith.

@Test
public void testStrStartsWith() throws Exception {
    KieBase kbase = readKnowledgeBase();
    KieSession ksession = createKnowledgeSession(kbase);
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    RoutingMessage m = new RoutingMessage();
    m.setRoutingValue("R1:messageBody");
    ksession.insert(m);
    ksession.fireAllRules();
    assertTrue(list.size() == 4);
    assertTrue(((String) list.get(0)).equals("Message starts with R1"));
    assertTrue(((String) list.get(1)).equals("Message length is not 17"));
    assertTrue(((String) list.get(2)).equals("Message does not start with R2"));
    assertTrue(((String) list.get(3)).equals("Message does not end with R1"));
}
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) RoutingMessage(org.drools.compiler.RoutingMessage) Test(org.junit.Test)

Example 2 with RoutingMessage

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

the class StrEvaluatorTest method testStrWithLogicalOr.

@Test
public void testStrWithLogicalOr() {
    String drl = "package org.drools.compiler.integrationtests\n" + "import org.drools.compiler.RoutingMessage\n" + "rule R1\n" + " when\n" + " RoutingMessage( routingValue == \"R2\" || routingValue str[startsWith] \"R1\" )\n" + " then\n" + "end\n";
    KieBase kbase = loadKnowledgeBaseFromString(drl);
    KieSession ksession = kbase.newKieSession();
    try {
        for (String msgValue : new String[] { "R1something", "R2something", "R2" }) {
            RoutingMessage msg = new RoutingMessage();
            msg.setRoutingValue(msgValue);
            ksession.insert(msg);
        }
        assertEquals("Wrong number of rules fired", 2, ksession.fireAllRules());
    } finally {
        ksession.dispose();
    }
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) RoutingMessage(org.drools.compiler.RoutingMessage) Test(org.junit.Test)

Example 3 with RoutingMessage

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

the class StrEvaluatorTest method testStrNotStartsWith.

@Test
public void testStrNotStartsWith() throws Exception {
    KieBase kbase = readKnowledgeBase();
    KieSession ksession = createKnowledgeSession(kbase);
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    RoutingMessage m = new RoutingMessage();
    m.setRoutingValue("messageBody");
    ksession.insert(m);
    ksession.fireAllRules();
    assertTrue(list.size() == 3);
    assertTrue(((String) list.get(1)).equals("Message does not start with R2"));
}
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) RoutingMessage(org.drools.compiler.RoutingMessage) Test(org.junit.Test)

Example 4 with RoutingMessage

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

the class StrEvaluatorTest method testStrNotEndsWith.

@Test
public void testStrNotEndsWith() throws Exception {
    KieBase kbase = readKnowledgeBase();
    KieSession ksession = createKnowledgeSession(kbase);
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    RoutingMessage m = new RoutingMessage();
    m.setRoutingValue("messageBody");
    ksession.insert(m);
    ksession.fireAllRules();
    assertTrue(list.size() == 3);
    assertTrue(((String) list.get(0)).equals("Message length is not 17"));
    assertTrue(((String) list.get(1)).equals("Message does not start with R2"));
    assertTrue(((String) list.get(2)).equals("Message does not end with R1"));
}
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) RoutingMessage(org.drools.compiler.RoutingMessage) Test(org.junit.Test)

Example 5 with RoutingMessage

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

the class StrEvaluatorTest method testStrEndsWith.

@Test
public void testStrEndsWith() throws Exception {
    KieBase kbase = readKnowledgeBase();
    KieSession ksession = createKnowledgeSession(kbase);
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    RoutingMessage m = new RoutingMessage();
    m.setRoutingValue("messageBody:R2");
    ksession.insert(m);
    ksession.fireAllRules();
    assertTrue(list.size() == 4);
    assertTrue(((String) list.get(0)).equals("Message ends with R2"));
    assertTrue(((String) list.get(1)).equals("Message length is not 17"));
    assertTrue(((String) list.get(2)).equals("Message does not start with R2"));
    assertTrue(((String) list.get(3)).equals("Message does not end with R1"));
}
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) RoutingMessage(org.drools.compiler.RoutingMessage) Test(org.junit.Test)

Aggregations

RoutingMessage (org.drools.compiler.RoutingMessage)7 Test (org.junit.Test)7 KieBase (org.kie.api.KieBase)7 KieSession (org.kie.api.runtime.KieSession)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6