*
* @throws org.drools.core.FactException
*/
@Test
public void testCache() throws FactException {
final AbstractWorkingMemory workingMemory = (AbstractWorkingMemory) this.ruleBase.newStatefulSession();
// Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
final Rete rete = ruleBase.getRete();
ObjectTypeNode objectTypeNode = new ObjectTypeNode(1,
this.entryPoint,
new ClassObjectType(List.class),
buildContext);
objectTypeNode.attach(buildContext);
MockObjectSink sink = new MockObjectSink();
objectTypeNode.addObjectSink(sink);
objectTypeNode = new ObjectTypeNode(1,
this.entryPoint,
new ClassObjectType(Collection.class),
buildContext);
objectTypeNode.attach(buildContext);
sink = new MockObjectSink();
objectTypeNode.addObjectSink(sink);
objectTypeNode = new ObjectTypeNode(1,
this.entryPoint,
new ClassObjectType(ArrayList.class),
buildContext);
objectTypeNode.attach(buildContext);
sink = new MockObjectSink();
objectTypeNode.addObjectSink(sink);
// ArrayList matches all three ObjectTypeNodes
final DefaultFactHandle h1 = new DefaultFactHandle(1,
new ArrayList());
rete.assertObject(h1,
pctxFactory.createPropagationContext(0,
PropagationContext.INSERTION,
null,
null,
null),
workingMemory);
// LinkedList matches two ObjectTypeNodes
h1.setObject(new LinkedList());
rete.assertObject(h1,
pctxFactory.createPropagationContext(0,
PropagationContext.INSERTION,
null,
null,
null),
workingMemory);
ClassObjectTypeConf conf = (ClassObjectTypeConf) workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPoint.getEntryPoint(), new ArrayList());
assertLength(3,
conf.getObjectTypeNodes());
conf = (ClassObjectTypeConf) workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPoint.getEntryPoint(), new ArrayList());
assertLength(3,
conf.getObjectTypeNodes());
}