You may have noticed that our production code example makes extensive use of placeholders for certain parameters, such as driverName
, url
etc. in the example below:
<spring:bean id="jdbcDataSource" class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName" value="${db.driver}" />
<spring:property name="url" value="${db.url}" />
<spring:property name="user" value="${db.user}" />
<spring:property name="password" value="${db.password}" />
</spring:bean>
The reason for this is that properties allow us to create code that is more configurable. Compare the example above with:
<spring:bean id="jdbcDataSource" class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName" value="org.mule.fake.Driver" />
<spring:property name="url" value="192.168.0.3" />
<spring:property name="user" value="myUser" />
<spring:property name="password" value="123456" />
</spring:bean>
The second example code is untestable, even without MUnit. If we need to test this code before going to production, we always hit the production DB server with our real credentials, which entails risk.
On the other hand, the first example code allows us to define two different property files:
This is use in combination with the Mule property placeholder, shown below with $site
:
<global-property value="mule.${env}.property"/>
In the example above, the use of $site
allows us to leverage execution environments. So for example we can define two separate properties files, mule.test.properties
and mule.prod.properties
, containing the same properties with values according to the environment we wish to use.
|
To run your test from Maven and issue the env parameter from the command line, you can run: mvn -DargLine="-Dmule.env=test" clean test .
|