Package org.apache.camel.component.mock

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


* @version $Revision: 668288 $
*/
public class UnmarshalThenMarshalTest extends ContextTestSupport {
    public void testSendXmlAndUnmarshal() throws Exception {

        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
        resultEndpoint.expectedMessageCount(1);

        PurchaseOrder expectedBody = new PurchaseOrder();
        expectedBody.setAmount(20.0);
        expectedBody.setName("Wine");
        expectedBody.setPrice(5.0);

        template.sendBody("direct:start", expectedBody);

        resultEndpoint.assertIsSatisfied();

        List<Exchange> list = resultEndpoint.getReceivedExchanges();
        Exchange exchange = list.get(0);
        Object actualBody = exchange.getIn().getBody();

        log.debug("Received: " + actualBody);
        assertEquals("Received body", expectedBody, actualBody);
View Full Code Here


    private static final String MESSAGE_INFO = "messageInfo";
    private static final String RESULT_QUEUE = "mock:result";
    private static final String ERROR_QUEUE = "mock:error";

    public void testHandledException() throws Exception {
        MockEndpoint result = getMockEndpoint(RESULT_QUEUE);
        result.expectedMessageCount(0);
        MockEndpoint mock = getMockEndpoint(ERROR_QUEUE);
        mock.expectedMessageCount(1);
        mock.expectedHeaderReceived(MESSAGE_INFO, "Handled exchange with NullPointerException");

        template.sendBody("direct:a", "Hello NPE");
        MockEndpoint.assertIsSatisfied(result, mock);
    }
View Full Code Here

        template.sendBody("direct:a", "Hello NPE");
        MockEndpoint.assertIsSatisfied(result, mock);
    }

    public void testHandledExceptionWithExpression() throws Exception {
        MockEndpoint result = getMockEndpoint(RESULT_QUEUE);
        result.expectedMessageCount(0);
        MockEndpoint mock = getMockEndpoint(ERROR_QUEUE);
        mock.expectedMessageCount(1);
        mock.expectedHeaderReceived(MESSAGE_INFO, "Handled exchange with IOException");

        template.sendBodyAndHeader("direct:a", "Hello IOE", "foo", "bar");
        MockEndpoint.assertIsSatisfied(result, mock);
    }
View Full Code Here

