Skip to content

Latest commit

 

History

History
 
 

eclipselink.jpa.testapps

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

EclipseLink Test Applications

Test Aplication layout

test-app/
├─ src/
│  ├─ main
│  │  ├─ java
│  │  │  ├─ ...model...
│  │  ├─ resources
│  │  │  ├─ META-INF
│  │  │  │  ├─ persistence.xml
│  │  │  ├─ ...other resources...
│  │  ├─ resources-ear (optional)
│  │  │  ├─ ...model...
│  │  ├─ resources-ejb (optional)
│  │  │  ├─ ...model...
│  ├─ test
│  │  ├─ java
│  │  │  ├─ ...tests...
├─ pom.xml
  • src/main/java contains model used by tests
  • src/main/resources/META-INF/persistence.xml descriptor for the SE environment, server-side version is generated by the build if no customized descriptor is provided in src/main/resources-ejb/META-INF/persistence.xml
  • src/main/resources-ejb optional directory for ejb jar specific resources for server-side testing, packaged into test-app_ejb.jar
  • src/main/resources-ear optional directory for ear specific resources for server-side testing, packaged into test-app.ear
  • src/test/java contains actual tests
  • EJB/EAR archives are produced by the eclipselink-testbuild-plugin
  • pom.xml reference:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>org.eclipse.persistence.jpa.testapps</artifactId>
        <groupId>org.eclipse.persistence</groupId>
        <version>4.1.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>org.eclipse.persistence.jpa.testapps.foo</artifactId>

    <name>Test - foo</name>

    <dependencies>
        <!-- dependency on an already available model -->
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa.testapps.inheritance</artifactId>
            <version>${project.version}</version>
            <classifier>model</classifier>
            <scope>provided</scope>
        </dependency>
        <!-- dependency on an already available tests -->
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa.testapps.inherited</artifactId>
            <version>${project.version}</version>
            <classifier>tests</classifier>
            <type>test-jar</type>
            <scope>provided</scope>
        </dependency>
        <!-- test specific dependencies (if any) -->
        ...
    </dependencies>

    <properties>
        <!-- skip SE tests execution -->
        <se.test.skip>false</se.test.skip>
        <!-- skip server tests execution -->
        <server.test.skip>false</server.test.skip>
        <!-- ignore failures in SE tests -->
        <ignore.se.failures>false</ignore.se.failures>
        <!-- ignore failures in server tests -->
        <ignore.server.failures>false</ignore.server.failures>
        
        <argLine/>
    </properties>

    <build>
        <plugins>
            <!-- generate canonical metamodel classes -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <!-- turn-off default compilation -->
                    <execution>
                        <id>default-compile</id>
                        <phase>none</phase>
                    </execution>
                    <!-- turn-on compilation with canonical model processor -->
                    <execution>
                        <id>compile-with-processor</id>
                        <phase>compile</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <!--Resolve dependencies into Maven properties like ${org.eclipse.persistence:org.eclipse.persistence.jpa:jar} for JPA module-->
                    <execution>
                        <id>get-test-classpath-to-properties</id>
                        <phase>process-test-classes</phase>
                    </execution>
                </executions>
            </plugin>
            <!-- start/stop in-memory derby before/after the test -->
            <plugin>
                <groupId>org.carlspring.maven</groupId>
                <artifactId>derby-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>start-derby</id>
                        <phase>process-test-classes</phase>
                    </execution>
                    <execution>
                        <id>stop-derby</id>
                        <phase>prepare-package</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-test</id>
                        <configuration>
                            <!-- turn on dynamic weaving -->
                            <argLine>-javaagent:${org.eclipse.persistence:org.eclipse.persistence.jpa:jar} @{argLine}</argLine>
                        </configuration>
                    </execution>
                    <execution>
                        <id>server-test</id>
                        <configuration>
                            <!-- exclude some tests from server-side run -->
                            <excludes>
                                <exclude>**/EntityManagerImplTest</exclude>
                                <exclude>**/EntityManagerFactoryImplTest</exclude>
                            </excludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <executions>
                    <!-- package model for other test apps to use -->
                    <execution>
                        <id>package-model</id>
                        <phase>package</phase>
                    </execution>
                    <!-- package tests for other test apps to use -->
                    <execution>
                        <id>package-se-tests</id>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- for Oracle DB -->
            <id>oracle</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>sql-maven-plugin</artifactId>
                        <configuration>
                            <username>${db.user}</username>
                            <password>${db.pwd}</password>
                            <autocommit>true</autocommit>
                            <onError>continue</onError>
                        </configuration>
                        <executions>
                            <!-- prepare DB object (type) for struct-converter -->
                            <execution>
                                <id>struct-converter-sql</id>
                                <phase>process-test-resources</phase>
                                <goals>
                                    <goal>execute</goal>
                                </goals>
                                <configuration>
                                    <sqlCommand>
                                        CREATE OR REPLACE TYPE MY_GEOMETRY AS OBJECT (id NUMBER, geom MDSYS.SDO_GEOMETRY);
                                    </sqlCommand>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

