-
1. Re: arquillian.xml: load properties from file
bmajsak Oct 13, 2014 8:49 AM (in response to wolf.moestl)Hi Wolfgang,
I think you can also use system-wide properties (env) in arquillian.xml (eg. JBOSS_HOME is used this way for jboss/wildfly container setup). Wouldn't it work?
Cheers,
Bartosz
-
2. Re: arquillian.xml: load properties from file
wolf.moestl Oct 13, 2014 9:44 AM (in response to bmajsak)Hi Bartosz,
That's what I indicated above using <property name="schema">${arquillian.db.user}</property>.
I will give the properties-maven-plugin a try for setting the system propery arquillian.db.user based on a value fetched from a property file.
Cheers,
Wolf
-
3. Re: arquillian.xml: load properties from file
bmajsak Oct 13, 2014 11:26 AM (in response to wolf.moestl)Right, I was low on coffee But on the other hand if you set it as env variable (on the OS level) do you really need to set it up in Eclipse for each and every test configuration? In such case it is global and should be fetched without any additional steps. Obviously each and every developer will need to set it, but only once.
-
4. Re: Re: arquillian.xml: load properties from file
wolf.moestl Oct 14, 2014 8:24 AM (in response to bmajsak)For the one who might be interested in, this is my working solution:
Goal: setting a user-specific configuration value in arquillian.xml using a value fetched from a file.
E.g. setting the "schema" value in "persistence-dbunit" extension in order to have ever developer running tests against his own schema in a central database (no, neither a local Oracle XE was an option nor using In-Memory DB H2).
Solution:
1. Use a system property im arquillian.xml:
<extension qualifier="persistence-dbunit">
<property name="schema">${arquillian.db.user}</property>
</extension>
2. Load a user-specific property file using properties-maven-plugin (every developer has his own file following a naming convention including the login name):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<executions>
<execution>
<id>properties-read-db-settings</id>
<phase>validate</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<!-- load the necessary properties from file, notice the usage of the "user.name" system property -->
<file>somefolder/db-config_${user.name}.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
3. Inject the loaded property "db.user" (is defined in the file loaded in step 2) as the system property "arquillian.db.user" expected by arquillian-xml (see setp 1):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<!-- Set the system property -->
<arquillian.db.user>${db.user}</arquillian.db.user>
</systemPropertyVariables>
</configuration>
</plugin>
That's it.
In terms of running JUnit tests out of Eclipse:
Unfortunately there is no way to configure default settings for all JUnit tests in Eclipse.
So there are 2 ways to inject the necessary system property (at least I know of):
- Set the system property in each and every JUnit launch configuration (boring...)
- Set the system property as default VM Argument in the JRE definition: Preferences => Java => Installed JREs => Select your JRE + Edit => Default VM arguments= "-Darquillian.db.user=theDBUser" (without the quotes)
Now each and every JUnit Run started using "Run as" => "JUnit Test" knows about the system property arquillian.db.user.
-
5. Re: arquillian.xml: load properties from file
raneves Nov 10, 2015 7:31 AM (in response to wolf.moestl)Hi,
I using spring for load properties file. like that:
in applicationContextTest.xml:
<context:property-placeholder
location="classpath:/conf/app.testProperties, classpath:/conf/buildInfo.testProperties"
ignore-resource-not-found="true"/>
in my Deployment:
.addAsResource("conf/app.testProperties", "app.properties")