Search in sources :

Example 1 with KieCommands

use of org.kie.api.command.KieCommands in project drools by kiegroup.

the class StatelessKieSessionDefaultInjectionTest method tessDefaultClassPathKBase.

@Test
public void tessDefaultClassPathKBase() throws IOException, ClassNotFoundException, InterruptedException {
    assertNotNull(defaultClassPathSKSession);
    KieCommands cmds = KieServices.Factory.get().getCommands();
    List<String> list = new ArrayList<String>();
    defaultClassPathSKSession.setGlobal("list", list);
    defaultClassPathSKSession.execute(cmds.newFireAllRules());
    assertEquals(2, list.size());
    assertTrue(list.get(0).endsWith("2.0"));
    assertTrue(list.get(1).endsWith("2.0"));
}
Also used : KieCommands(org.kie.api.command.KieCommands) ArrayList(java.util.ArrayList) AbstractKnowledgeTest(org.drools.cdi.kproject.AbstractKnowledgeTest) Test(org.junit.Test)

Example 2 with KieCommands

use of org.kie.api.command.KieCommands in project drools by kiegroup.

the class CommandsTest method testSessionTimeCommands.

@Test
public void testSessionTimeCommands() throws Exception {
    String str = "";
    str += "package org.drools.compiler.integrationtests \n";
    str += "import " + Cheese.class.getCanonicalName() + " \n";
    str += "rule StringRule \n";
    str += " when \n";
    str += " $c : Cheese() \n";
    str += " then \n";
    str += " System.out.println($c); \n";
    str += "end \n";
    KieServices ks = KieServices.get();
    KieCommands kieCommands = ks.getCommands();
    KieSessionConfiguration sessionConfig = ks.newKieSessionConfiguration();
    sessionConfig.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
    KieSession kSession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession(sessionConfig, null);
    assertEquals(0L, (long) kSession.execute(kieCommands.newGetSessionTime()));
    assertEquals(2000L, (long) kSession.execute(kieCommands.newAdvanceSessionTime(2, TimeUnit.SECONDS)));
    assertEquals(2000L, (long) kSession.execute(kieCommands.newGetSessionTime()));
    kSession.dispose();
}
Also used : KieCommands(org.kie.api.command.KieCommands) KieHelper(org.kie.internal.utils.KieHelper) Cheese(org.drools.compiler.Cheese) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) Test(org.junit.Test)

Example 3 with KieCommands

use of org.kie.api.command.KieCommands in project drools by kiegroup.

the class StatelessKieSessionDefaultInjectionTest method tessDefaultDynamicKBase.

@Test
public void tessDefaultDynamicKBase() throws IOException, ClassNotFoundException, InterruptedException {
    assertNotNull(defaultDynamicSKSession);
    KieCommands cmds = KieServices.Factory.get().getCommands();
    List<String> list = new ArrayList<String>();
    defaultDynamicSKSession.setGlobal("list", list);
    defaultDynamicSKSession.execute(cmds.newFireAllRules());
    assertEquals(2, list.size());
    assertTrue(list.get(0).endsWith("1.0"));
    assertTrue(list.get(1).endsWith("1.0"));
}
Also used : KieCommands(org.kie.api.command.KieCommands) ArrayList(java.util.ArrayList) AbstractKnowledgeTest(org.drools.cdi.kproject.AbstractKnowledgeTest) Test(org.junit.Test)

Example 4 with KieCommands

use of org.kie.api.command.KieCommands in project drools by kiegroup.

the class StatelessKieSessionInjectionTest method testDynamicStatelessKieSessionReleaseId.

@Test
public void testDynamicStatelessKieSessionReleaseId() throws IOException, ClassNotFoundException, InterruptedException {
    assertNotNull(kbase1ksession1v10);
    assertNotNull(kbase1ksession1v10);
    KieCommands cmds = KieServices.Factory.get().getCommands();
    List<String> list = new ArrayList<String>();
    kbase1ksession1v10.setGlobal("list", list);
    kbase1ksession1v10.execute(cmds.newFireAllRules());
    assertEquals(2, list.size());
    assertTrue(list.get(0).endsWith("1.0"));
    assertTrue(list.get(1).endsWith("1.0"));
    list = new ArrayList<String>();
    kbase1ksession1v11.setGlobal("list", list);
    kbase1ksession1v11.execute(cmds.newFireAllRules());
    assertEquals(2, list.size());
    assertTrue(list.get(0).endsWith("1.1"));
    assertTrue(list.get(1).endsWith("1.1"));
}
Also used : KieCommands(org.kie.api.command.KieCommands) ArrayList(java.util.ArrayList) AbstractKnowledgeTest(org.drools.cdi.kproject.AbstractKnowledgeTest) Test(org.junit.Test)

Example 5 with KieCommands

use of org.kie.api.command.KieCommands in project drools by kiegroup.

the class StatelessKieSessionInjectionTest method testNamedStatelessKieSessions.

@Test
public void testNamedStatelessKieSessions() throws IOException, ClassNotFoundException, InterruptedException {
    assertNotNull(kbase1ksession1sks1);
    assertNotNull(kbase1ksession1sks2);
    assertNotNull(kbase1ksession1sks22);
    assertNotSame(kbase1ksession1sks1, kbase1ksession1sks2);
    assertSame(kbase1ksession1sks2, kbase1ksession1sks22);
    KieCommands cmds = KieServices.Factory.get().getCommands();
    List<String> list = new ArrayList<String>();
    kbase1ksession1sks1.setGlobal("list", list);
    kbase1ksession1sks1.execute(cmds.newFireAllRules());
    assertEquals(2, list.size());
    assertTrue(list.get(0).endsWith("1.0"));
    assertTrue(list.get(1).endsWith("1.0"));
    list = new ArrayList<String>();
    kbase1ksession1sks2.setGlobal("list", list);
    kbase1ksession1sks2.execute(cmds.newFireAllRules());
    assertEquals(2, list.size());
    assertTrue(list.get(0).endsWith("1.0"));
    assertTrue(list.get(1).endsWith("1.0"));
}
Also used : KieCommands(org.kie.api.command.KieCommands) ArrayList(java.util.ArrayList) AbstractKnowledgeTest(org.drools.cdi.kproject.AbstractKnowledgeTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 KieCommands (org.kie.api.command.KieCommands)5 ArrayList (java.util.ArrayList)4 AbstractKnowledgeTest (org.drools.cdi.kproject.AbstractKnowledgeTest)4 Cheese (org.drools.compiler.Cheese)1 KieServices (org.kie.api.KieServices)1 KieSession (org.kie.api.runtime.KieSession)1 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)1 KieHelper (org.kie.internal.utils.KieHelper)1