Package org.apache.tuscany.spi.component

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


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


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

        impl.setComponentType(type);
        impl.setImplementationClass(Foo.class);
        ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(impl);
        PropertyValue propertyValue = new PropertyValue(property.getName(), property.getDefaultValueFactory());
        definition.getPropertyValues().put(property.getName(), propertyValue);
        AtomicComponent component = builder.build(parent, definition, deploymentContext);
        JavaBuilderPropertyTestCase.Foo foo = (JavaBuilderPropertyTestCase.Foo) component.createInstance();
        assertEquals("foo", foo.getTest());
    }
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);
        AtomicComponent component = builder.build(parent, definition, deploymentContext);
        component.start();
        container.onEvent(new CompositeStart(this, null));
        FooImpl foo = (FooImpl) component.getServiceInstance();
        assertTrue(foo.initialized);
        container.onEvent(new CompositeStop(this, null));
        assertTrue(foo.destroyed);
    }
View Full Code Here

        ComponentDefinition<SystemImplementation> definition = new ComponentDefinition<SystemImplementation>(impl);
        PropertyValue<String> propVal = new PropertyValue<String>();
        propVal.setName("prop");
        propVal.setValueFactory(new SingletonObjectFactory<String>("value"));
        definition.add(propVal);
        AtomicComponent component = builder.build(parent, definition, deploymentContext);
        component.start();
        FooImpl foo = (FooImpl) component.getServiceInstance();
        assertEquals("value", foo.prop);
        container.onEvent(new CompositeStop(this, null));
    }
View Full Code Here

        ComponentDefinition<SystemImplementation> definition = new ComponentDefinition<SystemImplementation>(impl);
        ReferenceTarget target = new ReferenceTarget();
        target.setReferenceName("ref");
        target.addTarget(new URI("foo"));
        definition.add(target);
        AtomicComponent component = builder.build(parent, definition, deploymentContext);
        OutboundWire wire = component.getOutboundWires().get("ref").get(0);
        SystemInboundWire inbound = EasyMock.createMock(SystemInboundWire.class);
        FooImpl targetFoo = new FooImpl();
        EasyMock.expect(inbound.getTargetService()).andReturn(targetFoo);
        EasyMock.replay(inbound);
        wire.setTargetWire(inbound);
        component.start();
        FooImpl foo = (FooImpl) component.getServiceInstance();
        assertNotNull(foo.ref);
        container.onEvent(new CompositeStop(this, null));
        EasyMock.verify(inbound);
    }
View Full Code Here

        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);
        container.onEvent(new CompositeStop(this, null));
        EasyMock.verify(parent);
    }
View Full Code Here

        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();
        assertNotNull(foo.getRef());
        container.onEvent(new CompositeStop(this, null));
        EasyMock.verify(parent);
    }
View Full Code Here

        deploymentContext.getModuleScope().start();
        component.start();
        CompositeComponent sourceComponent = (CompositeComponent) component.getChild("SourceComponent");
        Source source = (Source) sourceComponent.getServiceInstance("InnerSourceService");
        assertNotNull(source);
        AtomicComponent innerSourceComponent = (AtomicComponent) sourceComponent.getChild("InnerSourceComponent");
        Source innerSourceInstance = (Source) deploymentContext.getModuleScope().getInstance(innerSourceComponent);
        assertNotNull(innerSourceInstance);
        component.stop();
    }
View Full Code Here

        EasyMock.expect(container.getScope()).andReturn(Scope.MODULE).anyTimes();
        EasyMock.expect(container.getInstance(EasyMock.isA(AtomicComponent.class))).andAnswer(new IAnswer<Object>() {
            private Map<AtomicComponent, Object> cache = new HashMap<AtomicComponent, Object>();

            public Object answer() throws Throwable {
                AtomicComponent component = (AtomicComponent) EasyMock.getCurrentArguments()[0];
                Object instance = cache.get(component);
                if (instance == null) {
                    instance = component.createInstance();
                    cache.put(component, instance);
                }
                return instance;
            }
        });
View Full Code Here

TOP

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

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.