Package org.apache.tuscany.spi.component

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


        scope.start();

        Connector connector = new ConnectorImpl();
        SystemComponentBuilder builder = new SystemComponentBuilder();

        CompositeComponent parent = new CompositeComponentImpl(null, null, connector, null);

        ComponentDefinition<SystemImplementation> targetComponentDefinition = MockComponentFactory.createTarget();
        ComponentDefinition<SystemImplementation> sourceComponentDefinition =
            MockComponentFactory.createSourceWithTargetReference();

        AtomicComponent sourceComponent = builder.build(parent, sourceComponentDefinition, deploymentContext);
        AtomicComponent targetComponent = builder.build(parent, targetComponentDefinition, deploymentContext);

        parent.register(sourceComponent);
        parent.register(targetComponent);
        parent.prepare();
        parent.start();
        scope.onEvent(new CompositeStart(this, parent));
        Source source = (Source) parent.getSystemChild("source").getServiceInstance();
        assertNotNull(source);
        Target target = (Target) parent.getSystemChild("target").getServiceInstance();
        assertNotNull(target);
        assertSame(target, source.getTarget());
        scope.onEvent(new CompositeStop(this, parent));
        parent.stop();
        scope.stop();
    }
View Full Code Here


        Connector connector = new ConnectorImpl();
        SystemComponentBuilder builder = new SystemComponentBuilder();
        SystemBindingBuilder bindingBuilder = new SystemBindingBuilder();

        CompositeComponent grandParent = new CompositeComponentImpl("grandparent", null, null, null);
        CompositeComponent parent = new CompositeComponentImpl("parent", grandParent, null, null);

        // create a context in the grandparent that the reference will be autowired to
        ComponentDefinition<SystemImplementation> targetComponentDefinition = MockComponentFactory.createTarget();
        AtomicComponent targetComponentComponent = builder.build(parent, targetComponentDefinition, deploymentContext);
        grandParent.register(targetComponentComponent);

        BoundReferenceDefinition<SystemBinding> targetReferenceDefinition = MockComponentFactory.createBoundReference();
        ComponentDefinition<SystemImplementation> sourceComponentDefinition =
            MockComponentFactory.createSourceWithTargetReference();

        AtomicComponent sourceComponent = builder.build(parent, sourceComponentDefinition, deploymentContext);
        Reference reference = bindingBuilder.build(parent, targetReferenceDefinition, deploymentContext);

        parent.register(sourceComponent);
        parent.register(reference);
        connector.connect(reference.getInboundWire(), reference.getOutboundWire(), true);
        connector.connect(sourceComponent);
        grandParent.register(parent);
        grandParent.start();
        scope.onEvent(new CompositeStart(this, parent));
        Source source = (Source) parent.getSystemChild("source").getServiceInstance();
        assertNotNull(source);
        Target target = (Target) parent.getSystemChild("target").getServiceInstance();
        assertNotNull(target);
        assertSame(target, source.getTarget());
        scope.onEvent(new CompositeStop(this, parent));
        grandParent.stop();
        scope.stop();
View Full Code Here

        ConnectorImpl connector = new ConnectorImpl();
        SystemComponentBuilder builder = new SystemComponentBuilder();
        SystemBindingBuilder bindingBuilder = new SystemBindingBuilder();

        CompositeComponent parent = new CompositeComponentImpl(null, null, null, null);

        BoundServiceDefinition<SystemBinding> serviceDefinition = MockComponentFactory.createBoundService();
        ComponentDefinition<SystemImplementation> componentDefinition = MockComponentFactory.createTarget();

        AtomicComponent sourceComponent = builder.build(parent, componentDefinition, deploymentContext);
        parent.register(sourceComponent);

        Service service = bindingBuilder.build(parent, serviceDefinition, deploymentContext);
        parent.register(service);

        connector.connect(sourceComponent);
        connector.connect(service);

        parent.start();
        scope.onEvent(new CompositeStart(this, parent));
        Target target = (Target) parent.getSystemChild("serviceDefinition").getServiceInstance();
        assertNotNull(target);
        Target target2 = (Target) parent.getSystemChild("target").getServiceInstance();
        assertNotNull(target);
        assertSame(target, target2);
        scope.onEvent(new CompositeStop(this, parent));
        parent.stop();
        scope.stop();

    }
