/** * Tests ObjectTypeNodes are correctly added to the Rete object * * @throws Exception */ @Test public void testObjectTypeNodes() throws Exception { final Rete rete = kBase.getRete(); final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1, this.entryPoint, new ClassObjectType(Object.class), buildContext); objectTypeNode.attach(buildContext); final ObjectTypeNode stringTypeNode = new ObjectTypeNode(2, this.entryPoint, new ClassObjectType(String.class), buildContext); stringTypeNode.attach(buildContext); final List<ObjectTypeNode> list = rete.getObjectTypeNodes(); // Check the ObjectTypeNodes are correctly added to Rete assertEquals(3, list.size()); assertTrue(list.contains(objectTypeNode)); assertTrue(list.contains(stringTypeNode)); }
@Test public void testAdd() { /* * create a RuleBase with a single ObjectTypeNode we attach a * MockObjectSink so we can detect assertions and retractions */ InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(); BuildContext context = new BuildContext(kBase); NodeFactory nFacotry = kBase.getConfiguration().getComponentFactory().getNodeFactoryService(); EntryPointNode entryPoint = context.getKnowledgeBase().getRete().getEntryPointNodes().values().iterator().next(); final ObjectTypeNode objectTypeNode = nFacotry.buildObjectTypeNode( 0, entryPoint, new ClassObjectType( Object.class ), context ); objectTypeNode.attach(context); final MockObjectSink sink = new MockObjectSink(); objectTypeNode.addObjectSink( sink ); kBase.newKieSession(); // objectTypeNode. }
@Test public void test1() { StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newKieSession(); final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1, this.entryPoint, new ClassObjectType( State.class ), buildContext ); objectTypeNode.attach(buildContext); final MockObjectSink sink = new MockObjectSink(); objectTypeNode.addObjectSink( sink ); final State a = new State( "go" ); ksession.insert( a, true ); ksession.fireAllRules(); assertEquals( 1, sink.getAsserted().size() ); a.setState( "stop" ); }
new ClassObjectType(List.class), buildContext); objectTypeNode.attach(buildContext); MockObjectSink sink = new MockObjectSink(); objectTypeNode.addObjectSink(sink); new ClassObjectType(Collection.class), buildContext); objectTypeNode.attach(buildContext); sink = new MockObjectSink(); objectTypeNode.addObjectSink(sink); new ClassObjectType(ArrayList.class), buildContext); objectTypeNode.attach(buildContext); sink = new MockObjectSink(); objectTypeNode.addObjectSink(sink);
new ClassObjectType(Cheese.class), buildContext); objectTypeNode.attach(buildContext); final MockObjectSink sink1 = new MockObjectSink(); objectTypeNode.addObjectSink(sink1);
@Test public void testIsShadowed() { StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newKieSession(); // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList final Rete rete = kBase.getRete(); final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1, this.entryPoint, new ClassObjectType(Cheese.class), buildContext); objectTypeNode.attach(buildContext); final MockObjectSink sink1 = new MockObjectSink(); objectTypeNode.addObjectSink(sink1); // There are no String ObjectTypeNodes, make sure its not propagated final Cheese cheese = new Cheese("brie", 15); final DefaultFactHandle h1 = new DefaultFactHandle(1, cheese); rete.assertObject(h1, pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null), ksession); ksession.fireAllRules(); final Object[] results = (Object[]) sink1.getAsserted().get(0); }
new ClassObjectType(List.class), buildContext); objectTypeNode.attach(buildContext); final MockObjectSink sink1 = new MockObjectSink(); objectTypeNode.addObjectSink(sink1);
new ClassObjectType(List.class), buildContext); objectTypeNode.attach(buildContext); final MockObjectSink sink1 = new MockObjectSink(); objectTypeNode.addObjectSink(sink1);
new ClassObjectType( String.class ), buildContext ); objectTypeNode.attach( buildContext ); final MockObjectSink sink = new MockObjectSink(); objectTypeNode.addObjectSink( sink );
new ClassObjectType( String.class ), buildContext ); objectTypeNode.attach( buildContext ); final MockObjectSink sink = new MockObjectSink(); objectTypeNode.addObjectSink( sink );
new ClassObjectType( String.class ), buildContext ); objectTypeNode.attach( buildContext ); final MockObjectSink sink = new MockObjectSink(); objectTypeNode.addObjectSink( sink );
new ClassObjectType( String.class ), buildContext ); objectTypeNode.attach( buildContext ); final MockObjectSink sink = new MockObjectSink(); objectTypeNode.addObjectSink( sink );
new ClassObjectType( String.class ), buildContext ); objectTypeNode.attach( buildContext );
new ClassObjectType( String.class ), buildContext ); objectTypeNode.attach( buildContext ); final MockObjectSink sink = new MockObjectSink(); objectTypeNode.addObjectSink( sink );