assertEquals( "p1",
back.getName() );
builder.addPackage( packageDescr );
InternalKnowledgePackage pkg = builder.getPackage();
final RuleImpl rule = pkg.getRule( "rule-1" );
assertLength( 0,
builder.getErrors().getErrors() );
InternalKnowledgePackage newPkg = SerializationHelper.serializeObject( pkg );
final RuleImpl newRule = newPkg.getRule( "rule-1" );
InternalKnowledgeBase kBase = (InternalKnowledgeBase)KnowledgeBaseFactory.newKnowledgeBase();
// It's been serialised so we have to simulate the re-wiring process
newPkg.getDialectRuntimeRegistry().onAdd( kBase.getRootClassLoader() );
newPkg.getDialectRuntimeRegistry().onBeforeExecute();
kBase.getGlobals().put( "map", Map.class );
final KieSession workingMemory = kBase.newStatefulKnowledgeSession();
final HashMap map = new HashMap();
workingMemory.setGlobal( "map",
map );
final LeftTupleImpl tuple = new MockTuple( new HashMap() );
tuple.setLeftTupleSink( new RuleTerminalNode(1, new CompositeObjectSinkAdapterTest.MockBetaNode(), newRule,newRule.getLhs(), 0, new BuildContext(kBase, null) ) );
final Activation activation = new MockActivation( newRule,
0,
newRule.getLhs(),
tuple );
final DefaultKnowledgeHelper knowledgeHelper = new org.drools.core.base.DefaultKnowledgeHelper( ((StatefulKnowledgeSessionImpl)workingMemory) );
knowledgeHelper.setActivation( activation );
newRule.getConsequence().evaluate( knowledgeHelper,
((StatefulKnowledgeSessionImpl)workingMemory) );
assertEquals( new Integer( 1 ),
map.get( "value" ) );
}