use of org.kie.api.runtime.RequestContext in project drools by kiegroup.
the class BatchRunFluentTest method testContextScopeSearching.
@Test
public void testContextScopeSearching() {
ExecutableRunner<RequestContext> runner = ExecutableRunner.create();
ExecutableBuilder f = ExecutableBuilder.create();
// Check that get() will search up to Application, when no request or conversation values
f.newApplicationContext("app1").getKieContainer(releaseId).newSession().insert("h1").fireAllRules().getGlobal("outS").set("outS1", Scope.APPLICATION).get("outS1").out().dispose();
RequestContext requestContext = runner.execute(f.getExecutable());
assertEquals("h1", requestContext.get("outS1"));
assertEquals("h1", requestContext.getApplicationContext().get("outS1"));
assertEquals("h1", requestContext.get("outS1"));
// Check that get() will search up to Conversation, thus over-riding Application scope and ignoring Request when it has no value
f = new ExecutableBuilderImpl();
f.getApplicationContext("app1").startConversation().getKieContainer(releaseId).newSession().insert("h2").fireAllRules().getGlobal("outS").set("outS1", Scope.CONVERSATION).get("outS1").out().dispose();
requestContext = runner.execute(f.getExecutable());
assertEquals("h2", requestContext.get("outS1"));
assertEquals("h1", requestContext.getApplicationContext().get("outS1"));
assertEquals("h2", requestContext.getConversationContext().get("outS1"));
assertEquals("h2", requestContext.get("outS1"));
// Check that get() will search directly to Request, thus over-riding Application and Conversation scoped values
f = new ExecutableBuilderImpl();
f.getApplicationContext("app1").joinConversation(requestContext.getConversationContext().getName()).getKieContainer(releaseId).newSession().insert("h3").fireAllRules().getGlobal("outS").set("outS1", Scope.REQUEST).get("outS1").out().dispose();
requestContext = runner.execute(f.getExecutable());
assertEquals("h3", requestContext.get("outS1"));
assertEquals("h1", requestContext.getApplicationContext().get("outS1"));
assertEquals("h2", requestContext.getConversationContext().get("outS1"));
assertEquals("h3", requestContext.get("outS1"));
}
use of org.kie.api.runtime.RequestContext in project drools by kiegroup.
the class BatchRunFluentTest method testAfter.
@Test
public void testAfter() {
ExecutableRunner<RequestContext> runner = ExecutableRunner.create(0L);
ExecutableBuilder f = ExecutableBuilder.create();
// Check that get() will search up to Application, when no request or conversation values
f.after(1000).newApplicationContext("app1").getKieContainer(releaseId).newSession().insert("h1").fireAllRules().getGlobal("outS").out("outS1").getGlobal("timeNow").out("timeNow1").dispose().after(2000).newApplicationContext("app1").getKieContainer(releaseId).newSession().insert("h1").fireAllRules().getGlobal("outS").out("outS2").getGlobal("timeNow").out("timeNow2").dispose();
RequestContext requestContext = runner.execute(f.getExecutable());
assertEquals(1000l, requestContext.get("timeNow1"));
assertEquals(2000l, requestContext.get("timeNow2"));
}
use of org.kie.api.runtime.RequestContext in project drools by kiegroup.
the class BatchRunFluentTest method testDifferentConversationIds.
@Test
public void testDifferentConversationIds() {
ExecutableRunner<RequestContext> runner = ExecutableRunner.create();
RequestContext requestContext = runner.createContext();
ExecutableBuilder f = ExecutableBuilder.create();
f.newApplicationContext("app1").startConversation().getKieContainer(releaseId).newSession().insert("h1").fireAllRules().dispose();
runner.execute(f.getExecutable(), requestContext);
String conversationId = requestContext.getConversationContext().getName();
runner.execute(f.getExecutable(), requestContext);
assertNotEquals(conversationId, requestContext.getConversationContext().getName());
}
use of org.kie.api.runtime.RequestContext in project drools by kiegroup.
the class BatchRunFluentTest method testOutWithPriorSetAndNoName.
@Test
public void testOutWithPriorSetAndNoName() {
ExecutableBuilder f = ExecutableBuilder.create();
f.newApplicationContext("app1").getKieContainer(releaseId).newSession().insert("h1").fireAllRules().getGlobal("outS").set("outS").out().dispose();
RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable());
assertEquals("h1", requestContext.get("outS"));
assertEquals("h1", requestContext.get("outS"));
}
use of org.kie.api.runtime.RequestContext in project drools by kiegroup.
the class BatchRunFluentTest method testRequestScope.
@Test
public void testRequestScope() {
ExecutableBuilder f = ExecutableBuilder.create();
f.newApplicationContext("app1").getKieContainer(releaseId).newSession().insert("h1").fireAllRules().getGlobal("outS").set(// Request is default
"outS1").dispose();
RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable());
// Check that nothing went to the 'out'
assertNull(requestContext.get("outS"));
assertNull(requestContext.getApplicationContext().get("outS1"));
assertNull(requestContext.getConversationContext());
assertEquals("h1", requestContext.get("outS1"));
}
Aggregations