use of org.drools.core.fluent.impl.ExecutableBuilderImpl 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.drools.core.fluent.impl.ExecutableBuilderImpl in project drools by kiegroup.
the class BatchRunFluentTest method testConversationScope.
@Test
public void testConversationScope() {
ExecutableRunner<RequestContext> runner = ExecutableRunner.create();
ExecutableBuilder f = ExecutableBuilder.create();
f.newApplicationContext("app1").startConversation().getKieContainer(releaseId).newSession().insert("h1").fireAllRules().getGlobal("outS").set("outS1", Scope.CONVERSATION).dispose();
RequestContextImpl requestContext = (RequestContextImpl) runner.execute(f.getExecutable());
// check that nothing went to the 'out'
assertEquals(null, requestContext.get("outS"));
String conversationId = requestContext.getConversationContext().getName();
assertEquals("h1", requestContext.getConversationContext().get("outS1"));
// Make another request, add to conversation context, assert old and new values are there.
f = new ExecutableBuilderImpl();
f.getApplicationContext("app1").joinConversation(conversationId).getKieContainer(releaseId).newSession().insert("h2").fireAllRules().getGlobal("outS").set("outS2", Scope.CONVERSATION).dispose();
requestContext = (RequestContextImpl) runner.execute(f.getExecutable());
assertEquals("h1", requestContext.getConversationContext().get("outS1"));
assertEquals("h2", requestContext.getConversationContext().get("outS2"));
// End the conversation, check it's now null
f = new ExecutableBuilderImpl();
f.endConversation(conversationId);
requestContext = (RequestContextImpl) runner.execute(f.getExecutable());
assertNull(requestContext.getConversationContext());
}
use of org.drools.core.fluent.impl.ExecutableBuilderImpl in project drools by kiegroup.
the class BatchRunFluentTest method testApplicationScope.
@Test
public void testApplicationScope() {
ExecutableRunner<RequestContext> runner = ExecutableRunner.create();
ExecutableBuilder f = ExecutableBuilder.create();
f.newApplicationContext("app1").getKieContainer(releaseId).newSession().insert("h1").fireAllRules().getGlobal("outS").set("outS1", Scope.APPLICATION).dispose();
RequestContext requestContext = runner.execute(f.getExecutable());
// Check that nothing went to the 'out'
assertEquals(null, requestContext.get("outS"));
assertEquals("h1", requestContext.getApplicationContext().get("outS1"));
// Make another request, add to application context, assert old and new values are there.
f = new ExecutableBuilderImpl();
f.getApplicationContext("app1").getKieContainer(releaseId).newSession().insert("h2").fireAllRules().getGlobal("outS").set("outS2", Scope.APPLICATION).dispose();
requestContext = (RequestContextImpl) runner.execute(f.getExecutable());
assertEquals("h1", requestContext.getApplicationContext().get("outS1"));
assertEquals("h2", requestContext.getApplicationContext().get("outS2"));
}
Aggregations