0
votes

I have a basic Mule ESB application with a basic flow like: "Http Inbound endpoint (request-response mode) -> logger -> HTTP Outbound Endpoint (request-response mode) -> Java component"

Query: How do I write a junit test case to test the above flow. As can be seen, I have a HTTP Outbound Endpoint (request-response mode) which refers to some big application which does lots of processing and then returns a response. Do I mock this HTTP outbound endpoint? I don't want to test only the HTTP Outbound Endpoint (request-response mode) individually. I want to junit test the flow as a whole.

Thanks in Advance. Jai Shammi Raj Kulkarni

3

3 Answers

0
votes
public void httpEndpoint() throws IOException
    {
        DefaultHttpClient client = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet("http://localhost:8085/api/search");
        HttpResponse response = client.execute(httpGet);
        assertNotNull(response);
    }
5
votes

You can create a test flow with an HTTP Inbound Endpoint and a test:component for setting the payload, and add the flow file to your test configuration files. However, I prefer to use the Confluex Mock HTTP API to test applications with HTTP Outbound Endpoints. It sets up a mock HTTP server at localhost, where you can respond to different calls with specified data and response codes, so you can run all kinds of failure scenarios as well. Set up the mock server in a @Before annotated method in your FunctionalTestCase class and stop it in the @After method, so it will be available for the test methods.

Mule documentation gives some basic information on how to create functional test cases: http://www.mulesoft.org/documentation/display/current/Functional+Testing