Search in sources :

Example 1 with ExecutableBuilderImpl

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"));
}
Also used : ExecutableBuilderImpl(org.drools.core.fluent.impl.ExecutableBuilderImpl) ExecutableBuilder(org.kie.api.runtime.builder.ExecutableBuilder) RequestContext(org.kie.api.runtime.RequestContext) Test(org.junit.Test)

Example 2 with ExecutableBuilderImpl

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());
}
Also used : ExecutableBuilderImpl(org.drools.core.fluent.impl.ExecutableBuilderImpl) ExecutableBuilder(org.kie.api.runtime.builder.ExecutableBuilder) RequestContextImpl(org.drools.core.command.RequestContextImpl) RequestContext(org.kie.api.runtime.RequestContext) Test(org.junit.Test)

Example 3 with ExecutableBuilderImpl

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"));
}
Also used : ExecutableBuilderImpl(org.drools.core.fluent.impl.ExecutableBuilderImpl) ExecutableBuilder(org.kie.api.runtime.builder.ExecutableBuilder) RequestContext(org.kie.api.runtime.RequestContext) Test(org.junit.Test)

Aggregations

ExecutableBuilderImpl (org.drools.core.fluent.impl.ExecutableBuilderImpl)3 Test (org.junit.Test)3 RequestContext (org.kie.api.runtime.RequestContext)3 ExecutableBuilder (org.kie.api.runtime.builder.ExecutableBuilder)3 RequestContextImpl (org.drools.core.command.RequestContextImpl)1