Reputation: 51
I have a flow I wish to test. The flow has an HTTP inbound connector, and the flow itself acts as a RESTful service.
The flow expects a few URL parameters to be set, and accesses these throughout using the standard notation: #[message.inboundProperties.'http.query.params'.test]
.
I am wanting to test this flow using MUnit. When I create a default MUnit test against the flow, MUnit creates a flow-ref to call my original flow. Running this test immediately fails however, because the flow expects to be called by HTTP, and expects the URL parameters set.
This is where I'm at now. I wish to set these variables before calling the flow-ref, so that my flow can process normally.
I have tried a few things:
munit:set
component, which allows one to set various propertiesMessagePropertyMapContext
and assigning it to the http.query.params
variableflow-ref
component with an HTTP
component and calling the flow with an actual HTTP messageThese all do not seem to work properly.
The variable setting seems to always fail, and results in NullPointerException
when trying to access the variables.
Calling the flow using an HTTP
component doesn't work because Mule randomly assigns a port for testing, and I can't seem to get access to this port at runtime. Thus I have no way to call the endpoint.
I have looked elsewhere for similar questions here and here, but they do not seem to help me.
So my basic question is: how can I set URL parameters that can be accessed by a flow, when being tested from an MUnit test. Is there instead a better way to achieve what I'm trying to achieve here?
Thank you!
Upvotes: 1
Views: 7227
Reputation: 125
To add to the answer above, this corresponds to "Set Message" component in Mule 3 pallette.
Upvotes: 0
Reputation: 31
@TroyS you can try the following code. It worked for me.
<munit:set payload="#['']" doc:name="Set Message url_key:payload_1">
<munit:inbound-properties>
<munit:inbound-property key="http.query.params" value="#[['url_key':'payload_1']]"/>
</munit:inbound-properties>
</munit:set>
Upvotes: 3
Reputation: 51
Well it turns out the Mule documentation has the answer if you look hard enough ;) The answer is right here.
You just need to add the munit:set
component at the start of your MUnit test flow (search for "Set Message" in your Mule Palette for this component):
<munit:set payload="#['']" doc:name="Set HTTP query params">
<munit:inbound-properties>
<munit:inbound-property key="http.query.params" value="#[['transactionId': 'x873h3dj']]"/>
</munit:inbound-properties>
</munit:set>
This creates a parameter pair transactionId: x873h3dj
, which can then be accessed in your code as needed.
You can add more parameters by extending the following structure according to normal MEL syntax:
#[['key1':'val1', 'key2': 'val2', 'key3': 'val3']]
Upvotes: 0