Package org.apache.camel.component.mock

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


    }


    @Test
    public void multipleIssuesTest() throws Exception {
        MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");

        MockJiraRestClient client = (MockJiraRestClient) factory.getClient();
        MockSearchRestClient restClient = (MockSearchRestClient) client.getSearchClient();
        BasicIssue issue1 = restClient.addIssue();
        BasicIssue issue2 = restClient.addIssue();
        BasicIssue issue3 = restClient.addIssue();

        mockResultEndpoint.expectedBodiesReceived(issue3, issue2, issue1);

        mockResultEndpoint.assertIsSatisfied();
    }
View Full Code Here


        };
    }
   
    @Test
    public void emptyAtStartupTest() throws Exception {
        MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");

        mockResultEndpoint.expectedMessageCount(0);
       
        mockResultEndpoint.assertIsSatisfied();
    }
View Full Code Here

    }


    @Test
    public void singleIssueTest() throws Exception {
        MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");

        MockJiraRestClient jiraRestClient = (MockJiraRestClient) factory.getClient();
        MockSearchRestClient searchRestClient = (MockSearchRestClient) jiraRestClient.getSearchClient();
        BasicIssue issue1 = searchRestClient.addIssue();
        String commentText = "Comment added at " + new Date();
        Comment comment1 = searchRestClient.addCommentToIssue(issue1, commentText);

        mockResultEndpoint.expectedBodiesReceived(comment1);
       

        mockResultEndpoint.assertIsSatisfied();
    }
View Full Code Here

    }


    @Test
    public void multiIssueTest() throws Exception {
        MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");

        MockJiraRestClient jiraRestClient = (MockJiraRestClient) factory.getClient();
        MockSearchRestClient searchRestClient = (MockSearchRestClient) jiraRestClient.getSearchClient();
        BasicIssue issue1 = searchRestClient.addIssue();
        Comment comment1 = searchRestClient.addCommentToIssue(issue1, "Comment added at " + new Date());
        BasicIssue issue2 = searchRestClient.addIssue();
        Comment comment2 = searchRestClient.addCommentToIssue(issue2, "Comment added at " + new Date());

        mockResultEndpoint.expectedBodiesReceivedInAnyOrder(comment1, comment2);

        mockResultEndpoint.assertIsSatisfied();
    }
View Full Code Here

                // Mock and skip result endpoint
                mockEndpointsAndSkip("log:*");
            }
        });

        MockEndpoint resultEndpoint = context.getEndpoint("mock:log:foo", MockEndpoint.class);
        // resultEndpoint.expectedMessageCount(1); // If you want to just check the number of messages
        resultEndpoint.expectedBodiesReceived("hello"); // If you want to check the contents

        // You can also take the expected result from an external file
        // String result = IOUtils.toString(context.getClassResolver().loadResourceAsStream("testdata/out/result.txt"));
        // resultEndpoint.expectedBodiesReceived(result.replaceAll("\r?\n", "\n"));

        // Start the integration
        integration.run();

        // Send the test message
        context.createProducerTemplate().sendBody("direct:start", "hello");

        // You can also send an external file
        // context.createProducerTemplate.sendBody("direct:start", context.getClassResolver().loadResourceAsStream("testdata/in/input.xml"));

        // REST/HTTP services can be easily tested with RestAssured:
        // get(context.resolvePropertyPlaceholders("{{restUrl}}")).then().statusCode(204).body(isEmptyOrNullString());
        // given().param("status").get(context.resolvePropertyPlaceholders("{{restUrl}}")).then().statusCode(200).body(equalTo("active"));
        // given().auth().basic("testuser", "testpass").body("hello").when().post(context.resolvePropertyPlaceholders("{{restUrl}}")).then().statusCode(200).body(equalTo("response"));

        resultEndpoint.assertIsSatisfied();
  }
View Full Code Here

            }
        });
    }
     
    protected void testEncryption(String fragment, CamelContext context) throws Exception {
        MockEndpoint resultEndpoint = context.getEndpoint("mock:encrypted", MockEndpoint.class);
        resultEndpoint.setExpectedMessageCount(1);
        context.start();
        sendText(fragment, context);
        resultEndpoint.assertIsSatisfied(100);
        Exchange exchange = resultEndpoint.getExchanges().get(0);
        Document inDoc = getDocumentForInMessage(exchange);
        if (log.isDebugEnabled()) {
            logMessage(exchange, inDoc);
        }
        Assert.assertTrue("The XML message has no encrypted data.", hasEncryptedData(inDoc));
View Full Code Here

        testEncryption(XML_FRAGMENT, context);
    }
   
   
    protected void testDecryption(String fragment, CamelContext context) throws Exception {
        MockEndpoint resultEndpoint = context.getEndpoint("mock:decrypted", MockEndpoint.class);
        resultEndpoint.setExpectedMessageCount(1);
        // verify that the message was encrypted before checking that it is decrypted
        testEncryption(fragment, context);

        resultEndpoint.assertIsSatisfied(100);
        Exchange exchange = resultEndpoint.getExchanges().get(0);
        Document inDoc = getDocumentForInMessage(exchange);
        if (log.isDebugEnabled()) {
            logMessage(exchange, inDoc);
        }
        Assert.assertFalse("The XML message has encrypted data.", hasEncryptedData(inDoc));
View Full Code Here

    private MockEndpoint setupMock() {
        return setupMock(payload);
    }

    private MockEndpoint setupMock(String payload) {
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedBodiesReceived(payload);
        return mock;
    }
View Full Code Here

        CamelContext context = new DefaultCamelContext();
        try {
            context.addRoutes(builder);
            context.start();

            MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
            mock.setExpectedMessageCount(1);

            ProducerTemplate template = context.createProducerTemplate();
            if (e != null) {
                template.send("direct:in", e);
            } else {
                template.sendBodyAndHeaders("direct:in", payload, headers);
            }
            assertMockEndpointsSatisfied();
            return mock.getReceivedExchanges().get(0);
        } finally {
            context.stop();
        }
    }
View Full Code Here

    // Tests

    @Test
    public void shouldResolveBothCamelAndSpringPlaceholders() throws InterruptedException {
        // Given
        MockEndpoint mockEndpoint = camelContext.getEndpoint("mock:test", MockEndpoint.class);
        mockEndpoint.expectedMessageCount(1);

        // When
        producerTemplate.sendBody(from, "msg");

        // Then
        mockEndpoint.assertIsSatisfied();
    }
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.