Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Property Placeholder's Issue in MUnit [Snippet]

DZone's Guide to

Property Placeholder's Issue in MUnit [Snippet]

Let's look at this brief article that includes a code screenshot of a problem someone faced when running an MUnit test.

· Integration Zone ·
Free Resource

How to Transform Your Business in the Digital Age: Learn how organizations are re-architecting their integration strategy with data-driven app integration for true digital transformation.

In this brief article, I will describe the problem and solution that I have lately faced. As it is a good practice not to hard-code connection data I have extracted them to an external file called connection.properties. I did not expect to receive an error something like $[smtp.host]. I did not know what it can means. Below I have described what it is.

Problem

I have setup SMTP connector, like in the screenshot below. When I run my MUnit test for this particular flow, I received an error that my application can't be built.

Excerpt from flow with SMTP ConnectorThe problem I got in the console was as follows:

Caused by: java.net.URISyntaxException: Illegal character in hostname at index 7: smtp://$[Illegal character in hostname exception

At first, I didn't know why $[smtp.host] is in square brackets and not in curly brackets. I thought that I have made a mistake. That is why I looked into my source code in XML view. There, I found that smpt.host is in curly brackets as it should be. So, what is going on?

Solution

It turned out that I did not get a root cause exception message. The root cause was missing smtp.host property. I needed to create a separate property file in src/test/resources and then connect it into my MUnit test suit using Property Placeholder (Configuration). After that, the problem was gone.

Make your mark on the industry’s leading annual report. Fill out the State of API Integration 2019 Survey and receive $25 to the Cloud Elements store.

Topics:
integration ,mulesoft ,munit ,smtp

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}