0

I am trying to create a MUnit test for a flow with a HTTP Listener as message source.

When I'm running the test, I get:

org.mule.munit.runner.model.TestExecutionException: Error [HTTP:SERVICE_UNAVAILABLE] while running test 'AccServiceIntegrationTest-AccServiceFlowTest':HTTP GET on resource 'http://localhost:8303/AccService' failed: service unavailable (503).

My HTTP Listener configuration looks like this:

<http:listener-config name="ApiHttpListenerConfig" doc:name="HTTP Listener config" doc:id="b72fd4c2-e250-4591-b780-de4a40f3a805" >
    <http:listener-connection host="localhost" port="8303" />
</http:listener-config>

and my listener itself:

<http:listener doc:name="Listener" doc:id="91f3dc92-d221-4961-b33e-61e65040f481" config-ref="ApiHttpListenerConfig" path="/AccService"/>

The HTTP Request configuration in my test looks like this:

<http:request-config name="HTTPTestRequestConfiguration" doc:name="HTTP Request configuration" doc:id="d7ccc980-3103-4367-8ecc-e0c031f093e9">
    <http:request-connection host="localhost" port="8303" />
</http:request-config>

And the request itself:

<http:request method="GET" doc:name="Request" doc:id="912fe4a9-5e6b-4909-9dc7-a6f44642cf40" config-ref="HTTPTestRequestConfiguration" path="/AccService"/>

now the flow of the test looks like this:

<munit:test name="AccServiceIntegrationTest-AccServiceFlowTest" doc:id="5e2d057f-38b9-494f-a889-25579960a96f" description="Test">
    <munit:execution >
        <file:read doc:name="Read acc-service-request.xml" doc:id="66ad1782-cefc-42dd-8a9d-52f6b6e191f4" config-ref="XMLFileTest" path="resources/acc-service-request.xml"/>
        <http:request method="GET" doc:name="Request" doc:id="912fe4a9-5e6b-4909-9dc7-a6f44642cf40" config-ref="HTTPTestRequestConfiguration" path="/AccService"/>
        <flow-ref doc:name="Flow-ref to FleetServiceFlow" doc:id="b8536d75-c09f-4c1a-894e-f7d25392d6b7" name="AccServiceFlow"/>
    </munit:execution>
</munit:test>

All I get is a Service unavailable (503) response.

What am I doing wrong here? When I'm testing the configuration for the listener - everything seems to be alright...

hc0re
  • 1,806
  • 2
  • 26
  • 61
  • Is the application using API auto discovery? – aled Mar 04 '21 at 14:06
  • Also please add a snippet of the MUnit dependencies from the application's pom.xml. – aled Mar 04 '21 at 14:24
  • It seems like you are doing a HTTP request inside Munit and as such you need to enable the flow where the listener is. Munit by default does not enable flows where your listeners are configured thus you will encounter service unavailable error. – oim Mar 04 '21 at 20:09

2 Answers2

1

In your munit test , Please include the listener flow under the "Expected Flow sources".

        <munit:enable-flow-sources >
            <munit:enable-flow-source value="get:\folder:test-api-config" />
        </munit:enable-flow-sources>
        <munit:behavior> ```
NewBie
  • 23
  • 1
  • 5
0

Ensure that the MUnit dependencies in the pom have the test scope (ie <scope>test</scope>). Failing to do so is known to cause this issue.

Example:

<dependency>
    <groupId>com.mulesoft.munit</groupId>
    <artifactId>munit-runner</artifactId>
    <version>${munit.version}</version>
    <classifier>mule-plugin</classifier>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>com.mulesoft.munit</groupId>
    <artifactId>munit-tools</artifactId>
    <version>${munit.version}</version>
    <classifier>mule-plugin</classifier>
    <scope>test</scope>
</dependency>

Source: https://help.mulesoft.com/s/article/HTTP-Listener-replying-Server-not-available-to-handle-this-request-either-not-initialized-yet-or-it-has-been-disposed-in-Mule-4

aled
  • 21,330
  • 3
  • 27
  • 34