Package org.apache.camel.component.mock

Examples of org.apache.camel.component.mock.MockEndpoint


    @Test
    public void testMalformedJson() throws Exception {
        String in = "{ \"a\": 123, \"b\": true, \"c\": true2 }";

        MockEndpoint mockXML = getMockEndpoint("mock:xml");
        mockXML.expectedMessageCount(0);

        MockEndpoint mockException = getMockEndpoint("mock:exception");
        mockException.expectedMessageCount(1);

        try {
            template.requestBody("direct:unmarshal", in);
            fail("Exception expected");
        } catch (CamelExecutionException e) {
            assertEquals("JSONException expected", JSONException.class, e.getCause().getClass());
        }

        List<Exchange> exchs = mockException.getExchanges();
        assertEquals("Only one exchange was expected in mock:exception", 1, exchs.size());

        Exception e = (Exception) exchs.get(0).getProperty(Exchange.EXCEPTION_CAUGHT);
        assertNotNull("Exception expected", e);
        assertEquals("JSONException expected", JSONException.class, e.getClass());
View Full Code Here


    @Test
    public void testSendJsonToXML() throws Exception {
        String in = "{ \"a\": 123, \"b\": true, \"c\": true2 }";

        MockEndpoint mockJSON = getMockEndpoint("mock:xml");
        mockJSON.expectedMessageCount(0);

        MockEndpoint mockException = getMockEndpoint("mock:exception");
        mockException.expectedMessageCount(1);

        try {
            template.requestBody("direct:unmarshal", in);
            fail("Exception expected");
        } catch (CamelExecutionException e) {
            assertEquals("JSONException expected", JSONException.class, e.getCause().getClass());
        }

        List<Exchange> exchs = mockException.getExchanges();
        assertEquals("Only one exchange was expected in mock:exception", 1, exchs.size());

        Exception e = (Exception) exchs.get(0).getProperty(Exchange.EXCEPTION_CAUGHT);
        assertNotNull("Exception expected", e);
        assertEquals("JSONException expected", JSONException.class, e.getClass());
View Full Code Here

        when(jobMock.getData()).thenReturn(payload);
        when(client.reserve(anyInt()))
                .thenReturn(jobMock)
                .thenReturn(null);

        MockEndpoint result = getMockEndpoint("mock:result");
        result.expectedMinimumMessageCount(1);
        result.expectedBodiesReceived(testMessage);
        result.expectedHeaderReceived(Headers.JOB_ID, jobId);
        result.message(0).header(Headers.JOB_ID).isEqualTo(jobId);
        result.assertIsSatisfied(2000);

        verify(client, atLeastOnce()).reserve(anyInt());
        verify(client).delete(jobId);
    }
View Full Code Here

        resetMocks();
        doSendMessages(5, 2, "direct:startFromJson", "org/apache/camel/dataformat/xmljson/testMessage3-large.json");
    }

    private void doSendMessages(int files, int poolSize, final String endpointURI, String resourceURI) throws Exception {
        MockEndpoint mockJSON = getMockEndpoint("mock:json");
        MockEndpoint mockXML = getMockEndpoint("mock:xml");
        mockJSON.expectedMessageCount(files);
        mockXML.expectedMessageCount(files);

        InputStream inStream = getClass().getClassLoader().getResourceAsStream(resourceURI);
        final String in = context.getTypeConverter().convertTo(String.class, inStream);

        ExecutorService executor = Executors.newFixedThreadPool(poolSize);
        for (int i = 0; i < files; i++) {
            executor.submit(new Callable<Object>() {
                public Object call() throws Exception {
                    template.sendBody(endpointURI, in);
                    return null;
                }
            });
        }

        // give much time as slow servers may take long time
        assertMockEndpointsSatisfied(60, TimeUnit.SECONDS);

        // test that all messages are equal
        Object jsonBody = mockJSON.getExchanges().get(0).getIn().getBody(String.class);
        Object xmlBody = mockXML.getExchanges().get(0).getIn().getBody(String.class);

        for (Exchange e : mockJSON.getExchanges()) {
            assertEquals("Bodies are expected to be equal (json mock endpoint)", jsonBody, e.getIn().getBody(String.class));
        }

        for (Exchange e : mockXML.getExchanges()) {
            assertEquals("Bodies are expected to be equal (xml mock endpoint)", xmlBody, e.getIn().getBody(String.class));
        }

        mockJSON.reset();
        mockXML.reset();

        executor.shutdownNow();
    }
