@Test public void bindDataSourcesNonexistingEntryPoints() { final StatefulKnowledgeSessionImpl sessionImpl = mock(StatefulKnowledgeSessionImpl.class); when(sessionImpl.getEntryPoint("number")).thenReturn(null); when(sessionImpl.getEntryPoint("numbersArray")).thenReturn(null); when(sessionImpl.getEntryPoint("stringList")).thenReturn(null); when(sessionImpl.getEntryPoint("simpleFactList")).thenReturn(null); final TestRuleUnit testRuleUnit = new TestRuleUnit(new Integer[]{1, 2, 5}, BigDecimal.TEN); final SimpleFact simpleFact = new SimpleFact("testValue"); testRuleUnit.addSimpleFact(simpleFact); ruleUnitDescr.bindDataSources(sessionImpl, testRuleUnit); verify(sessionImpl, never()).insert(anyObject()); verify(sessionImpl, never()).insert(anyObject(), anyBoolean(), anyObject(), anyObject()); }
@Test public void bindDataSources() { final WorkingMemoryEntryPoint numberEntryPoint = mock(WorkingMemoryEntryPoint.class); final WorkingMemoryEntryPoint numbersArrayEntryPoint = mock(WorkingMemoryEntryPoint.class); final WorkingMemoryEntryPoint stringListEntryPoint = mock(WorkingMemoryEntryPoint.class); final WorkingMemoryEntryPoint simpleFactListEntryPoint = mock(WorkingMemoryEntryPoint.class); final StatefulKnowledgeSessionImpl sessionImpl = mock(StatefulKnowledgeSessionImpl.class); when(sessionImpl.getEntryPoint(TestRuleUnit.class.getCanonicalName() + ".number")).thenReturn(numberEntryPoint); when(sessionImpl.getEntryPoint(TestRuleUnit.class.getCanonicalName() + ".numbersArray")).thenReturn(numbersArrayEntryPoint); when(sessionImpl.getEntryPoint(TestRuleUnit.class.getCanonicalName() + ".stringList")).thenReturn(stringListEntryPoint); when(sessionImpl.getEntryPoint(TestRuleUnit.class.getCanonicalName() + ".simpleFactList")).thenReturn(simpleFactListEntryPoint); final TestRuleUnit testRuleUnit = new TestRuleUnit(new Integer[]{1, 2, 5}, BigDecimal.TEN); final SimpleFact simpleFact = new SimpleFact("testValue"); testRuleUnit.addSimpleFact(simpleFact); ruleUnitDescr.bindDataSources(sessionImpl, testRuleUnit); verify(numberEntryPoint).insert(BigDecimal.TEN); verifyNoMoreInteractions(numberEntryPoint); verify(numbersArrayEntryPoint).insert(1); verify(numbersArrayEntryPoint).insert(2); verify(numbersArrayEntryPoint).insert(5); verifyNoMoreInteractions(numbersArrayEntryPoint); verifyZeroInteractions(stringListEntryPoint); verify(simpleFactListEntryPoint).insert(simpleFact); verifyNoMoreInteractions(simpleFactListEntryPoint); }
@Test public void unbindDataSources() { final WorkingMemoryEntryPoint boundPropEntryPoint = mock(WorkingMemoryEntryPoint.class); final StatefulKnowledgeSessionImpl sessionImpl = mock(StatefulKnowledgeSessionImpl.class); // This is a little hack, see description in TestRuleUnit class. when(sessionImpl.getEntryPoint(TestRuleUnit.class.getCanonicalName() + ".bound")).thenReturn(boundPropEntryPoint); final TestRuleUnit testRuleUnit = new TestRuleUnit(new Integer[]{1, 2, 5}, BigDecimal.TEN); final SimpleFact simpleFact = new SimpleFact("testValue"); testRuleUnit.addSimpleFact(simpleFact); assertThat(testRuleUnit.bound).isFalse(); // Bind calls getBound() which switches the bound flag to true ruleUnitDescr.bindDataSources(sessionImpl, testRuleUnit); verify(boundPropEntryPoint).insert(true); // Unbind calls getBound() which switches the bound flag to false ruleUnitDescr.unbindDataSources(sessionImpl, testRuleUnit); // We have to observe directly. By calling getBound, it will get switched again. assertThat(testRuleUnit.bound).isFalse(); }
@Test(timeout = 10000 ) public void testConflictStrict() { KieSession kSession = getSessionFromFile( "posNegConflict.drl" ); ArrayList list = new ArrayList(); kSession.setGlobal( "list", list ); NamedEntryPoint ep = ( NamedEntryPoint ) ((StatefulKnowledgeSessionImpl)kSession).getEntryPoint( "DEFAULT" ); JTMSBeliefSystem bs = ( JTMSBeliefSystem ) ep.getTruthMaintenanceSystem().getBeliefSystem(); bs.STRICT = true; try { kSession.fireAllRules(); fail( "A fact and its negation should have been asserted, but no exception was trhown in strict mode" ); } catch ( Exception e ) { } finally { bs.STRICT = false; } }
.getObjectTypeConf(ksession.getEntryPoint(), stringFact1); .getObjectTypeConf(ksession.getEntryPoint(), intFact1);
@Test public void shouldLazilyAdd() throws Exception { final String fact1 = "logical"; ksession.insert(fact1); assertEquals( "Shouldn't have anything, since no logical insert was performed.", 0, tms.getEqualityKeyMap().size()); final String fact2 = "logical"; ksession.getTruthMaintenanceSystem().insert( fact2, null, null, new MockActivation() ); assertEquals( "Now that a logical insert was done, it should have an element.", 1, tms.getEqualityKeyMap().size()); // Make sure the internals are fine. ObjectTypeConf typeConf = ksession.getObjectTypeConfigurationRegistry() .getObjectTypeConf(ksession.getEntryPoint(), fact1); assertTrue("Should have enabled TMS", typeConf.isTMSEnabled()); }
assertEquals( 1, getNegativeObjects(kSession).size() ); NamedEntryPoint ep = ( NamedEntryPoint ) ((StatefulKnowledgeSessionImpl)kSession).getEntryPoint( "DEFAULT" ); ObjectHashMap equalityMap = ep.getTruthMaintenanceSystem().getEqualityKeyMap(); assertEquals( 2, equalityMap.size() ); // go1, neg are two different strings.
kSession.fireAllRules(); NamedEntryPoint ep = ( NamedEntryPoint ) ((StatefulKnowledgeSessionImpl)kSession).getEntryPoint( "DEFAULT" ); assertEquals( 3, ep.getObjects().size() ); //just go1, go2, go3 assertEquals( 1, getNegativeObjects(kSession).size() ); // Person(darth)
kSession.fireAllRules(); NamedEntryPoint ep = ( NamedEntryPoint ) ((StatefulKnowledgeSessionImpl)kSession).getEntryPoint( "DEFAULT" ); assertEquals( 4, ep.getObjects().size() ); //just go1, go2, go3, Person(darth)