Package org.apache.tuscany.core.implementation.java

Examples of org.apache.tuscany.core.implementation.java.JavaAtomicComponent


    /**
     * Verifies callback wires are built and callback invocations are handled properly
     */
    public void testComponentToComponentCallback() throws Exception {
        ComponentDefinition<JavaImplementation> targetDefinition = createTarget();
        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 =
            (JavaAtomicComponent) builder.build(parent, sourceDefinition, context);
        wireService.createWires(clientComponent, sourceDefinition);
        container.register(clientComponent);

        Connector connector = new ConnectorImpl(new JDKWireService(), null, scheduler , workContext);

        connector.connect(clientComponent);
        FooClient client = (FooClient) clientComponent.getServiceInstance();
        client.invoke();
        assertTrue(client.invoked);
    }
View Full Code Here


     * Verifies a callback in response to an invocation from two different client components is routed back to the
     * appropriate client.
     */
    public void testTwoSourceComponentToComponentCallback() throws Exception {
        ComponentDefinition<JavaImplementation> targetDefinition = createTarget();
        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");
        JavaAtomicComponent clientComponent1 =
            (JavaAtomicComponent) builder.build(parent, sourceDefinition1, context);
        wireService.createWires(clientComponent1, sourceDefinition1);
        container.register(clientComponent1);
        JavaAtomicComponent clientComponent2 =
            (JavaAtomicComponent) builder.build(parent, sourceDefinition2, context);
        wireService.createWires(clientComponent2, sourceDefinition2);
        container.register(clientComponent2);

        Connector connector = new ConnectorImpl(new JDKWireService(), null, scheduler, workContext);
        connector.connect(clientComponent1);
        connector.connect(clientComponent2);
        FooClient client1 = (FooClient) clientComponent1.getServiceInstance();
        client1.invoke();
        assertTrue(client1.invoked);
        FooClient client2 = (FooClient) clientComponent2.getServiceInstance();
        client2.invoke();
        assertTrue(client2.invoked);
    }
View Full Code Here

    public void testNoInterceptors() throws Exception {
        AsyncTarget target = createMock(AsyncTarget.class);
        target.invoke();
        expectLastCall().once();
        replay(target);
        JavaAtomicComponent component = MockFactory.createJavaComponent(target);
        WorkScheduler scheduler = createMock(WorkScheduler.class);
        scheduler.scheduleWork(isA(Runnable.class));
        expectLastCall().andStubAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                Runnable runnable = (Runnable) getCurrentArguments()[0];
View Full Code Here

        } catch (NoSuchMethodException e) {
            throw new AssertionError(e);
        }
        configuration.addServiceInterface(DummyImpl.class);
        configuration.setWireService(WIRE_SERVICE);
        return new JavaAtomicComponent(instance.getClass().getName(), configuration, null);
    }
View Full Code Here

        PojoConfiguration configuration = new PojoConfiguration();
        configuration.setScopeContainer(scope);
        configuration.setInstanceFactory(new PojoObjectFactory(clazz.getConstructor()));
        configuration.addServiceInterface(clazz);
        configuration.setWireService(WIRE_SERVICE);
        return new JavaAtomicComponent(name, configuration, null);

    }
View Full Code Here

                                                                     Class<?> targetClass,
                                                                     ScopeContainer targetScope,
                                                                     Interceptor targetHeadInterceptor)
        throws Exception {

        JavaAtomicComponent targetContext =
            createJavaComponent(targetName, targetScope, targetClass);
        String serviceName = targetService.getName().substring(targetService.getName().lastIndexOf('.') + 1);
        InboundWire inboundWire = createServiceWire(serviceName, targetService, targetHeadInterceptor);
        targetContext.addInboundWire(inboundWire);

        PojoConfiguration configuration = new PojoConfiguration();
        configuration.setScopeContainer(sourceScope);
        configuration.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor()));
        configuration.addServiceInterface(sourceClass);
        configuration.setWireService(WIRE_SERVICE);
        for (Map.Entry<String, Member> entry : members.entrySet()) {
            configuration.addReferenceSite(entry.getKey(), entry.getValue());
        }
        JavaAtomicComponent sourceContext = new JavaAtomicComponent(sourceName, configuration, null);
        OutboundWire outboundWire = createReferenceWire(targetName, sourceReferenceClass, sourceHeadInterceptor);
        sourceContext.addOutboundWire(outboundWire);
        targetScope.register(targetContext);
        sourceScope.register(sourceContext);
        connect(outboundWire, inboundWire, targetContext, false);
        Map<String, AtomicComponent> contexts = new HashMap<String, AtomicComponent>();
        contexts.put(sourceName, sourceContext);
View Full Code Here

                                                                       ScopeContainer sourceScope,
                                                                       String targetName, Class<?> targetService,
                                                                       Class<?> targetClass,
                                                                       Map<String, Member> members,
                                                                       ScopeContainer targetScope) throws Exception {
        JavaAtomicComponent targetContext =
            createJavaComponent(targetName, targetScope, targetClass);
        String serviceName = targetService.getName().substring(targetService.getName().lastIndexOf('.') + 1);
        InboundWire inboundWire = createServiceWire(serviceName, targetService, null);
        targetContext.addInboundWire(inboundWire);

        PojoConfiguration configuration = new PojoConfiguration();
        configuration.setScopeContainer(sourceScope);
        configuration.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor()));
        configuration.addServiceInterface(sourceClass);
        configuration.setWireService(WIRE_SERVICE);
        for (Map.Entry<String, Member> entry : members.entrySet()) {
            configuration.addReferenceSite(entry.getKey(), entry.getValue());
        }
        JavaAtomicComponent sourceContext = new JavaAtomicComponent(sourceName, configuration, null);
        OutboundWire outboundWire = createReferenceWire(targetName, sourceReferenceClass, null);
        List<OutboundWire> factories = new ArrayList<OutboundWire>();
        factories.add(outboundWire);
        sourceContext.addOutboundWires(sourceReferenceClass, factories);
        targetScope.register(targetContext);
        sourceScope.register(sourceContext);
        connect(outboundWire, inboundWire, targetContext, false);
        Map<String, AtomicComponent> contexts = new HashMap<String, AtomicComponent>();
        contexts.put(sourceName, sourceContext);
View Full Code Here

        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.core.implementation.java.JavaAtomicComponent

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.