Package org.apache.tuscany.core.context

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


        Assert.assertNotNull(service2);
        Assert.assertSame(service, service2);
    }

    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");
View Full Code Here


        Assert.assertNotNull(service2);
        Assert.assertSame(service, service2);
    }

    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");
View Full Code Here

        Assert.assertNotNull(service2);
        Assert.assertSame(service, service2);
    }

    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");
View Full Code Here

     * <p/>
     * <strong>NB:</strong> the test assumes an error with a message containing
     * "@ComponentName" is generated
     */
    public void testBadNameType() throws Exception {
        CompositeContext mc = new CompositeContextImpl();
        mc.setName("mc");
        try {
            MockFactory.createPojoContext("BadNamePojo", BadNamePojo.class, Scope.MODULE, mc);
        } catch (NoSuchMethodException e) {
            if (e.getMessage().indexOf("@ComponentName") < 0) {
                throw e;
View Full Code Here

     * <p/>
     * <strong>NB:</strong> the test assumes an error with a message containing
     * "@Context" is generated
     */
    public void testContextType() throws Exception {
        CompositeContext mc = new CompositeContextImpl();
        mc.setName("mc");
        try {
            MockFactory.createPojoContext("BadContextPojo", BadContextPojo.class, Scope.MODULE, mc);
        } catch (NoSuchMethodException e) {
            if (e.getMessage().indexOf("@Context") < 0) {
                throw e;
View Full Code Here

* @version $Rev$ $Date$
*/
public class MultiplicityTestCase extends TestCase {

    public void testMultiplicity() throws Exception {
        CompositeContext context = createContext();
        context.start();
        context.registerModelObject(MockFactory.createModuleWithWiredComponents(Scope.MODULE, Scope.MODULE));
        context.publish(new ModuleStart(this));
        Source source = (Source) ((AtomicContext) context.getContext("source")).getTargetInstance();
        Assert.assertNotNull(source);
        Target target = (Target) ((AtomicContext)context.getContext("target")).getTargetInstance();
        Assert.assertNotNull(target);
        // test setter injection
        List<Target> targets = source.getTargets();
        Assert.assertEquals(1, targets.size());

View Full Code Here

    /**
     * Ensures scope events are propagated in an composite scope
     */
    public void testCompositeScopePropagation() throws Exception {
        EventContext ctx = new EventContextImpl();
        CompositeContext moduleComponentCtx = new CompositeContextImpl();
        moduleComponentCtx.setName("testMC");
        moduleComponentCtx.start();
        CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx);
        scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent"));
        scopeContainer.start();
        CompositeContext child = (CompositeContext) scopeContainer.getContext("CompositeComponent");
        List<Extensible> models = createAssembly();
        for (Extensible model : models) {
            child.registerModelObject(model);
        }

        scopeContainer.onEvent(new ModuleStart(this));
        Object session = new Object();
        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

    /**
     * Ensures only child entry points (and not components) are accessible from parents
     */
    public void testCompositeNoEntryPoint() throws Exception {
        EventContext ctx = new EventContextImpl();
        CompositeContext moduleComponentCtx = new CompositeContextImpl();
        moduleComponentCtx.setName("testMC");
        CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx);
        scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent"));
        scopeContainer.start();
        CompositeContext child = (CompositeContext) scopeContainer.getContext("CompositeComponent");
        List<Extensible> parts = createAssembly();
        for (Extensible part : parts) {
            child.registerModelObject(part);
        }
        scopeContainer.onEvent(new ModuleStart(this));
        scopeContainer.getContext("CompositeComponent");
    }
View Full Code Here

    /**
     * Tests adding a context before its parent has been started
     */
    public void testRegisterContextBeforeStart() throws Exception {
        EventContext ctx = new EventContextImpl();
        CompositeContext moduleComponentCtx = new CompositeContextImpl();
        moduleComponentCtx.setName("testMC");
        CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx);
        scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent"));
        scopeContainer.start();
        scopeContainer.onEvent(new ModuleStart(this));
        scopeContainer.getContext("CompositeComponent");
View Full Code Here

    /**
     * Tests adding a context after its parent has been started
     */
    public void testRegisterContextAfterStart() throws Exception {
        EventContext ctx = new EventContextImpl();
        CompositeContext moduleComponentCtx = new CompositeContextImpl();
        moduleComponentCtx.setName("testMC");
        CompositeScopeContext scopeContainer = new CompositeScopeContext(ctx);
        scopeContainer.start();

        scopeContainer.onEvent(new ModuleStart(this));
        scopeContainer.registerFactory(MockFactory.createCompositeConfiguration("CompositeComponent"));
View Full Code Here

TOP

Related Classes of org.apache.tuscany.core.context.CompositeContext

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.