Running & debugging tests

Edit properties file in $REPO/etc to match you environment and then:

  • mvn verify -pl :org.eclipse.persistence.jpa.testapps -amd - runs all tests against default in-memory Derby DB in Java SE environment; the DB is started/stopped for every testapp

  • mvn verify -pl :org.eclipse.persistence.jpa.testapps -amd -Pmysql - runs all tests against MySQL DB in Java SE environment; the DB must be started/stopped externally. This allows running tests in parallel (ie -T3C maven option or using mvnd)

  • mvn verify -pl :org.eclipse.persistence.jpa.testapps -amd -Pmysql,wildfly - runs all tests against MySQL DB in Java SE environment and in Jakarta EE environment on WildFly server; the DB must be started/stopped externally. To allow running tests in parallel (ie -T3C maven option or using mvnd), datasources on the server need to point to different MySQL DB schemas from those used for running in the SE env.

  • mvn test -pl :org.eclipse.persistence.jpa.testapps.jpql -Poracle - runs all JPQL tests against Oracle DB in Java SE

  • mvn test -pl :org.eclipse.persistence.jpa.testapps.jpql -Dtest=JUnitJPQLDateTimeTest -Pmysql - runs single JPQL test against MySQL DB in Java SE

  • use -Dmaven.surefire.debug property to debug tests; the debugger will wait on port 5005

WildFly configuration

EclipseLink module

WILDFLY_HOME=...
REPO_HOME=$HOME/.m2/repository/org/eclipse/persistence
VERSION=4.1.0-SNAPSHOT
ASM_VERSION=9.4.0

WR=$WILDFLY_HOME/modules/system/layers/base/org/eclipse/persistence/main

cp -v $REPO_HOME/org.eclipse.persistence.asm/$ASM_VERSION/org.eclipse.persistence.asm-$ASM_VERSION.jar $WR/org.eclipse.persistence.asm.jar
cp -v $REPO_HOME/org.eclipse.persistence.core/$VERSION/org.eclipse.persistence.core-$VERSION.jar $WR/org.eclipse.persistence.core.jar
cp -v $REPO_HOME/org.eclipse.persistence.jpa/$VERSION/org.eclipse.persistence.jpa-$VERSION.jar $WR/org.eclipse.persistence.jpa.jar
cp -v $REPO_HOME/org.eclipse.persistence.jpa.jpql/$VERSION/org.eclipse.persistence.jpa.jpql-$VERSION.jar $WR/org.eclipse.persistence.jpa.jpql.jar
cp -v $REPO_HOME/org.eclipse.persistence.moxy/$VERSION/org.eclipse.persistence.moxy-$VERSION.jar $WR/org.eclipse.persistence.moxy.jar
cp -v $REPO_HOME/org.eclipse.persistence.oracle/$VERSION/org.eclipse.persistence.oracle-$VERSION.jar $WR/org.eclipse.persistence.oracle.jar

