*/
public void testEPtoJavaSessionScopeInvoke() throws Throwable {
RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime());
PolicyBuilderRegistry registry = (PolicyBuilderRegistry) ((CompositeContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD))
.getContext(MockFactory.POLICY_BUILDER_REGISTRY).getInstance(null);
MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false);
registry.registerTargetBuilder(interceptorBuilder);
runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test.module"));
CompositeContext child = (CompositeContext) runtime.getRootContext().getContext("test.module");
child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.SESSION));
child.publish(new ModuleStart(this));
// first session
Object session = new Object();
Object id = new Object();
child.publish(new RequestStart(this, id));
child.publish(new HttpSessionBound(this, session));
EntryPointContext ctx = (EntryPointContext) child.getContext("source");
Assert.assertNotNull(ctx);
InvocationHandler handler = (InvocationHandler) ctx.getHandler();
Assert.assertEquals(0, mockInterceptor.getCount());
Object response = handler.invoke(null, hello, new Object[]{"foo"});
Assert.assertEquals("Hello foo", response);
Assert.assertEquals(1, mockInterceptor.getCount());
child.publish(new RequestEnd(this, id));
Object id2 = new Object();
child.publish(new RequestStart(this, id2));
child.publish(new HttpSessionBound(this, session));
EntryPointContext ctx2 = (EntryPointContext) child.getContext("source");
Assert.assertNotNull(ctx2);
response = handler.invoke(null, hello, new Object[]{"foo"});
Assert.assertEquals("Hello foo", response);
Assert.assertEquals(2, mockInterceptor.getCount());
HelloWorldService service1 = (HelloWorldService) child.getContext("target").getInstance(null);
Assert.assertEquals(2, service1.count());
child.publish(new RequestEnd(this, id2));
child.publish(new HttpSessionEnd(this, session));
// second session
Object session2 = new Object();
child.publish(new RequestStart(this, new Object()));
child.publish(new HttpSessionBound(this, session2));
ctx = (EntryPointContext) child.getContext("source");
Assert.assertNotNull(ctx);
Assert.assertEquals(2, mockInterceptor.getCount());
response = handler.invoke(null, hello, new Object[]{"foo"});
Assert.assertEquals("Hello foo", response);
Assert.assertEquals(3, mockInterceptor.getCount());
child.publish(new HttpSessionBound(this, session2));
Object id3 = new Object();
child.publish(new RequestStart(this, id3));
child.publish(new HttpSessionBound(this, session2));
ctx2 = (EntryPointContext) child.getContext("source");
Assert.assertNotNull(ctx2);
response = handler.invoke(null, hello, new Object[]{"foo"});
Assert.assertEquals("Hello foo", response);
Assert.assertEquals(4, mockInterceptor.getCount());
HelloWorldService service2 = (HelloWorldService) child.getContext("target").getInstance(null);
Assert.assertEquals(2, service2.count());
Assert.assertEquals(2, service1.count()); //ensure sessions not crossed
child.publish(new RequestEnd(this, session2));
child.publish(new HttpSessionBound(this, session2));