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"));
}
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();
}
}
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"));
}
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"));
}
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"));
}
Aggregations