user439407
user439407

Reputation: 1756

Getting http response code in MUnit

I have a flow that I am trying to test a basic HTTP flow in Mule using Munit, the flow looks something like this:

<flow name="health-checkFlow">
    <http:listener config-ref="HTTP_Listener_Configuration"
        path="/" allowedMethods="GET" doc:name="HTTP">
        <http:response-builder  />
    </http:listener>
....
</flow>

With Munit I am calling the flow using:

MuleEvent resultEvent = runFlow("health-checkFlow", testEvent(""));

The resultEvent object has the proper payload, but when I try to get the http response code using:

    assertEquals("HTTP status code should be 200","200",resultEvent.getMessage().getOutboundProperty("http.status"));

the status is always null. How do I get the http response code from the message in Munit?

Upvotes: 0

Views: 1141

Answers (1)

Ryan Carter
Ryan Carter

Reputation: 11606

By calling runFlow you are actually bypassing the http:listener and just invoking the flow directly. By default inbound endpoints and connectors will be disabled. To test the http portion override the following in your test case:

@Override
protected boolean haveToMockMuleConnectors()
{
return false;
}

@Override
protected boolean haveToDisableInboundEndpoints()
{
return false;
}

Then I would use a standard Java HTTP client or maybe the Mule Client to test the HTTP inbound endpoint and check the status code.

Upvotes: 1

Related Questions