echo '<module name="org.eclipse.persistence" xmlns="urn:jboss:module:1.9">
    <properties>
        <property name="jboss.api" value="public"/>
    </properties>

    <resources>
        <resource-root path="jipijapa-eclipselink-jakarta-27.0.0.Alpha4.jar"/>
        <resource-root path="org.eclipse.persistence.asm.jar"/>
        <resource-root path="org.eclipse.persistence.core.jar"/>
        <resource-root path="org.eclipse.persistence.jpa.jar" />
        <resource-root path="org.eclipse.persistence.jpa.jpql.jar"/>
        <resource-root path="org.eclipse.persistence.moxy.jar"/>
        <resource-root path="org.eclipse.persistence.oracle.jar"/>
    </resources>

    <dependencies>
        <module name="java.desktop"/>
        <module name="java.instrument"/>
        <module name="java.logging"/>
        <module name="java.management"/>
        <module name="java.naming"/>
        <module name="java.rmi"/>
        <module name="java.xml"/>
        <module name="jdk.unsupported"/>
        <module name="jakarta.annotation.api"/>
        <module name="jakarta.enterprise.api"/>
        <module name="jakarta.json.api" optional="true"/>
        <module name="javax.persistence.api"/>
        <module name="jakarta.transaction.api"/>
        <module name="jakarta.validation.api"/>
        <module name="jakarta.xml.bind.api"/>
        <module name="org.jboss.as.jpa.spi"/>
        <module name="org.jboss.logging"/>
        <module name="org.jboss.vfs"/>
        <module name="com.oracle.ojdbc11" optional="true"/>
    </dependencies>

</module>' > $WR/module.xml

MySQL

JDBC driver

connect
module add --name=com.mysql.driver8 --resources=$HOME/.m2/repository/com/mysql/mysql-connector-j/8.0.32/mysql-connector-j-8.0.32.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=mysql8/:add(driver-module-name=com.mysql.driver8,driver-name=mysql8,driver-class-name=com.mysql.cj.jdbc.Driver,driver-major-version=8,driver-minor-version=0)
:shutdown(restart=true)

DataSources

connect
data-source add --jndi-name=java:/jdbc/EclipseLinkDS --name=EclipseLinkDS --connection-url=jdbc:mysql://localhost:3306/testds --driver-name=mysql8 --user-name=root —-password=root --jta=true --validate-on-match=true --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter --enabled=true
/subsystem=datasources/data-source=EclipseLinkDS:write-attribute(name=password,value=testds)

xa-data-source add --jndi-name=java:/jdbc/EclipseLinkXADS --name=EclipseLinkXADS --driver-name=mysql8 --user-name=root —-password=root --xa-datasource-class=com.mysql.cj.jdbc.MysqlXADataSource --validate-on-match=true --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter --enabled=true --xa-datasource-properties={"ServerName"="localhost","PortNumber"="3306","DatabaseName"="testxads1"}
/subsystem=datasources/xa-data-source=EclipseLinkXADS:write-attribute(name=password,value=testxads1)

xa-data-source add --jndi-name=java:/jdbc/EclipseLinkDS2 --name=EclipseLinkDS2 --driver-name=mysql8 --user-name=root —-password=root --xa-datasource-class=com.mysql.cj.jdbc.MysqlXADataSource --validate-on-match=true --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter --enabled=true --xa-datasource-properties={"ServerName"="localhost","PortNumber"="3306","DatabaseName"="testxads2"}
/subsystem=datasources/xa-data-source=EclipseLinkDS2:write-attribute(name=password,value=testxads2)

xa-data-source add --jndi-name=java:/jdbc/EclipseLinkDS3 --name=EclipseLinkDS3 --driver-name=mysql8 --user-name=root —-password=root --xa-datasource-class=com.mysql.cj.jdbc.MysqlXADataSource --validate-on-match=true --valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter --enabled=true --xa-datasource-properties={"ServerName"="localhost","PortNumber"="3306","DatabaseName"="testxads3"}
/subsystem=datasources/xa-data-source=EclipseLinkDS3:write-attribute(name=password,value=testxads3)

:reload

Oracle

JDBC driver

