Search in sources :

Example 11 with RequestContext

use of org.kie.api.runtime.RequestContext 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)

Example 12 with RequestContext

use of org.kie.api.runtime.RequestContext in project drools by kiegroup.

the class BatchRunFluentTest method testOutWithoutPriorSetAndNoName.

@Test
public void testOutWithoutPriorSetAndNoName() {
    ExecutableBuilder f = ExecutableBuilder.create();
    f.newApplicationContext("app1").getKieContainer(releaseId).newSession().insert("h1").fireAllRules().getGlobal("outS").out().dispose();
    try {
        RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable());
        assertEquals("h1", requestContext.get("out1"));
        fail("Must throw Exception, as no prior set was called and no name given to out");
    } catch (Exception e) {
    }
}
Also used : ExecutableBuilder(org.kie.api.runtime.builder.ExecutableBuilder) RequestContext(org.kie.api.runtime.RequestContext) Test(org.junit.Test)

Example 13 with RequestContext

use of org.kie.api.runtime.RequestContext in project drools by kiegroup.

the class BatchRunFluentTest method testOutName.

@Test
public void testOutName() {
    ExecutableBuilder f = ExecutableBuilder.create();
    f.newApplicationContext("app1").getKieContainer(releaseId).newSession().insert("h1").fireAllRules().getGlobal("outS").out("outS").dispose();
    RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable());
    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 14 with RequestContext

use of org.kie.api.runtime.RequestContext in project drools by kiegroup.

the class BatchRunFluentTest method testSetAndGetWithCommandRegisterWithoutEnds.

@Test
public void testSetAndGetWithCommandRegisterWithoutEnds() {
    ExecutableBuilder f = ExecutableBuilder.create();
    f.newApplicationContext("app1").getKieContainer(releaseId).newSession().set("s1").end().getKieContainer(releaseId).newSession().set("s2").get("s1", KieSessionFluent.class).insert("h1").fireAllRules().get("s2", KieSessionFluent.class).insert("h2").fireAllRules().get("s1", KieSessionFluent.class).getGlobal("outS").out("outS1").dispose().get("s2", KieSessionFluent.class).getGlobal("outS").out("outS2").dispose();
    RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable());
    // Check that nothing went to the 'out'
    assertEquals("h1", requestContext.get("outS1"));
    assertEquals("h2", requestContext.get("outS2"));
}
Also used : ExecutableBuilder(org.kie.api.runtime.builder.ExecutableBuilder) KieSessionFluent(org.kie.api.runtime.builder.KieSessionFluent) 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