public void testCompositeScopePropagation() throws Exception {
EventContext ctx = new EventContextImpl();
CompositeContext moduleComponentCtx = new CompositeContextImpl();
moduleComponentCtx.setName("testMC");
moduleComponentCtx.start();
CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx);
scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent"));
scopeContainer.start();
CompositeContext child = (CompositeContext) scopeContainer.getContext("CompositeComponent");
List<Extensible> models = createAssembly();
for (Extensible model : models) {
child.registerModelObject(model);
}
scopeContainer.onEvent(new ModuleStart(this));
Object session = new Object();
Object id = new Object();
//ctx.setIdentifier(EventContext.SESSION,session);
scopeContainer.onEvent(new RequestStart(this,id));
scopeContainer.onEvent(new HttpSessionBound(this,session));
CompositeContext componentCtx = (CompositeContext) scopeContainer.getContext("CompositeComponent");
GenericComponent testService1 = (GenericComponent) componentCtx.getContext("TestService1").getInstance(null);
GenericComponent testService2 = (GenericComponent) componentCtx.getContext("TestService2").getInstance(null);
GenericComponent testService3 = (GenericComponent) componentCtx.getContext("TestService3").getInstance(null);
Assert.assertNotNull(testService1);
Assert.assertNotNull(testService2);
Assert.assertNotNull(testService3);
scopeContainer.onEvent(new RequestEnd(this,id));
scopeContainer.onEvent(new RequestStart(this,id));
scopeContainer.onEvent(new HttpSessionBound(this,session));
GenericComponent testService2a = (GenericComponent) componentCtx.getContext("TestService2").getInstance(null);
Assert.assertNotNull(testService2a);
GenericComponent testService3a = (GenericComponent) componentCtx.getContext("TestService3").getInstance(null);
Assert.assertNotNull(testService3a);
Assert.assertEquals(testService2, testService2a);
Assert.assertNotSame(testService3, testService3a);
scopeContainer.onEvent(new RequestEnd(this,id));
scopeContainer.onEvent(new HttpSessionEnd(this,session));
Object session2 = new Object();
Object id2 = new Object();
scopeContainer.onEvent(new RequestStart(this,id2));
scopeContainer.onEvent(new HttpSessionBound(this,session2));
GenericComponent testService2b = (GenericComponent) componentCtx.getContext("TestService2").getInstance(null);
Assert.assertNotNull(testService2b);
Assert.assertNotSame(testService2, testService2b);
scopeContainer.onEvent(new RequestEnd(this,id2));
scopeContainer.onEvent(new HttpSessionEnd(this,session2));
}