connect
module add --name=com.oracle.ojdbc11 --resources=$HOME/.m2/repository/com/oracle/database/jdbc/ojdbc11/21.6.0.0.1/ojdbc11-21.6.0.0.1.jar:$HOME/.m2/repository/com/oracle/database/jdbc/ucp/21.6.0.0.1/ucp-21.6.0.0.1.jar:$HOME/.m2/repository/com/oracle/database/ha/simplefan/21.6.0.0.1/simplefan-21.6.0.0.1.jar:$HOME/.m2/repository/com/oracle/database/ha/ons/21.6.0.0.1/ons-21.6.0.0.1.jar:$HOME/.m2/repository/com/oracle/database/xml/xmlparserv2/21.6.0.0.1/xmlparserv2-21.6.0.0.1.jar:$HOME/.m2/repository/com/oracle/database/xml/xdb/21.6.0.0.1/xdb-21.6.0.0.1.jar:$HOME/.m2/repository/com/oracle/database/nls/orai18n/21.6.0.0.1/orai18n-21.6.0.0.1.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=ojdbc11/:add(driver-module-name=com.oracle.ojdbc11,driver-name=ojdbc11,driver-class-name=oracle.jdbc.OracleDriver,driver-major-version=21,driver-minor-version=6)
:shutdown(restart=true)

DataSources

connect
data-source add --jndi-name=java:/jdbc/EclipseLinkDS --name=EclipseLinkDS --connection-url=jdbc:oracle:thin:@//localhost:1521/ORCLPDB1 --driver-name=ojdbc11 --user-name=testds —-password=testds --jta=true --validate-on-match=true --enabled=true
/subsystem=datasources/data-source=EclipseLinkDS:write-attribute(name=password,value=tst)

# XA ds TBD

Add new server configuration

To add new server configuration for runnig tests, define new profile which does deploy/undeploy, test execution and sets properties for the test run. Manual JDBC DS creation and server start up/shutdown is currently required.

In the WildFly example below, deploy is bound to pre-integration-test, test-run to integration-test, and undeploy to post-integration-test phase.

    <profile>
        <!-- server ID -->
        <id>wildfly</id>
        <properties>
            <!-- EJB client configuration -->
            <server.jndi.factory>org.wildfly.naming.client.WildFlyInitialContextFactory</server.jndi.factory>
            <server.remote.url>remote+http://localhost:8080</server.remote.url>
            <!-- don't deploy anything if tests are being skipped -->
            <wildfly.deploy.skip>${server.test.skip}</wildfly.deploy.skip>
        </properties>
        <!-- server specific dependencies (EJB client) -->
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.wildfly</groupId>
                    <artifactId>wildfly-client-all</artifactId>
                    <version>27.0.0.Alpha4</version>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.wildfly</groupId>
                <artifactId>wildfly-client-all</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.wildfly.plugins</groupId>
                    <artifactId>wildfly-maven-plugin</artifactId>
                    <version>2.1.0.Beta1</version>
                    <configuration>
                        <skip>${wildfly.deploy.skip}</skip>
                        <username>${wildfly.username}</username>
                        <password>${wildfly.password}</password>
                        <name>${project.build.finalName}.ear</name>
                    </configuration>
                    <executions>
                        <execution>
                            <id>server-deploy</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>deploy-only</goal>
                            </goals>
                            <configuration>
                                <filename>${project.build.finalName}.ear</filename>
                                <force>true</force>
                            </configuration>
                        </execution>
                        <execution>
                            <id>server-undeploy</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>undeploy</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>server-test</id>
                            <phase>integration-test</phase>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

Oracle Spatial

Oracle Spatial API jar is available either in the Oracle DB installation or in the Oracle SQL Developer. To be able to run tests for this functionality, locate sdoapi.jar in the instalation of one of these products and install it into local maven repository, ie via:

mvn install:install-file -Dfile=sdoapi.jar -DgroupId=com.oracle.spatial -DartifactId=sdoapi -Dversion=LOCAL -Dpackaging=jar

To run tests on the server, add the sdoapi.jar to the Oracle JDBC driver library there.