Categories
continuous-integration java maven-2 spring

Can I inject properties from Maven (passwords defined in settings.xml) into my Spring container?

I define passwords to servers via properties I define in my ~/.m2/settings.xml (could be anywhere, though, including pom.xml) for my deployment plugin. I’d like to use the same properties for my integration tests. Is there a way to do so?

If not, is there a convenient way to share properties between Maven and TestNG?

I want to write a nice test suite that can run on different continuous integration servers, pointing to different remote hosts (development, testing, staging, and production), without modification of the code.

I am defining credentials to a remote service in settings.xml:

<properties>
<my.host>http://my.company.com</my.host>
<my.username>my-un</my.username>
<my.password>my-pw</my.password>
</properties>

I’d like to be able to reference the properties in my unit/integration tests (src/test/resources) using:

<?xml version="1.0" encoding="UTF-8"?>
<beans....
<bean class="java.lang.String" id="un">
<constructor-arg value="${my.username}"/>
</bean>
<bean class="java.lang.String" id="pw">
<constructor-arg value="${my.password}"/>
</bean>
</beans>

Are there any options to doing this? Has anyone else tried this before? I am writing a lot of REST tests which require authorization in my tests.

Thanks!