Search in sources :

Example 6 with EventBus

use of io.vertx.rxjava.core.eventbus.EventBus in project rulesservice by genny-project.

the class KieTest method setupKieSessionTest.

@Test
public void setupKieSessionTest() {
    String rule = "";
    rule += "package org.kie.test\n";
    rule += "global java.util.List list\n";
    rule += "rule rule1\n";
    rule += "when\n";
    rule += "  Integer(intValue > 0)\n";
    rule += "then\n";
    rule += "  list.add( 1 );\n";
    rule += "  System.out.println(\"Added!\");\n";
    rule += "end\n";
    rule += "\n";
    String rulesGroup = "GRP_RULES_TEST";
    List<Tuple3<String, String, String>> rules = new ArrayList<Tuple3<String, String, String>>();
    rules.add(Tuple.of("genny", "rule1.drl", rule));
    List<Tuple2<String, Object>> globals = new ArrayList<Tuple2<String, Object>>();
    List<?> list = new ArrayList<Object>();
    globals.add(Tuple.of("list", list));
    RulesLoader.setupKieRules(rulesGroup, rules);
    Map<String, KieBase> cache = RulesLoader.getKieBaseCache();
    Integer count = cache.size();
    System.out.println("Loaded Test Kie Session with " + count + " ruleGroups");
    EventBus eb = null;
    List<Object> facts = new ArrayList<Object>();
    facts.add(1);
    facts.add(2);
    facts.add(3);
    Map<String, String> keyvalue = new HashMap<String, String>();
    keyvalue.put("token", null);
    RulesLoader.executeStatefull(rulesGroup, eb, globals, facts, keyvalue);
    assertThat(list.size(), is(3));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EventBus(io.vertx.rxjava.core.eventbus.EventBus) Tuple2(io.vavr.Tuple2) KieBase(org.kie.api.KieBase) Tuple3(io.vavr.Tuple3) Test(org.junit.Test)

Aggregations

EventBus (io.vertx.rxjava.core.eventbus.EventBus)6 Tuple2 (io.vavr.Tuple2)2 Tuple3 (io.vavr.Tuple3)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 KieBase (org.kie.api.KieBase)2 Message (io.vertx.rxjava.core.eventbus.Message)1 Random (java.util.Random)1