Package org.apache.tuscany.spi.component

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



    public void testAutowire() throws Exception {
        List<Class<?>> services = new ArrayList<Class<?>>();
        services.add(Foo.class);
        CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null);
        SystemAtomicComponent component = EasyMock.createMock(SystemAtomicComponent.class);
        component.start();
        EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce();
        EasyMock.expect(component.getServiceInterfaces()).andReturn(services);
        EasyMock.expect(component.getServiceInstance()).andReturn(new Foo() {
        });
        EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce();
        component.stop();
        EasyMock.replay(component);
        parent.register(component);
        parent.start();
        assertNull(parent.resolveExternalInstance(Foo.class));
        assertNotNull(parent.resolveInstance(Foo.class));
        parent.stop();
        EasyMock.verify(component);
    }
View Full Code Here


    /**
     * Tests autowiring to an system atomic component
     */
    public void testSystemAtomicAutowire() throws Exception {
        CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null);
        parent.start();

        List<Class<?>> interfaces = new ArrayList<Class<?>>();
        interfaces.add(Source.class);
        interfaces.add(Source2.class);
        Source originalSource = new SourceImpl();
        SystemAtomicComponent component = EasyMock.createMock(SystemAtomicComponent.class);
        EasyMock.expect(component.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(component.getServiceInstance()).andReturn(originalSource).atLeastOnce();
        EasyMock.expect(component.getServiceInterfaces()).andReturn(interfaces);
        EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce();

        EasyMock.replay(component);
        parent.register(component);

        Source source = parent.resolveSystemInstance(Source.class);
        assertNotNull(source);
        Source2 source2 = parent.resolveSystemInstance(Source2.class);
        assertSame(source, source2);
        assertNull(parent.resolveSystemExternalInstance(Source.class));
        EasyMock.verify(component);
    }
View Full Code Here

    /**
     * Tests autowiring to an system atomic component
     */
    public void testAtomicAutowire() throws Exception {
        CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null);
        parent.start();

        List<Class<?>> interfaces = new ArrayList<Class<?>>();
        interfaces.add(Source.class);
        interfaces.add(Source2.class);
        Source originalSource = new SourceImpl();
        AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
        EasyMock.expect(component.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(component.getServiceInstance()).andReturn(originalSource).atLeastOnce();
        EasyMock.expect(component.getServiceInterfaces()).andReturn(interfaces);
        EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce();

        EasyMock.replay(component);
        parent.register(component);

        Source source = parent.resolveInstance(Source.class);
        assertNotNull(source);
        Source2 source2 = parent.resolveInstance(Source2.class);
        assertSame(source, source2);
        assertNull(parent.resolveExternalInstance(Source.class));
        EasyMock.verify(component);
    }
View Full Code Here

        BuilderRegistry registry = createNiceMock(BuilderRegistry.class);

        // Test the SpringCompositeBuilder
        SpringCompositeBuilder builder = new SpringCompositeBuilder();
        builder.setBuilderRegistry(registry);
        CompositeComponent parent = createNiceMock(CompositeComponent.class);
        DeploymentContext context = createNiceMock(DeploymentContext.class);
        SpringCompositeComponent component =
            (SpringCompositeComponent) builder.build(parent, componentDefinition, context);
        TestBean bean = (TestBean) component.getApplicationContext().getBean("foo");
        assertEquals("call foo", bean.echo("call foo"));
View Full Code Here

        // Test the SpringCompositeBuilder
        SpringCompositeBuilder builder = new SpringCompositeBuilder();
        builder.setWireService(wireService);
        builder.setBuilderRegistry(registry);
        CompositeComponent parent = createNiceMock(CompositeComponent.class);
        DeploymentContext context = createNiceMock(DeploymentContext.class);
        CompositeComponent component = (CompositeComponent) builder.build(parent, componentDefinition, context);
        Service service = component.getService("fooService");
        TestBean bean = (TestBean) service.getServiceInstance();
        assertEquals("call foo", bean.echo("call foo"));
        verify(registry);
    }
