5 Replies Latest reply on Nov 10, 2015 7:31 AM by raneves

    arquillian.xml: load properties from file

    wolf.moestl

      Hi,

       

      Is there a way to use settings stored in a properties file in arquillian.xml?

       

      What I want to archive:

      I've to set the "schema" property value within the "persistence-dbunit" extension to a non-static value (due to multi-developer environment).

       

      I know one can use a system property like the following:

      <property name="schema">${arquillian.db.user}</property>

      Unfortunately this is not an option as I do not want to force every developer to specify the settings in the commandline or to create a Enclipse run configuration per test class.

       

      Is there something like "include properties file" in arquillian.xml in order to set some system properties ?

       

      Thanks a lot!

       

      Cheers,

      Wolf

        • 1. Re: arquillian.xml: load properties from file
          bmajsak

          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

            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

              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

                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):

                1. Set the system property in each and every JUnit launch configuration (boring...)
                2. 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

                  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")