        template.sendBodyAndHeader("direct:a", "Hello IOE", "foo", "bar");
        MockEndpoint.assertIsSatisfied(result, mock);
    }

    public void testUnhandledException() throws Exception {
        MockEndpoint result = getMockEndpoint(RESULT_QUEUE);
        result.expectedMessageCount(0);
        MockEndpoint mock = getMockEndpoint(ERROR_QUEUE);
        mock.expectedMessageCount(1);
        mock.expectedHeaderReceived(MESSAGE_INFO, "Handled exchange with IOException");
       
        try {
            template.sendBodyAndHeader("direct:a", "Hello IOE", "foo", "something that does not match");
            fail("Should have thrown a IOException");
        } catch (RuntimeCamelException e) {
View Full Code Here

        assertApplicationContextStarts(appContextLocation, createProperties("useCase", "bar/input1"));
        assertExpectedCount(1);
    }

    protected void assertExpectedCount(int expectedCount) throws InterruptedException {
        MockEndpoint endpoint = getCamelContext().getEndpoint("mock:results", MockEndpoint.class);
        endpoint.expectedMessageCount(expectedCount);
        endpoint.assertIsSatisfied();
    }
View Full Code Here

public class TryProcessorHandleTest extends ContextTestSupport {

    private boolean handled;

    public void test() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:result");
        sendBody("direct:start", "<test>Hello World!</test>");
        assertTrue("Should have been handled", handled);
        mock.expectedMessageCount(0);
        mock.assertIsSatisfied();
    }
View Full Code Here

    protected ActiveMQQueue replyQueue = new ActiveMQQueue("test.reply.queue");
    protected String correlationID = "ABC-123";
    protected String messageType = getClass().getName();

    public void testForwardingAMessageAcrossJMSKeepingCustomJMSHeaders() throws Exception {
        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);

        resultEndpoint.expectedBodiesReceived(expectedBody);
        AssertionClause firstMessageExpectations = resultEndpoint.message(0);
        firstMessageExpectations.header("cheese").isEqualTo(123);
        firstMessageExpectations.header("JMSReplyTo").isEqualTo(replyQueue);
        firstMessageExpectations.header("JMSCorrelationID").isEqualTo(correlationID);
        firstMessageExpectations.header("JMSType").isEqualTo(messageType);

        template.sendBodyAndHeader("activemq:test.a", expectedBody, "cheese", 123);

        resultEndpoint.assertIsSatisfied();

        List<Exchange> list = resultEndpoint.getReceivedExchanges();
        Exchange exchange = list.get(0);
        Object replyTo = exchange.getIn().getHeader("JMSReplyTo");
        LOG.info("Reply to is: " + replyTo);
        Destination destination = assertIsInstanceOf(Destination.class, replyTo);
        assertEquals("ReplyTo", replyQueue.toString(), destination.toString());
View Full Code Here

        Integer started = (Integer) mbeanServer.getAttribute(on, "StartedRoutes");
        assertEquals(2, started.intValue());

        // invoke operations
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedBodiesReceived("Hello World");
        mbeanServer.invoke(on, "sendBody", new Object[]{"direct:start", "Hello World"}, new String[]{"java.lang.String", "java.lang.Object"});
        assertMockEndpointsSatisfied();

        resetMocks();
        mock.expectedBodiesReceived("Hello World");
        mbeanServer.invoke(on, "sendStringBody", new Object[]{"direct:start", "Hello World"}, new String[]{"java.lang.String", "java.lang.String"});
        assertMockEndpointsSatisfied();

        Object reply = mbeanServer.invoke(on, "requestBody", new Object[]{"direct:foo", "Hello World"}, new String[]{"java.lang.String", "java.lang.Object"});
        assertEquals("Bye World", reply);

        reply = mbeanServer.invoke(on, "requestStringBody", new Object[]{"direct:foo", "Hello World"}, new String[]{"java.lang.String", "java.lang.String"});
        assertEquals("Bye World", reply);

        resetMocks();
        mock = getMockEndpoint("mock:result");
        mock.expectedBodiesReceived("Hello World");
        mock.expectedHeaderReceived("foo", 123);
        Map<String, Object> headers = new HashMap<String, Object>();
        headers.put("foo", 123);
        mbeanServer.invoke(on, "sendBodyAndHeaders", new Object[]{"direct:start", "Hello World", headers}, new String[]{"java.lang.String", "java.lang.Object", "java.util.Map"});
        assertMockEndpointsSatisfied();

        resetMocks();
        mock = getMockEndpoint("mock:result");
        mock.expectedBodiesReceived("Hello World");
        mock.expectedHeaderReceived("foo", 123);
        reply = mbeanServer.invoke(on, "requestBodyAndHeaders", new Object[]{"direct:start", "Hello World", headers}, new String[]{"java.lang.String", "java.lang.Object", "java.util.Map"});
        assertEquals("Hello World", reply);
        assertMockEndpointsSatisfied();

        // test can send
View Full Code Here

public class DelegateEndpointQuartzTest extends CamelTestSupport {
   
    @Test
    public void testQuartzCronRoute() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMinimumMessageCount(3);
       
        assertMockEndpointsSatisfied();

        JobDetail job = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
        assertNotNull(job);

        assertEquals("cron", job.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_TYPE));
        assertEquals("0/2 * * * * ?", job.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION));
    }
View Full Code Here

    @Test
    public void testActionCalled() throws Exception {
        Mailbox mailbox = Mailbox.get("bill@localhost");
        assertEquals(1, mailbox.size());

        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedBodiesReceivedInAnyOrder("TestText");

        assertMockEndpointsSatisfied();
        waitForActionCalled();
    }
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.