Examples of EventContext


Examples of org.apache.tuscany.core.context.EventContext

    /**
     * Tests runtime context registration
     */
    public void testRegisterContextAfterSession() throws Exception {
        EventContext ctx = new EventContextImpl();
        SessionScopeContext scope = new SessionScopeContext(ctx);
        scope.registerFactories(createConfigurations());
        scope.start();
        Object session = new Object();

        // first request
        ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session);
        SessionScopeComponent comp1 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null);
        Assert.assertNotNull(comp1);
        ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER);

        scope.registerFactory(createConfiguration("NewTestService"));

        // second request
        ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session);
        SessionScopeInitDestroyComponent comp2 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService")
                .getInstance(null);
        Assert.assertNotNull(comp2);
        Assert.assertTrue(comp2.isInitialized());
        ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER);

        // third request different session
        Object session2 = new Object();
        ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session2);
        SessionScopeInitDestroyComponent comp3 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService")
                .getInstance(null);
        Assert.assertNotNull(comp3);
        Assert.assertNotSame(comp2, comp3);
        Assert.assertTrue(comp3.isInitialized());
        ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER);

        scope.onEvent(new HttpSessionEnd(this, session));
        Assert.assertTrue(comp2.isDestroyed());

        scope.onEvent(new HttpSessionEnd(this, session2));
View Full Code Here

Examples of org.apache.tuscany.core.context.EventContext

    /**
     * Tests instance identity is properly maintained
     */
    public void testInstanceManagement() throws Exception {
        EventContext ctx = new EventContextImpl();
        StatelessScopeContext scope = new StatelessScopeContext(ctx);
        scope.registerFactories(createConfigurations());
        scope.start();
        // first request
        StatelessComponentImpl comp1 = (StatelessComponentImpl) scope.getContext("TestService1").getInstance(null);
View Full Code Here

Examples of org.apache.tuscany.core.context.EventContext

        Assert.assertNotSame(comp1, comp2);
        scope.stop();
    }

    public void testRegisterContextBeforeRequest() throws Exception {
        EventContext ctx = new EventContextImpl();
        StatelessScopeContext scope = new StatelessScopeContext(ctx);
        scope.registerFactories(createConfigurations());
        scope.registerFactory(createConfiguration("NewTestService"));
        scope.start();
        StatelessComponent comp1 = (StatelessComponent) scope.getContext("TestService1").getInstance(null);
View Full Code Here

Examples of org.apache.tuscany.core.context.EventContext

        Assert.assertNotNull(comp2);
        scope.stop();
    }

    public void testRegisterContextAfterRequest() throws Exception {
        EventContext ctx = new EventContextImpl();
        StatelessScopeContext scope = new StatelessScopeContext(ctx);
        scope.registerFactories(createConfigurations());
        scope.start();
        StatelessComponent comp1 = (StatelessComponent) scope.getContext("TestService1").getInstance(null);
        Assert.assertNotNull(comp1);
View Full Code Here

Examples of org.apache.tuscany.core.context.EventContext

   
    /**
     * Tests setting no components in the scope
     */
    public void testSetNullComponents() throws Exception {
        EventContext ctx = new EventContextImpl();
        StatelessScopeContext scope = new StatelessScopeContext(ctx);
        scope.registerFactories(createConfigurations());
        scope.start();
        scope.stop();
    }
View Full Code Here

Examples of org.apache.tuscany.core.context.EventContext

    /**
     * Tests instance identity is properly maintained
     */
    public void testInitDestroy() throws Exception {
        EventContext ctx = new EventContextImpl();
        SessionScopeContext scope = new SessionScopeContext(ctx);
        scope.registerFactories(createComponents());
        scope.start();
        Object session = new Object();
        // first request, no need to notify scope container since sessions are
        // evaluated lazily
        ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER,session);
        SessionScopeInitDestroyComponent initDestroy = (SessionScopeInitDestroyComponent) scope.getContext(
                "TestServiceInitDestroy").getInstance(null);
        Assert.assertNotNull(initDestroy);
        SessionScopeInitOnlyComponent initOnly = (SessionScopeInitOnlyComponent) scope.getContext("TestServiceInitOnly")
                .getInstance(null);
        Assert.assertNotNull(initOnly);
        SessionScopeDestroyOnlyComponent destroyOnly = (SessionScopeDestroyOnlyComponent) 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
        ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER);
        // expire session
        scope.onEvent(new HttpSessionEnd(this,session));
        Assert.assertTrue(initDestroy.isDestroyed());
        Assert.assertTrue(destroyOnly.isDestroyed());

View Full Code Here

Examples of org.apache.tuscany.core.context.EventContext

    /**
     * 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();
View Full Code Here

Examples of org.apache.tuscany.core.context.EventContext

    /**
     * Tests instance identity is properly maintained
     */
    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);
View Full Code Here

Examples of org.apache.tuscany.core.context.EventContext

    /**
     * Test instances destroyed in proper (i.e. reverse) order
     */
    public void testDestroyOrder() throws Exception {
        EventContext ctx = new EventContextImpl();
        RequestScopeContext scope = new RequestScopeContext(ctx);
        scope.registerFactories(createOrderedInitComponents());
        scope.start();
        // request start
        RequestScopedOrderedInitPojo one = (RequestScopedOrderedInitPojo) scope.getContext("one").getInstance(null);
View Full Code Here

Examples of org.apache.tuscany.core.context.EventContext

    /**
     * Tests instance identity is properly maintained
     */
    public void testInstanceManagement() throws Exception {
        EventContext ctx = new EventContextImpl();
        ModuleScopeContext scope = new ModuleScopeContext(ctx);
        scope.registerFactories(createConfigurations());
        scope.start();
        // first request
        scope.onEvent(new ModuleStart(this));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.