Package org.apache.tuscany.core.mock.wire

Examples of org.apache.tuscany.core.mock.wire.MockSyncInterceptor


    }

    private OutboundInvocationChain createChain(Method m, Operation operation) {
        MockStaticInvoker invoker = new MockStaticInvoker(m, new TestBeanImpl());
        OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation);
        chain.addInterceptor(new MockSyncInterceptor());
        chain.setTargetInvoker(invoker);
        chain.setTargetInterceptor(new InvokerInterceptor());
        chain.prepare();
        return chain;
    }
View Full Code Here


     * Tests basic wiring of a source to a target, including handlers and interceptors
     */
    public void testInvokeWithInterceptors() throws Exception {
        Operation operation = contract.getOperations().get("hello");
        OutboundInvocationChain source = new OutboundInvocationChainImpl(operation);
        MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
        source.addInterceptor(sourceInterceptor);

        InboundInvocationChain target = new InboundInvocationChainImpl(operation);
        MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
        target.addInterceptor(targetInterceptor);
        target.addInterceptor(new InvokerInterceptor());

        // connect the source to the target
        source.setTargetInterceptor(target.getHeadInterceptor());
        source.prepare();
        target.prepare();
        MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
        source.setTargetInvoker(invoker);

        Message msg = new MessageImpl();
        msg.setTargetInvoker(invoker);
        Message response = source.getHeadInterceptor().invoke(msg);
        assertTrue(response.isFault());
        assertTrue(response.getBody() instanceof IllegalArgumentException);
        assertEquals(1, sourceInterceptor.getCount());
        assertEquals(1, targetInterceptor.getCount());

    }
View Full Code Here

        JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
        ServiceContract<?> contract = registry.introspect(SimpleTarget.class);
        Operation<?> operation = contract.getOperations().get("echo");
        MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
        OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation);
        MockSyncInterceptor interceptor = new MockSyncInterceptor();
        chain.addInterceptor(interceptor);
        chain.setTargetInterceptor(new InvokerInterceptor());
        chain.setTargetInvoker(invoker);
        chain.prepare();
        //chains.put(echo, chain);
        OutboundWire wire = new OutboundWireImpl();
        wire.addInvocationChain(operation, chain);
        wire.setServiceContract(contract);
        JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(wire, new WorkContextImpl());
        assertEquals("foo", handler.invoke(null, echo, new String[]{"foo"}));
        assertEquals(1, interceptor.getCount());
    }
View Full Code Here

        assertEquals("foo", handler.invoke(hello, new Object[]{"foo"}));
    }

    private OutboundInvocationChain createChain(Operation operation) {
        OutboundInvocationChain source = new OutboundInvocationChainImpl(operation);
        MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
        source.addInterceptor(sourceInterceptor);

        InboundInvocationChain target = new InboundInvocationChainImpl(operation);
        MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
        target.addInterceptor(targetInterceptor);
        target.addInterceptor(new InvokerInterceptor());

        // connect the source to the target
        source.setTargetInterceptor(targetInterceptor);
View Full Code Here

    }

    private InboundInvocationChain createChain(Method m, Operation operation) {
        MockStaticInvoker invoker = new MockStaticInvoker(m, new InboundInvocationErrorTestCase.TestBeanImpl());
        InboundInvocationChain chain = new InboundInvocationChainImpl(operation);
        chain.addInterceptor(new MockSyncInterceptor());
        chain.setTargetInvoker(invoker);
        chain.addInterceptor(new InvokerInterceptor());
        chain.prepare();
        return chain;
    }
View Full Code Here

    /**
     * Verifies an invocation with a single source interceptor
     */
    public void testSourceInterceptor() throws Exception {
        ConnectorImpl connector = new ConnectorImpl();
        MockSyncInterceptor interceptor = new MockSyncInterceptor();
        List<Interceptor> interceptors = new ArrayList<Interceptor>();
        interceptors.add(interceptor);

        InboundInvocationChain inboundChain = setupInbound(interceptors);
        OutboundInvocationChain outboundChain = setupOutbound(null);
        Message msg = new MessageImpl();
        TargetInvoker invoker = createNiceMock(TargetInvoker.class);
        expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg);
        replay(invoker);
        assertEquals(0, interceptor.getCount());
        connector.connect(inboundChain, outboundChain);
        inboundChain.setTargetInvoker(invoker);
        inboundChain.prepare();
        msg.setTargetInvoker(inboundChain.getTargetInvoker());
        assertEquals(msg, inboundChain.getHeadInterceptor().invoke(msg));
        assertEquals(1, interceptor.getCount());
        verify(invoker);
    }