View Full Code Here

    /**
     * Tests autowiring to a system service which is wired to an atomic component.
     */
    public void testSystemServiceAutowire() throws Exception {
        CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null);
        parent.start();

        List<Class<?>> interfaces = new ArrayList<Class<?>>();
        interfaces.add(Source.class);
        interfaces.add(Source2.class);

        Source serviceSource = new SourceImpl();
        SystemService component = EasyMock.createMock(SystemService.class);
        EasyMock.expect(component.getName()).andReturn("service").atLeastOnce();
        component.getInterface();
        EasyMock.expectLastCall().andReturn(Source.class).atLeastOnce();
        EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce();
        EasyMock.expect(component.getServiceInstance()).andReturn(serviceSource);
        EasyMock.replay(component);
        parent.register(component);


        SystemAtomicComponent component2 = EasyMock.createMock(SystemAtomicComponent.class);
        EasyMock.expect(component2.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(component2.getServiceInterfaces()).andReturn(interfaces).atLeastOnce();
        EasyMock.expect(component2.isSystem()).andReturn(true).atLeastOnce();
        EasyMock.replay(component2);
        parent.register(component2);

        Source source = parent.resolveSystemExternalInstance(Source.class);
        assertSame(serviceSource, source);
        Source2 source2 = parent.resolveSystemExternalInstance(Source2.class);
        assertNull(source2);
        EasyMock.verify(component);
        EasyMock.verify(component2);
    }
View Full Code Here

    /**
     * Tests autowiring to a system service which is wired to an atomic component.
     */
    public void testServiceAutowire() throws Exception {
        CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null);
        parent.start();

        List<Class<?>> interfaces = new ArrayList<Class<?>>();
        interfaces.add(Source.class);
        interfaces.add(Source2.class);

        Source serviceSource = new SourceImpl();
        Service component = EasyMock.createMock(Service.class);
        EasyMock.expect(component.getName()).andReturn("service").atLeastOnce();
        component.getInterface();
        EasyMock.expectLastCall().andReturn(Source.class).atLeastOnce();
        EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce();
        EasyMock.expect(component.getServiceInstance()).andReturn(serviceSource);
        EasyMock.replay(component);
        parent.register(component);


        AtomicComponent component2 = EasyMock.createMock(AtomicComponent.class);
        EasyMock.expect(component2.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(component2.getServiceInterfaces()).andReturn(interfaces).atLeastOnce();
        EasyMock.expect(component2.isSystem()).andReturn(false).atLeastOnce();
        EasyMock.replay(component2);
        parent.register(component2);

        Source source = parent.resolveExternalInstance(Source.class);
        assertSame(serviceSource, source);
        Source2 source2 = parent.resolveExternalInstance(Source2.class);
        assertNull(source2);
        EasyMock.verify(component);
        EasyMock.verify(component2);
    }
View Full Code Here

    /**
     * Tests autowiring to a system reference
     */
    public void testSystemReferenceAutowire() throws Exception {
        CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null);
        parent.start();

        Source refSource = new SourceImpl();
        SystemReference reference = EasyMock.createMock(SystemReference.class);
        EasyMock.expect(reference.getName()).andReturn("service").atLeastOnce();
        EasyMock.expect(reference.getServiceInstance()).andReturn(refSource);
        EasyMock.expect(reference.isSystem()).andReturn(true).atLeastOnce();
        reference.getInterface();
        EasyMock.expectLastCall().andReturn(Source.class);
        EasyMock.replay(reference);
        parent.register(reference);

        Source source = parent.resolveSystemInstance(Source.class);
        assertNotNull(source);
        assertNull(parent.resolveSystemExternalInstance(Source.class));
        EasyMock.verify(reference);
    }
View Full Code Here

    /**
     * Tests autowiring to a reference
     */
    public void testReferenceAutowire() throws Exception {
        CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null);
        parent.start();
        Source refSource = new SourceImpl();
        Reference reference = EasyMock.createMock(Reference.class);
        EasyMock.expect(reference.getName()).andReturn("service").atLeastOnce();
        EasyMock.expect(reference.getServiceInstance()).andReturn(refSource);
        EasyMock.expect(reference.isSystem()).andReturn(false).atLeastOnce();
        reference.getInterface();
        EasyMock.expectLastCall().andReturn(Source.class);
        EasyMock.replay(reference);
        parent.register(reference);

        Source source = parent.resolveInstance(Source.class);
        assertNotNull(source);
        assertNull(parent.resolveExternalInstance(Source.class));
        EasyMock.verify(reference);
    }
View Full Code Here

*/
public class SystemComponentTypeLoaderTestCase extends TestCase {
    private SystemComponentTypeLoader loader;

    public void testIntrospectUnannotatedClass() throws ProcessingException {
        CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class);
        SystemImplementation impl = new SystemImplementation(BasicInterfaceImpl.class);
        PojoComponentType<?, ?, ?> componentType = loader.loadByIntrospection(parent, impl, null);
        ServiceDefinition service = componentType.getServices().get("BasicInterface");
        assertEquals(BasicInterface.class, service.getServiceContract().getInterfaceClass());
        Property<?> property = componentType.getProperties().get("publicProperty");
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.