Package org.apache.tuscany.container.java.mock.components

Examples of org.apache.tuscany.container.java.mock.components.GenericComponent


        testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.MODULE));
        testCtx.publish(new ModuleStart(this));
       
        Object id = new Object();
        testCtx.publish(new RequestStart(this,id));
        GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
        Assert.assertNotNull(source);
        GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
        Assert.assertNotNull(target);
        source.getGenericComponent().setString("foo");
        Assert.assertEquals("foo",target.getString());
        testCtx.publish(new RequestEnd(this,new Object()));

        //second session
        Object id2 = new Object();
        testCtx.publish(new RequestStart(this,id2));
        GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
        Assert.assertNotNull(source2);
        GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);

        Assert.assertNotNull(target2);
        Assert.assertEquals("foo",target2.getString());
        Assert.assertEquals("foo",source2.getGenericComponent().getString());
        source2.getGenericComponent().setString("baz");
        Assert.assertEquals("baz",source2.getGenericComponent().getString());
        Assert.assertEquals("baz",target2.getString());
       
        testCtx.publish(new RequestEnd(this,new Object()));

    }
View Full Code Here


    public void testGetModuleInstance() throws Exception {
        CompositeContext mc = new CompositeContextImpl();
        mc.setName("mc");
        JavaAtomicContext c = new JavaAtomicContext("foo", new PojoObjectFactory<ModuleScopeComponentImpl>(JavaIntrospectionHelper
                .getDefaultConstructor(ModuleScopeComponentImpl.class), null, null), false, null, null, false);
        GenericComponent service = (GenericComponent) c.getInstance(null);
        Assert.assertNotNull(service);
        service.setString("foo");
        GenericComponent service2 = (GenericComponent) c.getInstance(null);
        Assert.assertNotNull(service2);
        Assert.assertSame(service, service2);
    }
View Full Code Here

    public void testGetSessionInstance() throws Exception {
        CompositeContext mc = new CompositeContextImpl();
        mc.setName("mc");
        JavaAtomicContext c = new JavaAtomicContext("foo", new PojoObjectFactory<SessionScopeComponentImpl>(JavaIntrospectionHelper
                .getDefaultConstructor(SessionScopeComponentImpl.class), null, null), false, null, null, false);
        GenericComponent service = (GenericComponent) c.getInstance(null);
        Assert.assertNotNull(service);
        service.setString("foo");
        GenericComponent service2 = (GenericComponent) c.getInstance(null);
        Assert.assertNotNull(service2);
        Assert.assertSame(service, service2);
    }
View Full Code Here

    public void testGetRequestInstance() throws Exception {
        CompositeContext mc = new CompositeContextImpl();
        mc.setName("mc");
        JavaAtomicContext c = new JavaAtomicContext("foo", new PojoObjectFactory<RequestScopeComponentImpl>(JavaIntrospectionHelper
                .getDefaultConstructor(RequestScopeComponentImpl.class), null, null), false, null, null, false);
        GenericComponent service = (GenericComponent) c.getInstance(null);
        Assert.assertNotNull(service);
        service.setString("foo");
        GenericComponent service2 = (GenericComponent) c.getInstance(null);
        Assert.assertNotNull(service2);
        Assert.assertSame(service, service2);
    }
View Full Code Here

    public void testGetStatelessInstance() throws Exception {
        CompositeContext mc = new CompositeContextImpl();
        mc.setName("fooContext");
        JavaAtomicContext c = new JavaAtomicContext("foo", new PojoObjectFactory<StatelessComponentImpl>(JavaIntrospectionHelper
                .getDefaultConstructor(StatelessComponentImpl.class), null, null), false, null, null, true);
        GenericComponent service = (GenericComponent) c.getInstance(null);
        Assert.assertNotNull(service);
        service.setString("foo");
        GenericComponent service2 = (GenericComponent) c.getInstance(null);
        Assert.assertNotNull(service2);
        Assert.assertTrue(!"foo".equals(service2.getString()));
    }
View Full Code Here

        Object id = new Object();
        //ctx.setIdentifier(EventContext.SESSION,session);
        scopeContainer.onEvent(new RequestStart(this,id));
        scopeContainer.onEvent(new HttpSessionBound(this,session));
        CompositeContext componentCtx = (CompositeContext) scopeContainer.getContext("CompositeComponent");
        GenericComponent testService1 = (GenericComponent) componentCtx.getContext("TestService1").getInstance(null);
        GenericComponent testService2 = (GenericComponent) componentCtx.getContext("TestService2").getInstance(null);
        GenericComponent testService3 = (GenericComponent) componentCtx.getContext("TestService3").getInstance(null);
        Assert.assertNotNull(testService1);
        Assert.assertNotNull(testService2);
        Assert.assertNotNull(testService3);
        scopeContainer.onEvent(new RequestEnd(this,id));
        scopeContainer.onEvent(new RequestStart(this,id));
        scopeContainer.onEvent(new HttpSessionBound(this,session));

        GenericComponent testService2a = (GenericComponent) componentCtx.getContext("TestService2").getInstance(null);
        Assert.assertNotNull(testService2a);
        GenericComponent testService3a = (GenericComponent) componentCtx.getContext("TestService3").getInstance(null);
        Assert.assertNotNull(testService3a);
        Assert.assertEquals(testService2, testService2a);
        Assert.assertNotSame(testService3, testService3a);
        scopeContainer.onEvent(new RequestEnd(this,id));
        scopeContainer.onEvent(new HttpSessionEnd(this,session));

        Object session2 = new Object();
        Object id2 = new Object();
        scopeContainer.onEvent(new RequestStart(this,id2));
        scopeContainer.onEvent(new HttpSessionBound(this,session2));
        GenericComponent testService2b = (GenericComponent) componentCtx.getContext("TestService2").getInstance(null);
        Assert.assertNotNull(testService2b);
        Assert.assertNotSame(testService2, testService2b);

        scopeContainer.onEvent(new RequestEnd(this,id2));
        scopeContainer.onEvent(new HttpSessionEnd(this,session2));
View Full Code Here

        runtime.getRootContext().registerModelObject(MockFactory.createCompositeComponent("test"));
        CompositeContext testCtx = (CompositeContext) runtime.getRootContext().getContext("test");
        Assert.assertNotNull(testCtx);
        testCtx.registerModelObject(MockFactory.createModule());
        testCtx.publish(new ModuleStart(this));
        GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
        Assert.assertNotNull(source);
        GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
        Assert.assertNotNull(target);
        source.getGenericComponent().getString();
   }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.container.java.mock.components.GenericComponent

Copyright © 2018 www.massapicom. 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.