Package org.switchyard.test

Examples of org.switchyard.test.MockHandler


    private QName _serviceName = new QName("urn:test", "Service");
    private ServiceInterface _metadata = new InOnlyService(OPERATION_NAME);

    @Test
    public void messageComposerComposeTest() {
        MockHandler mock = new MockHandler().forwardInToOut();
        _serviceDomain.registerService(_serviceName, _metadata, mock);
        _serviceDomain.registerServiceReference(_serviceName, _metadata);
        InboundHandler<?> handler = createInboundHandler(_serviceName, "direct:input", "input",
                new V1MessageComposerModel(SwitchYardNamespace.DEFAULT.uri()).setClazz(Composer.class.getName()));
        handler.start();

        sendBody("direct:input", PAYLOAD);
        mock.waitForOKMessage();
        List<Exchange> exchanges = new ArrayList<Exchange>();
        mock.getMessages().drainTo(exchanges);
        assertEquals(1, exchanges.size());
        assertEquals(Composer.COMPOSE_PREFIX + PAYLOAD, exchanges.get(0).getMessage().getContent());

        handler.stop();
    }
View Full Code Here


        handler.stop();
    }

    @Test
    public void contextMapperMapToTest() {
        MockHandler mock = new MockHandler().forwardInToOut();
        _serviceDomain.registerService(_serviceName, _metadata, mock);
        _serviceDomain.registerServiceReference(_serviceName, _metadata);
        InboundHandler<?> handler = createInboundHandler(_serviceName, "direct:input", "direct",
                new V1ContextMapperModel(SwitchYardNamespace.DEFAULT.uri()).setClazz(Mapper.class.getName()));
        handler.start();

        sendBody("direct:input", PAYLOAD);
        mock.waitForOKMessage();
        List<Exchange> exchanges = new ArrayList<Exchange>();
        mock.getMessages().drainTo(exchanges);
        assertEquals(1, exchanges.size());
        Exchange exchange = exchanges.get(0);
        Property property = exchange.getContext().getProperty(Mapper.PROPERTY);
        assertNotNull(property);
        assertEquals(Mapper.VALUE, property.getValue());
View Full Code Here

        handler.stop();
    }

    @Test
    public void operationSelectorTest() {
        MockHandler mock = new MockHandler().forwardInToOut();
        _serviceDomain.registerService(_serviceName, _metadata, mock);
        _serviceDomain.registerServiceReference(_serviceName, _metadata);
        InboundHandler<?> handler = createInboundHandler(_serviceName, "direct:input", "input",
                new V1StaticOperationSelectorModel(SwitchYardNamespace.DEFAULT.uri()).setOperationName(OPERATION_NAME));
        handler.start();

        sendBody("direct:input", PAYLOAD);
        mock.waitForOKMessage();
        List<Exchange> exchanges = new ArrayList<Exchange>();
        mock.getMessages().drainTo(exchanges);
        assertEquals(1, exchanges.size());
        assertEquals(OPERATION_NAME, exchanges.get(0).getContract().getProviderOperation().getName());

        handler.stop();
    }
View Full Code Here

        handler.stop();
    }

    @Test
    public void wrongOperationSelectorTest() {
        MockHandler mock = new MockHandler().forwardInToOut();
        JavaService metadata = JavaService.fromClass(TestService.class);
        _serviceDomain.registerService(_serviceName, metadata, mock);
        _serviceDomain.registerServiceReference(_serviceName, metadata);
        InboundHandler<?> handler = createInboundHandler(_serviceName, "direct:input", "input",
                new V1StaticOperationSelectorModel(SwitchYardNamespace.DEFAULT.uri()).setOperationName("missing"));
        handler.start();

        sendBody("direct:input", PAYLOAD);
        assertTrue(mock.getMessages().isEmpty());
        handler.stop();
    }
View Full Code Here

    @ServiceOperation("InvokerService")
    private Invoker invokerService;

    @Test
    public void invokeReferenceA() {
        MockHandler handlerA = testKit.registerInOnlyService(REFERENCE_A);
        MockHandler handlerB = testKit.registerInOnlyService(REFERENCE_B);
        invokerService.operation("testA").sendInOut("testA");
        Assert.assertEquals(1, handlerA.getMessages().size());
        Assert.assertEquals(0, handlerB.getMessages().size());
    }
View Full Code Here

        Assert.assertEquals(0, handlerB.getMessages().size());
    }
   
    @Test
    public void invokeReferenceB() {
        MockHandler handlerA = testKit.registerInOnlyService(REFERENCE_A);
        MockHandler handlerB = testKit.registerInOnlyService(REFERENCE_B);
        invokerService.operation("testB").sendInOut("testB");
        Assert.assertEquals(0, handlerA.getMessages().size());
        Assert.assertEquals(1, handlerB.getMessages().size());
    }
View Full Code Here

                       + "</test:sayHello>";

        String faultStr = "SOAPFaultInfo [_actor=null, _codeAsQName={http://schemas.xmlsoap.org/soap/envelope/}Server.AppError, "
                            + "_reasonTexts={}, _role=null, _string=Invalid name, _stringLocale=null, _subcodes=[], _detail=[detail: null]]";

        MockHandler handler = new MockHandler();
        Exchange ex = _consumerService11.operation("sayHello").createExchange(handler);

        Message requestMsg = ex.createMessage().setContent(input);
        ex.send(requestMsg);
        handler.waitForFaultMessage();
        Exchange exchange = handler.getFaults().iterator().next();
        Property faultInfoProperty = exchange.getContext().getProperty(SOAPComposition.SOAP_FAULT_INFO);
        Assert.assertNotNull(faultInfoProperty);
        Assert.assertEquals(faultStr, faultInfoProperty.getValue().toString());
    }
View Full Code Here

            .sendInOut(TEST_IN_CONTENT);
    }
   
    @Test
    public void sendReply() throws Exception {
        MockHandler handler = new MockHandler();
        handler.setWaitTimeout(3000);
        Exchange ex = sendReply.createExchange(handler);
        ex.send(ex.createMessage().setContent(TEST_IN_CONTENT));
        Assert.assertEquals(1, handler.waitForOKMessage().getMessages().size());
        Assert.assertEquals(TEST_OUT_CONTENT,
                handler.getMessages().poll().getMessage().getContent());
    }
View Full Code Here

                handler.getMessages().poll().getMessage().getContent());
    }
   
    @Test
    public void attachments() throws Exception {
        MockHandler handler = new MockHandler();
        handler.setWaitTimeout(3000);
        Exchange ex = attachments.createExchange(handler);
        ex.send(ex.createMessage()
                .setContent(TEST_IN_CONTENT)
                .addAttachment(TEST_IN_ATTACHMENT, new DummyDataSource(TEST_IN_ATTACHMENT)));
        Assert.assertEquals(1, handler.waitForOKMessage().getMessages().size());
        Message reply = handler.getMessages().poll().getMessage();
        DataSource attachOut = reply.getAttachment(TEST_OUT_ATTACHMENT);
        Assert.assertNotNull(attachOut);
        Assert.assertEquals(TEST_OUT_ATTACHMENT, attachOut.getName());
    }
View Full Code Here

    private SwitchYardTestKit testKit;
    private HTTPMixIn httpMixIn;

    @Test
    public void testWrapUnwrap() throws Exception {
        MockHandler provider = new MockHandler().forwardInToOut();
        testKit.registerInOutService("Payments", provider, new InOutService("submit"));
        String reply = httpMixIn.postResource("http://localhost:18001/Payments", "wrappedRequest.xml");
        String receivedPayload = provider.getMessages().poll(300, TimeUnit.MILLISECONDS)
                .getMessage().getContent(String.class);
       
        // verify request is unwrapped
        XMLUnit.setIgnoreWhitespace(true);
        Diff requestDiff = XMLUnit.compareXML(testKit.readResourceString(UNWRAPPED_PAYLOAD), receivedPayload);
View Full Code Here

TOP

Related Classes of org.switchyard.test.MockHandler

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.