View Full Code Here

        when(jobMock.getData()).thenReturn(payload);
        when(client.reserve(anyInt()))
                .thenReturn(jobMock)
                .thenReturn(null);

        MockEndpoint result = getMockEndpoint("mock:result");
        result.expectedMinimumMessageCount(1);
        result.assertIsNotSatisfied(1000);

        verify(client, atLeastOnce()).reserve(anyInt());
        verify(client).release(jobId, priority, delay);
    }
View Full Code Here

        when(jobMock.getData()).thenReturn(payload);
        when(client.reserve(anyInt()))
                .thenThrow(new BeanstalkException("test"))
                .thenReturn(jobMock);

        MockEndpoint result = getMockEndpoint("mock:result");
        result.expectedMessageCount(1);
        result.expectedBodiesReceived(testMessage);
        result.expectedHeaderReceived(Headers.JOB_ID, jobId);
        result.message(0).header(Headers.JOB_ID).isEqualTo(jobId);
        result.assertIsSatisfied(100);

        verify(client, atLeast(1)).reserve(anyInt());
        verify(client, times(1)).close();
    }
View Full Code Here

        when(jobMock.getData()).thenReturn(payload);
        when(client.reserve(anyInt()))
                .thenReturn(jobMock)
                .thenReturn(null);

        MockEndpoint result = getMockEndpoint("mock:result");
        result.expectedMessageCount(1);
        result.expectedBodiesReceived(testMessage);
        result.expectedHeaderReceived(Headers.JOB_ID, jobId);
        result.message(0).header(Headers.JOB_ID).isEqualTo(jobId);
        result.assertIsSatisfied(100);

        verify(client, atLeast(1)).reserve(0);
        verify(client, atLeast(1)).delete(jobId);
    }
View Full Code Here

    @Test
    public void testInOnlyTopicProducerProducer() throws Exception {
        MessageConsumer mc = createTopicConsumer(TEST_DESTINATION_NAME, null);
        assertNotNull(mc);
        final String expectedBody = "Hello World!";
        MockEndpoint mock = getMockEndpoint("mock:result");

        mock.expectedMessageCount(1);
        mock.expectedBodiesReceived(expectedBody);

        template.sendBody("direct:start", expectedBody);
        Message message = mc.receive(5000);
        assertNotNull(message);
        assertTrue(message instanceof TextMessage);
       
        TextMessage tm = (TextMessage) message;
        String text = tm.getText();
        assertNotNull(text);
       
        template.sendBody("direct:finish", text);
       
        mock.assertIsSatisfied();
        mc.close();

    }
View Full Code Here

    }

    @Test
    public void testExceptionSignatureForPlainTextWithWrongEncoding() throws Exception {
        String text = "plain test text";
        MockEndpoint mock = setupExceptionMock();
        Map<String, Object> headers = new TreeMap<String, Object>();
        headers.put(XmlSignatureConstants.HEADER_MESSAGE_IS_PLAIN_TEXT, Boolean.TRUE);
        headers.put(XmlSignatureConstants.HEADER_PLAIN_TEXT_ENCODING, "wrongEncoding");
        sendBody("direct:enveloping", text, headers);
        assertMockEndpointsSatisfied();
View Full Code Here

    public void testExceptionEnvelopedSignatureWithWrongParent() throws Exception {
        // payload root element renamed to a -> parent name in route definition
        // does not fit
        String payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a xmlns=\"http://test/test\"><test>Test Message</test></a>";

        MockEndpoint mock = setupExceptionMock();
        sendBody("direct:enveloped", payload);
        assertMockEndpointsSatisfied();
        checkThrownException(mock, XmlSignatureFormatException.class, null);
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.component.mock.MockEndpoint

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.