/**
* Test instances destroyed in proper (i.e. reverse) order
*/
public void testDestroyOrder() throws Exception {
EventContext ctx = new EventContextImpl();
SessionScopeContext scope = new SessionScopeContext(ctx);
scope.registerFactories(createOrderedInitComponents());
scope.start();
Object session = new Object();
// request start
ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER,session);
SessionScopedOrderedInitPojo one = (SessionScopedOrderedInitPojo) scope.getContext("one").getInstance(null);
Assert.assertNotNull(one);
Assert.assertEquals(1, one.getNumberInstantiated());
Assert.assertEquals(1, one.getInitOrder());
SessionScopedOrderedInitPojo two = (SessionScopedOrderedInitPojo) scope.getContext("two").getInstance(null);
Assert.assertNotNull(two);
Assert.assertEquals(2, two.getNumberInstantiated());
Assert.assertEquals(2, two.getInitOrder());
SessionScopedOrderedInitPojo three = (SessionScopedOrderedInitPojo) scope.getContext("three").getInstance(null);
Assert.assertNotNull(three);
Assert.assertEquals(3, three.getNumberInstantiated());
Assert.assertEquals(3, three.getInitOrder());
// end request
ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER);
// expire session
scope.onEvent(new HttpSessionEnd(this, session));
Assert.assertEquals(0, one.getNumberInstantiated());
scope.stop();