X

Technical Articles relating to Oracle Development Tools and Frameworks

  • ADF
    August 13, 2014

Maven and ADFBC Unit Tests in 12.1.3

Duncan Mills
Architect

An issue that has come up recently has revolved around setting your Maven POM up in 12.1.3 such that you can run ADF BC JUnit Tests successfully both interactively in the IDE and headless through Maven maybe in your Hudson Jobs.  Out of the box, the default POM that you will end up with will be missing a couple of vital bits of information and need a little extra configuration.

Here are the steps you'll need to take:

Step 1: Use The Correct JUnit Dependency

Once you have created some unit tests JDeveloper will have added dependencies for JUnit from the JDeveloper JUnit extensions, something like this:

<dependency>
<groupId>com.oracle.adf.library</groupId>
  <artifactId>JUnit-4-Runtime</artifactId>
  <version>12.1.3-0-0</version>
  <type>pom</type>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>com.oracle.adf.library</groupId>
  <artifactId>JUnit-Runtime</artifactId>
  <version>12.1.3-0-0</version>
  <type>pom</type>
  <scope>test</scope>
</dependency> 

Delete both of these entries, if they exist, and drop in a dependency to the vanilla JUnit 4.11 library instead:

<dependency>
<groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
  <type>jar</type>
  <scope>test</scope>
</dependency> 

Failing to make this change will result in the following error:

 java.lang.NoClassDefFoundError: org/junit/runner/notification/RunListener 

Step 2: Configure the Surefire Plugin to Select the Correct JUnit Version

This is probably not needed but it ensures that Surefire is left in no doubt about what version of JUnit it shoudl be working with (in this case a version of 4.7 or higher):

<plugin>
<groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.17</version>
  <dependencies>
  <dependency>
    <groupId>org.apache.maven.surefire</groupId>
      <artifactId>surefire-junit47</artifactId>
      <version>2.17</version>
    </dependency>
  </dependencies>
</plugin>

Step 3 : Identifying Your connections.xml File 

When running outside of JDeveloper we need to set things up so that  the unit tests can actually find the connection information that defines the datasource that your Application Modules are using.  To do this, we need to add a configuration section to the  Surefire plugin to add the location into the classpath.  Add the collowing configuration into the Surefire plugin, after the <dependencies>  section:

<configuration>
<additionalClasspathElements>
  <additionalClasspathElement>
    ${basedir}/../.adf
    </additionalClasspathElement>
  </additionalClasspathElements>
</configuration> 

This will ensure that the connection information can be found.  If you forget this step you'll get a stack trace including the message:

MDS-00013: no metadata found for metadata object "/META-INF/connections.xml" 

Step 4 - Supply the Missing JPS Library

Finally we need to supply the location of one extra required library.  This requirement will hopefully be resolved in the next release, but for now add it.  Again this is added to the Surefire plugin configuration <additionalClasspathElements> 

<additionalClasspathElement>
${oracleHome}/oracle_common/modules/oracle.jps_12.1.3/jps-manifest.jar
</additionalClasspathElement> 

Omitting this will result in the error:

WARNING: No credential could be loaded for Reference = Reference Class Name: oracle.jdeveloper.db.adapter.DatabaseProvider

For reference here's the complete Surefire plugin definition 

<plugin>
<groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.17</version>
  <dependencies>
  <dependency>
    <groupId>org.apache.maven.surefire</groupId>
      <artifactId>surefire-junit47</artifactId>
      <version>2.17</version>
    </dependency>
  </dependencies>
  <configuration>
  <additionalClasspathElements>
    <additionalClasspathElement>
      ${basedir}/../.adf
      </additionalClasspathElement>
      <additionalClasspathElement>
        ${oracleHome}/oracle_common/modules/oracle.jps_12.1.3/jps-manifest.jar
      </additionalClasspathElement>
    </additionalClasspathElements>
  </configuration>
</plugin> 

Join the discussion

Comments ( 1 )
  • Vladimir Tsoy Friday, September 5, 2014

    Thanks for the share Duncan, this was very helpful.

    Vladimir


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha