Search code examples
javamavenunitils

Maven- Pom.xml properties not recognized in unitils configuration File


I included my database configuration in pom.xml file in order to use them for my project testing ,I'm using unitils for database integration My pom.xml properties are

    <test.database.rules-satellite.driver>com.mysql.jdbc.Driver</test.database.rulessatellite.driver>
    <test.database.rules-satellite.server>localhost</test.database.rules-satellite.server>
    <test.database.rules-satellite.schema>R133_isp_copie_pdx</test.database.rules-satellite.schema>
    <test.database.rules-satellite.url>jdbc:mysql://${test.database.rules-satellite.server}/${test.database.rules-satellite.schema}</test.database.rules-satellite.url>

    <test.database.rules-satellite.username>junit</test.database.rules-satellite.username>
    <test.database.rules-satellite.password>junit</test.database.rules-satellite.password>

and my unitils configuration is as below :

# Properties for the`enter code here` PropertiesDataSourceFactory
database.driverClassName=com.mysql.jdbc.Driver
database.url=jdbc:mysql://${test.database.rules-satellite.server}/${test.database.rules-satellite.schema}

# This property specifies the underlying DBMS implementation. Supported values are 'oracle', 'db2', 'mysql' and 'hsqldb'.
# The value of this property defines which vendor specific implementations of DbSupport and ConstraintsDisabler are chosen.
database.dialect=mysql

# user properties
database.userName=${test.database.rules-satellite.username}
database.password=${test.database.rules-satellite.password}
database.schemaNames=${test.database.rules-satellite.schema}

When I run tests I get following error :

BEGIN NESTED EXCEPTION

java.net.UnknownHostException
MESSAGE: ${test.database.rules-satellite.server}

STACKTRACE:

java.net.UnknownHostException: ${test.database.rules-satellite.server}
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
    at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1202)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
    at java.net.InetAddress.getAllByName(InetAddress.java:1083)
    at java.net.InetAddress.getAllByName(InetAddress.java:1019)

I think maven properties not being propagated that's why unitils doesn't recognize them.


Solution

  • You need to use maven resources plugin with filtering option. More detailed explanation can be found here: http://www.manydesigns.com/en/portofino/portofino3/tutorials/using-maven-profiles-and-resource-filtering/#TOC-Resource-filtering