/**
* Tests a stateless-to-session scoped wire is setup properly by the runtime
*/
public void testStatelessToSession() throws Exception {
WorkContext ctx = new WorkContextImpl();
ScopeContainer statelessScope = new StatelessScopeContainer(ctx);
statelessScope.start();
ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx);
sessionScope.start();
Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
statelessScope, members, "target", Target.class, TargetImpl.class, sessionScope);
Object session1 = new Object();
ctx.setIdentifier(HttpSessionScopeContainer.HTTP_IDENTIFIER, session1);
sessionScope.onEvent(new HttpSessionStart(this, session1));
AtomicComponent sourceComponent = contexts.get("source");
AtomicComponent targetComponent = contexts.get("target");
Source source = (Source) sourceComponent.getServiceInstance();
Target target = (Target) targetComponent.getServiceInstance();
assertNull(source.getTarget().getString());
assertNull(target.getString());
target.setString("foo");
assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
assertEquals("foo", source.getTarget().getString());
ctx.clearIdentifier(HttpSessionScopeContainer.HTTP_IDENTIFIER);
sessionScope.onEvent(new HttpSessionEnd(this, session1));
//second session
Object session2 = new Object();
ctx.setIdentifier(HttpSessionScopeContainer.HTTP_IDENTIFIER, session2);
sessionScope.onEvent(new HttpSessionStart(this, session2));
Target target2 = (Target) targetComponent.getServiceInstance();
assertFalse("foo".equals(target2.getString()));
assertFalse("foo".equals(source.getTarget().getString()));
source.getTarget().setString("bar");
assertEquals("bar", target2.getString());
assertEquals("bar", source.getTarget().getString());
sessionScope.onEvent(new HttpSessionEnd(this, session2));
ctx.clearIdentifier(HttpSessionScopeContainer.HTTP_IDENTIFIER);
sessionScope.stop();
statelessScope.stop();
}