Search in sources :

Example 1 with RequestContext

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"));
}
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 RequestContext

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

Example 3 with RequestContext

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

Example 4 with RequestContext

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

Example 5 with RequestContext

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

Aggregations

RequestContext (org.kie.api.runtime.RequestContext)14 Test (org.junit.Test)12 ExecutableBuilder (org.kie.api.runtime.builder.ExecutableBuilder)11 ExecutableBuilderImpl (org.drools.core.fluent.impl.ExecutableBuilderImpl)3 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)2 KieSessionFluent (org.kie.api.runtime.builder.KieSessionFluent)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EntryPointCreator (org.drools.core.command.EntryPointCreator)1 ExecuteCommand (org.drools.core.command.ExecuteCommand)1 RequestContextImpl (org.drools.core.command.RequestContextImpl)1 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)1 KieBase (org.kie.api.KieBase)1 ExecutableRunner (org.kie.api.runtime.ExecutableRunner)1 ExecutionResults (org.kie.api.runtime.ExecutionResults)1 KieSession (org.kie.api.runtime.KieSession)1