Search in sources :

Example 6 with RequestContextImpl

use of org.drools.core.command.RequestContextImpl 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)

Aggregations

RequestContextImpl (org.drools.core.command.RequestContextImpl)6 RegistryContext (org.drools.core.command.impl.RegistryContext)3 Context (org.kie.api.runtime.Context)2 ExecutableBuilderImpl (org.drools.core.fluent.impl.ExecutableBuilderImpl)1 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 PMML4Result (org.kie.api.pmml.PMML4Result)1 KieContainer (org.kie.api.runtime.KieContainer)1 RequestContext (org.kie.api.runtime.RequestContext)1 ExecutableBuilder (org.kie.api.runtime.builder.ExecutableBuilder)1