Package org.apache.tuscany.spi.component

Examples of org.apache.tuscany.spi.component.CompositeComponent


        composite.register(getReference("bar"));
        Assert.assertEquals(1, composite.getReferences().size());
    }

    public void testServiceInterfaces() {
        CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null);
        Service service1 = getService("foo", Foo.class);
        composite.register(service1);
        Service service2 = getService("bar", Bar.class);
        composite.register(service2);

        List<Class<?>> interfaces = composite.getServiceInterfaces();
        assertEquals(2, interfaces.size());
        for (Class o : interfaces) {
            if (!(Foo.class.isAssignableFrom(o)) && !(Bar.class.isAssignableFrom(o))) {
                fail();
            }
View Full Code Here


            }
        }
    }

    public void testGetServiceInstanceByName() {
        CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null);
        Service service = createMock(Service.class);
        EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce();
        service.getName();
        expectLastCall().andReturn("foo").anyTimes();
        service.getInterface();
        expectLastCall().andReturn(Foo.class);
        service.getServiceInstance();
        expectLastCall().andReturn(new Foo() {
        });
        replay(service);
        composite.register(service);
        assertNotNull(composite.getServiceInstance("foo"));
    }
View Full Code Here

        composite.register(service);
        assertNotNull(composite.getServiceInstance("foo"));
    }

    public void testGetServiceInstanceNotFound() {
        CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null);
        Service service = getService("foo", Foo.class);
        composite.register(service);
        try {
            composite.getServiceInstance("bar");
            fail();
        } catch (TargetNotFoundException e) {
            //expected
        }
    }
View Full Code Here

            //expected
        }
    }

    public void testGetServiceInstanceNotService() {
        CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null);
        Reference reference = getReference("foo");
        composite.register(reference);
        try {
            composite.getServiceInstance("foo");
            fail();
        } catch (IllegalTargetException e) {
            //expected
        }
    }
View Full Code Here

            //expected
        }
    }

    public void testOnEvent() {
        CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null);
        Event event = new Event() {
            public Object getSource() {
                return null;
            }
        };
        RuntimeEventListener listener = createMock(RuntimeEventListener.class);
        listener.onEvent(isA(CompositeStart.class));
        listener.onEvent(eq(event));
        expectLastCall();
        replay(listener);
        composite.addListener(listener);
        composite.start();
        composite.onEvent(event);
    }
View Full Code Here

        composite.start();
        composite.onEvent(event);
    }

    public void testPrepare() {
        CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null);
        composite.prepare();
    }
View Full Code Here


    protected void setUp() throws Exception {
        super.setUp();
        parent = new CompositeComponentImpl("parent", null, null, null);
        CompositeComponent child1 = new CompositeComponentImpl("child1", parent, null, null);
        child2 = new CompositeComponentImpl("child2", child1, null, null);
        child1.register(child2);
        parent.register(child1);
    }
View Full Code Here

        type.setConstructorDefinition(ctorDef);
        SystemImplementation impl = new SystemImplementation();
        impl.setComponentType(type);
        impl.setImplementationClass(FooImpl.class);
        ComponentDefinition<SystemImplementation> definition = new ComponentDefinition<SystemImplementation>(impl);
        CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class);
        FooImpl targetFoo = new FooImpl();
        EasyMock.expect(parent.resolveSystemInstance(EasyMock.eq(Foo.class))).andReturn(targetFoo);
        EasyMock.replay(parent);
        AtomicComponent component = builder.build(parent, definition, deploymentContext);
        component.start();
        FooImpl foo = (FooImpl) component.getServiceInstance();
        assertNotNull(foo.ref);
View Full Code Here

        mappedReference.setAutowire(true);
        ServiceContract contract = new JavaServiceContract(Foo.class);
        mappedReference.setServiceContract(contract);
        type.add(mappedReference);
        ComponentDefinition<SystemImplementation> definition = new ComponentDefinition<SystemImplementation>(impl);
        CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class);
        FooImpl targetFoo = new FooImpl();
        EasyMock.expect(parent.resolveSystemInstance(EasyMock.eq(Foo.class))).andReturn(targetFoo);
        EasyMock.replay(parent);
        AtomicComponent component = builder.build(parent, definition, deploymentContext);
        component.start();
        container.onEvent(new CompositeStart(this, null));
        FooImpl2 foo = (FooImpl2) component.getServiceInstance();
View Full Code Here

    private OutboundWire getWire(ScopeContainer scope) throws NoSuchMethodException,
                                                              InvalidServiceContractException {
        ConnectorImpl connector = new ConnectorImpl();

        CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);

        PojoConfiguration configuration = new PojoConfiguration();
        configuration.setScopeContainer(scope);
        configuration.setInstanceFactory(new PojoObjectFactory<TargetImpl>(TargetImpl.class.getConstructor()));
        configuration.addServiceInterface(Target.class);
        configuration.setParent(parent);

        JavaAtomicComponent source = new JavaAtomicComponent("source", configuration, null);
        OutboundWire outboundWire = createOutboundWire(new QualifiedName("target/Target"), Target.class);
        outboundWire.setContainer(source);
        source.addOutboundWire(outboundWire);
        JavaAtomicComponent target = new JavaAtomicComponent("target", configuration, null);
        InboundWire targetWire = MockFactory.createTargetWire("Target", Target.class);
        targetWire.setContainer(target);
        target.addInboundWire(targetWire);
        InboundWire inboundWire = target.getInboundWire("Target");
        inboundWire.setContainer(target);

        EasyMock.expect(parent.getChild("target")).andReturn(target);
        EasyMock.replay(parent);

        connector.connect(source);
        target.start();
        return outboundWire;
View Full Code Here

TOP

Related Classes of org.apache.tuscany.spi.component.CompositeComponent

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.