@Test public void testSetAndOutBehaviour() { ExecutableBuilder f = ExecutableBuilder.create(); f.newApplicationContext("app1") .getKieContainer(releaseId).newSession() .insert("h1") .fireAllRules() .getGlobal("outS").set("outS") .getGlobal("outS").set("outS1").out() .dispose(); RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable()); assertNull(requestContext.getOutputs().get("outS")); assertEquals("h1", requestContext.get("outS")); assertNotNull(requestContext.getOutputs().get("outS1")); assertEquals(requestContext.get("outS1"), requestContext.getOutputs().get("outS1")); assertEquals(requestContext.get("outS"), requestContext.get("outS1")); }
@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.getOutputs().get("outS")); assertEquals("h1", requestContext.get("outS")); }
@Test public void testSetAndGetWithCommandRegisterWithoutEnds() { ExecutableBuilder f = ExecutableBuilder.create(); f.newApplicationContext("app1") // create two sessions, and assign names .getKieContainer(releaseId).newSession().set("s1").end() // this end is needed, it's the get(String, Class) we are checking to see if it auto ends .getKieContainer(releaseId).newSession().set("s2") // initialise s1 with data .get("s1", KieSessionFluent.class) .insert("h1").fireAllRules() // initialise s2 with data .get("s2", KieSessionFluent.class) .insert("h2").fireAllRules() // assign s1 to out .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.getOutputs().get("outS1")); assertEquals("h2", requestContext.getOutputs().get("outS2")); }
@Test public void testSetAndGetWithCommandRegisterWithEnds() { ExecutableBuilder f = ExecutableBuilder.create(); f.newApplicationContext("app1") // create two sessions, and assign names .getKieContainer(releaseId).newSession().set("s1").end() .getKieContainer(releaseId).newSession().set("s2").end() // initialise s1 with data .get("s1", KieSessionFluent.class) .insert("h1").fireAllRules().end() // initialise s2 with data .get("s2", KieSessionFluent.class) .insert("h2").fireAllRules().end() // assign s1 to out .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.getOutputs().get("outS1")); assertEquals("h2", requestContext.getOutputs().get("outS2")); }
@Test public void testRequestScope() { ExecutableBuilder f = ExecutableBuilder.create(); f.newApplicationContext("app1") .getKieContainer(releaseId).newSession() .insert("h1") .fireAllRules() .getGlobal("outS").set("outS1") // Request is default .dispose(); RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable()); // Check that nothing went to the 'out' assertNull(requestContext.get("outS")); assertNull(requestContext.getOutputs().get("outS1")); assertNull(requestContext.getApplicationContext().get("outS1")); assertNull(requestContext.getConversationContext()); assertEquals("h1", requestContext.get("outS1")); }
@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 = (RequestContext) runner.execute(f.getExecutable()); assertEquals("h1", requestContext.getApplicationContext().get("outS1")); assertEquals("h2", requestContext.getApplicationContext().get("outS2")); }
.insert("h1") .fireAllRules() .getGlobal("outS").set("outS1", Scope.APPLICATION) .get("outS1").out() .dispose(); .insert("h2") .fireAllRules() .getGlobal("outS").set("outS1", Scope.CONVERSATION) .get("outS1").out() .dispose(); .insert("h3") .fireAllRules() .getGlobal("outS").set("outS1", Scope.REQUEST) .get("outS1").out() .dispose();