danw
danw

Reputation: 1648

Mule - separate test config files or vm endpoints for functional testing?

I've been building a Mule application for a while now and have just begun experimenting with writing JUnit tests for my flows. The flows I've built typically handle flat-file transformations and are structured similar to the below:

<flow>
   <inbound endpoint>

   ... DO SOMETHING WITH THE FILE ...

   <outbound endpoint>
</flow> 

My inbound/outbound endpoints are specific locations in the environments I'm deploying to and differ for each flow. The question I have is what's the best practice/approach in writing a test to inject a file into my flow and then check the output? Is it normal to create a test copy of the config file with dummy, vm endpoints and inject the file into that? Or is it more appropriate to go with a composite source like below and inject the file into the regular flow? Apologies for the potentially novice question, this is the first time I've worked with automated testing.

<flow>
   <composite source>
      <inbound endpoint>
      <vm endpoint>
   <composite source>

   ... DO SOMETHING WITH THE FILE ...

   <choice>
      <when "file originates from inbound endpoint...">
         <outbound endpoint>
      </when>
      <otherwise>
         <vm endpoint>
      </otherwise>
   </choice>
</flow>

Upvotes: 0

Views: 386

Answers (2)

Andres
Andres

Reputation: 10707

In your same situation, I use a properties configuration file for each environment. On that environment customized file, I define the address(including protocol) of each inbound/outbound element. For the local environment I use files and directories, and for all the other environments, I use the real protocols. That allows you to test locally without depending on the availability of any service.

Upvotes: 1

Mujahed
Mujahed

Reputation: 184

Mule has its own testing framework, basically instead of marking your class as @Test (Junit4) you just extend FunctionalTestCase (which indirectly extends JUnit framework) http://www.mulesoft.org/docs/site/current/apidocs/org/mule/tck/FunctionalTestCase.html

So, to start with I would first recommend reading this page: http://www.mulesoft.org/documentation/display/current/Functional+Testing

And suppose your inbound endpoint is http then you would use something like below, please note muleClient is available for you from parent class.

    muleClient = muleContext.getClient();

    Map<String, Object> props = new HashMap<String, Object>();
    props.put("http.method", "GET");

    MuleMessage result = muleClient.send(webaddress, "", props);

    assertNotNull(result);
    assertNotNull(result.getPayloadAsString());
    assertFalse(result.getPayload() instanceof NullPayload);

And more asserts as needed.

Upvotes: 1

Related Questions