Examples of EventContext


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

public class ModuleScopeLifecycleTestCase extends TestCase {

    JavaContextFactoryBuilder builder;

    public void testInitDestroy() throws Exception {
        EventContext ctx = new EventContextImpl();
        ModuleScopeContext scope = new ModuleScopeContext(ctx);
        scope.registerFactories(createComponents());
        scope.start();
        scope.onEvent(new ModuleStart(this));
        ModuleScopeInitDestroyComponent initDestroy = (ModuleScopeInitDestroyComponent) scope.getContext(
View Full Code Here

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

        scope.stop();
    }

    public void testEagerInit() throws Exception {
        EventContext ctx = new EventContextImpl();
        ModuleScopeContext scope = new ModuleScopeContext(ctx);
        scope.registerFactories(createEagerInitComponents());
        scope.start();
        scope.onEvent(new ModuleStart(this));
        ModuleScopeEagerInitDestroyComponent initDestroy = (ModuleScopeEagerInitDestroyComponent) scope.getContext(
View Full Code Here

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

        scope.stop();

    }

    public void testDestroyOrder() throws Exception {
        EventContext ctx = new EventContextImpl();
        ModuleScopeContext scope = new ModuleScopeContext(ctx);
        scope.registerFactories(createOrderedInitComponents());
        scope.start();
        scope.onEvent(new ModuleStart(this));
        OrderedInitPojo one = (OrderedInitPojo) scope.getContext("one").getInstance(null);
View Full Code Here

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

        Assert.assertEquals(0, one.getNumberInstantiated());
        scope.stop();
    }

    public void testEagerInitDestroyOrder() throws Exception {
        EventContext ctx = new EventContextImpl();
        ModuleScopeContext scope = new ModuleScopeContext(ctx);
        scope.registerFactories(createOrderedEagerInitComponents());
        scope.start();
        scope.onEvent(new ModuleStart(this));
        OrderedEagerInitPojo one = (OrderedEagerInitPojo) scope.getContext("one").getInstance(null);
View Full Code Here

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

        JavaTargetWireBuilder javaWireBuilder = new JavaTargetWireBuilder();
        ScopeStrategy strategy = new DefaultScopeStrategy();
        DefaultWireBuilder wireBuilder = new DefaultWireBuilder();
        wireBuilder.addWireBuilder(javaWireBuilder);
        Module module = MockFactory.createModule();
        EventContext eCtx = new EventContextImpl();
        ScopeContext scopeContext = new ModuleScopeContext(eCtx);
        scopeContext.start();
        scopeContext.onEvent(new ModuleStart(this));
        List<Component> components = module.getComponents();
        Map<String, Component> compMap = new HashMap<String, Component>(components.size());
View Full Code Here

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

public class DependencyLifecycleTestCase extends TestCase {



    public void testInitDestroyOrderModuleScope() throws Exception {
        EventContext ctx = new EventContextImpl();
        ModuleScopeContext scope = new ModuleScopeContext(ctx);
        scope.registerFactories(MockContextFactory.createWiredContexts(Scope.MODULE,scope));
        scope.start();
        scope.onEvent(new ModuleStart(this));
        OrderedDependentPojo source = (OrderedDependentPojo) scope.getContext("source").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();
        SessionScopeContext scope = new SessionScopeContext(ctx);
        scope.registerFactories(createConfigurations());
        scope.start();
        Object session = new Object();
        Object session2 = 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);

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

        // third request, different session
        ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session2);
        SessionScopeComponent comp3 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null);
        Assert.assertNotNull(comp3);
        Assert.assertNotSame(comp1, comp3); // should be different instances
        ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER);

        scope.onEvent(new HttpSessionEnd(this, session));
        scope.onEvent(new HttpSessionEnd(this, session2));
        scope.stop();
    }
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();
        SessionScopeContext scope = new SessionScopeContext(ctx);
        scope.registerFactories(new ArrayList<ContextFactory<Context>>());
        scope.start();
        scope.stop();
    }
View Full Code Here

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

        scope.start();
        scope.stop();
    }

    public void testGetContextByKey() throws Exception {
        EventContext ctx = new EventContextImpl();
        SessionScopeContext scope = new SessionScopeContext(ctx);
        scope.registerFactories(createConfigurations());
        scope.start();
        Object session = new Object();
        Object session2 = 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);

        // second request, different session
        ctx.setIdentifier(HttpSessionEvent.HTTP_IDENTIFIER, session2);
        SessionScopeComponent comp2 = (SessionScopeComponent) scope.getContextByKey("TestService1", session)
                .getInstance(null);
        SessionScopeComponent comp3 = (SessionScopeComponent) scope.getContextByKey("TestService1", session)
                .getInstance(null);
        Assert.assertNotNull(comp2);
        Object id = new Object();
        scope.onEvent(new RequestEnd(this, id));
        Assert.assertSame(comp1, comp2); // should be same instances
        Assert.assertSame(comp2, comp3); // should not be same instances
        ctx.clearIdentifier(HttpSessionEvent.HTTP_IDENTIFIER);

        // shutdown sessions
        scope.onEvent(new HttpSessionEnd(this, session));
        scope.onEvent(new HttpSessionEnd(this, session2));
View Full Code Here

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

        scope.stop();
    }

    public void testRegisterContextBeforeSession() throws Exception {
        EventContext ctx = new EventContextImpl();
        SessionScopeContext scope = new SessionScopeContext(ctx);
        scope.registerFactories(createConfigurations());
        scope.start();
        Object session = new Object();
        scope.registerFactory(createConfiguration("NewTestService"));

        // first 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);

        // second 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
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.