View Full Code Here

    /**
     * Verifies an invocation with a single target interceptor
     */
    public void testTargetInterceptor() throws Exception {
        ConnectorImpl connector = new ConnectorImpl();
        MockSyncInterceptor interceptor = new MockSyncInterceptor();
        List<Interceptor> interceptors = new ArrayList<Interceptor>();
        interceptors.add(interceptor);

        InboundInvocationChain inboundChain = setupInbound(interceptors);
        OutboundInvocationChain outboundChain = setupOutbound(null);
        Message msg = new MessageImpl();
        TargetInvoker invoker = createNiceMock(TargetInvoker.class);
        expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg);
        replay(invoker);
        assertEquals(0, interceptor.getCount());
        connector.connect(inboundChain, outboundChain);
        inboundChain.setTargetInvoker(invoker);
        inboundChain.prepare();
        msg.setTargetInvoker(inboundChain.getTargetInvoker());
        assertEquals(msg, inboundChain.getHeadInterceptor().invoke(msg));
        assertEquals(1, interceptor.getCount());
        verify(invoker);
    }
View Full Code Here

    /**
     * Verifies an invocation with a source and target interceptor
     */
    public void testSourceTargetInterceptor() throws Exception {
        ConnectorImpl connector = new ConnectorImpl();
        MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
        List<Interceptor> sourceInterceptors = new ArrayList<Interceptor>();
        sourceInterceptors.add(sourceInterceptor);
        MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
        List<Interceptor> targetInterceptors = new ArrayList<Interceptor>();
        targetInterceptors.add(targetInterceptor);

        OutboundInvocationChain outboundChain = setupOutbound(sourceInterceptors);
        InboundInvocationChain inboundChain = setupInbound(targetInterceptors);
        Message msg = new MessageImpl();
        TargetInvoker invoker = createNiceMock(TargetInvoker.class);
        expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg);
        replay(invoker);
        assertEquals(0, sourceInterceptor.getCount());
        assertEquals(0, targetInterceptor.getCount());
        connector.connect(inboundChain, outboundChain);
        inboundChain.setTargetInvoker(invoker);
        inboundChain.prepare();
        msg.setTargetInvoker(inboundChain.getTargetInvoker());
        assertEquals(msg, inboundChain.getHeadInterceptor().invoke(msg));
        assertEquals(1, sourceInterceptor.getCount());
        assertEquals(1, targetInterceptor.getCount());
        verify(invoker);
    }
View Full Code Here

    /**
     * Tests basic wiring of a source to a target, including handlers and interceptors
     */
    public void testInvokeWithInterceptors() throws Exception {
        OutboundInvocationChain source = new OutboundInvocationChainImpl(operation);
        MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
        source.addInterceptor(sourceInterceptor);

        InboundInvocationChain target = new InboundInvocationChainImpl(operation);
        MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
        target.addInterceptor(targetInterceptor);
        target.addInterceptor(new InvokerInterceptor());

        // connect the source to the target
        source.setTargetInterceptor(target.getHeadInterceptor());
        source.prepare();
        target.prepare();
        MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
        source.setTargetInvoker(invoker);

        Message msg = new MessageImpl();
        msg.setBody("foo");
        msg.setTargetInvoker(invoker);
        Message response = source.getHeadInterceptor().invoke(msg);
        assertEquals("foo", response.getBody());
        assertEquals(1, sourceInterceptor.getCount());
        assertEquals(1, targetInterceptor.getCount());
    }
View Full Code Here

    public void testInterceptorInvoke() throws Throwable {
        Map<Method, InboundInvocationChain> chains = new HashMap<Method, InboundInvocationChain>();
        MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
        InboundInvocationChain chain = new InboundInvocationChainImpl(operation);
        MockSyncInterceptor interceptor = new MockSyncInterceptor();
        chain.addInterceptor(interceptor);
        chain.addInterceptor(new InvokerInterceptor());
        chain.setTargetInvoker(invoker);
        chain.prepare();
        chains.put(echo, chain);
        WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
        EasyMock.replay(workContext);
        JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(chains, workContext);
        assertEquals("foo", handler.invoke(echo, new String[]{"foo"}));
        assertEquals(1, interceptor.getCount());
    }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.core.mock.wire.MockSyncInterceptor

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.