View Full Code Here

* @version $Rev: 451895 $ $Date: 2006-10-01 23:58:18 -0700 (Sun, 01 Oct 2006) $
*/
public class DuplicateRegistrationTestCase extends TestCase {

    public void testDuplicateRegistration() throws Exception {
        CompositeComponent parent = new CompositeComponentImpl(null, null, null, null);
        parent.start();

        List<Class<?>> interfaces = new ArrayList<Class<?>>();
        interfaces.add(Source.class);
        SystemAtomicComponent component1 = EasyMock.createMock(SystemAtomicComponent.class);
        EasyMock.expect(component1.getName()).andReturn("source").atLeastOnce();
        EasyMock.expect(component1.isSystem()).andReturn(true).atLeastOnce();
        component1.stop();
        EasyMock.expect(component1.getServiceInterfaces()).andReturn(interfaces);
        EasyMock.replay(component1);

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

        parent.register(component1);
        try {
            parent.register(component2);
            fail();
        } catch (DuplicateNameException e) {
            // ok
        }
        parent.stop();
    }
View Full Code Here

    }

    public void testDuplicateNameSystemService() throws Exception {
        List<Class<?>> services = new ArrayList<Class<?>>();
        services.add(Source.class);
        CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null);
        SystemAtomicComponent component = EasyMock.createMock(SystemAtomicComponent.class);
        EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce();
        EasyMock.expect(component.getServiceInterfaces()).andReturn(services);
        EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce();
        EasyMock.replay(component);
        parent.register(component);
        SystemAtomicComponent component2 = EasyMock.createMock(SystemAtomicComponent.class);
        EasyMock.expect(component2.getName()).andReturn("bar").atLeastOnce();
        EasyMock.expect(component2.getServiceInterfaces()).andReturn(services);
        EasyMock.expect(component2.isSystem()).andReturn(true).atLeastOnce();
        EasyMock.replay(component2);
        try {
            parent.register(component2);
            fail();
        } catch (DuplicateNameException e) {
            // expected
        }
    }
View Full Code Here

        JavaAtomicComponent fooComponent =
            (JavaAtomicComponent) builder.build(null, targetDefinition, context);
        wireService.createWires(fooComponent, targetDefinition);
        container.register(fooComponent);

        CompositeComponent parent = createMock(CompositeComponent.class);
        parent.getChild(isA(String.class));
        expectLastCall().andReturn(fooComponent).anyTimes();
        replay(parent);

        ComponentDefinition<JavaImplementation> sourceDefinition = createSource("fooClient");
        JavaAtomicComponent clientComponent =
View Full Code Here

        JavaAtomicComponent fooComponent =
            (JavaAtomicComponent) builder.build(null, targetDefinition, context);
        wireService.createWires(fooComponent, targetDefinition);
        container.register(fooComponent);

        CompositeComponent parent = createMock(CompositeComponent.class);
        parent.getChild(isA(String.class));
        expectLastCall().andReturn(fooComponent).anyTimes();
        replay(parent);

        ComponentDefinition<JavaImplementation> sourceDefinition1 = createSource("fooCleint1");
        ComponentDefinition<JavaImplementation> sourceDefinition2 = createSource("fooCleint2");
View Full Code Here

            // expected
        }
    }

    public void testNotService() {
        CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null);
        composite.register(getReference("foo"));
        composite.start();
        try {
            composite.getService("foo");
            fail();
        } catch (ComponentNotFoundException e) {
            // expected
        }
    }
View Full Code Here

            // expected
        }
    }

    public void testTargetNotFound() {
        CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null);
        composite.register(getReference("foo"));
        composite.start();
        try {
            composite.locateService(Foo.class, "foo1");
            fail();
        } catch (TargetNotFoundException e) {
            // expected
        }
    }
View Full Code Here

            // expected
        }
    }

    public void testReferencesServices() {
        CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null);
        composite.register(new ServiceExtension("foo", null, null, null));
        composite.register(getReference("bar"));
        Assert.assertEquals(1, composite.getReferences().size());
    }
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.