public void testInitDestroy() throws Exception {
EventContext ctx = new EventContextImpl();
RequestScopeContext scope = new RequestScopeContext(ctx);
scope.registerFactories(createComponents());
scope.start();
RequestScopeInitDestroyComponent initDestroy = (RequestScopeInitDestroyComponent) scope.getContext(
"TestServiceInitDestroy").getInstance(null);
Assert.assertNotNull(initDestroy);
RequestScopeInitOnlyComponent initOnly = (RequestScopeInitOnlyComponent) scope.getContext("TestServiceInitOnly")
.getInstance(null);
Assert.assertNotNull(initOnly);
RequestScopeDestroyOnlyComponent destroyOnly = (RequestScopeDestroyOnlyComponent) scope.getContext(
"TestServiceDestroyOnly").getInstance(null);
Assert.assertNotNull(destroyOnly);
Assert.assertTrue(initDestroy.isInitialized());
Assert.assertTrue(initOnly.isInitialized());
Assert.assertFalse(initDestroy.isDestroyed());
Assert.assertFalse(destroyOnly.isDestroyed());
// end request
scope.onEvent(new RequestEnd(this, new Object()));
Assert.assertTrue(initDestroy.isDestroyed());
Assert.assertTrue(destroyOnly.isDestroyed());
scope.stop();
}