Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial draft of JPA/CDI EE integration tests #1623

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 79 additions & 11 deletions glassfish-runner/jpa-platform-tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

<properties>
<admin.user>admin</admin.user>
<arquillian.jakarta>10.0.0.Final</arquillian.jakarta>
<arquillian.junit>1.9.1.Final</arquillian.junit>
<connectionpoolid>${derby.poolName}</connectionpoolid>
<datasourceclassname>${derby.dataSource}</datasourceclassname>
Expand Down Expand Up @@ -106,6 +107,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.jakarta</groupId>
<artifactId>arquillian-parent-jakarta</artifactId>
<version>${arquillian.jakarta}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -271,6 +279,22 @@
<artifactId>tck-porting-lib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.test</groupId>
<artifactId>arquillian-test-impl-base</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-rest-jakarta</artifactId>
<version>${arquillian.jakarta}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>jakarta.tck</groupId>
<artifactId>common</artifactId>
Expand Down Expand Up @@ -510,11 +534,12 @@

<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
<executions>

<execution>
<id>jpa-tests-appclient</id>
<goals>
Expand Down Expand Up @@ -555,7 +580,50 @@
</configuration>
</execution>
<execution>
<id>jta-tests-javatest</id>
<id>jpa-tests-cdi</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.directory}/${glassfish.toplevel.dir}/javadb/lib/derbytools.jar</additionalClasspathElement>
<additionalClasspathElement>${project.build.directory}/${glassfish.toplevel.dir}/javadb/lib/derbyclient.jar</additionalClasspathElement>
<additionalClasspathElement>${project.build.directory}/${glassfish.toplevel.dir}/javadb/lib/derby.jar</additionalClasspathElement>
<additionalClasspathElement>${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/glassfish-naming.jar</additionalClasspathElement>
</additionalClasspathElements>
<includes>
<include>ee/jakarta/tck/persistence/ee/cdi/*Test.java</include>
</includes>
<dependenciesToScan>jakarta.tck:persistence-platform-tck-tests</dependenciesToScan>

<systemPropertyVariables>
<GLASSFISH_HOME>${project.build.directory}/${glassfish.toplevel.dir}</GLASSFISH_HOME>
<glassfish.home>${project.build.directory}/${glassfish.toplevel.dir}</glassfish.home>
<glassfish.postBootCommands>set server-config.network-config.protocols.protocol.http-listener-1.http.trace-enabled=true
create-file-user --groups guest --passwordfile ${project.basedir}/javajoe.pass javajoe
create-file-user --groups staff:mgr --passwordfile ${project.basedir}/j2ee.pass j2ee
create-jdbc-connection-pool --restype javax.sql.DataSource --datasourceclassname org.apache.derby.jdbc.ClientDataSource --property DatabaseName=derbyDB:serverName=localhost:portNumber=1527:user=cts1:password=cts1:connectionAttributes="create=true" --steadypoolsize 32 --maxpoolsize 64 cts-derby-pool
create-jdbc-connection-pool --restype javax.sql.DataSource --datasourceclassname org.apache.derby.jdbc.ClientDataSource --property DatabaseName=derbyDB:serverName=localhost:PortNumber=1527:User=cts1:Password=cts1 --steadypoolsize 32 --maxpoolsize 64 cts-derby-pool_no_tx
create-jdbc-resource --connectionpoolid cts-derby-pool jdbc/DB1
create-jdbc-resource --connectionpoolid cts-derby-pool_no_tx jdbc/DB_no_tx
list-jdbc-connection-pools
list-jdbc-resources
list-file-users</glassfish.postBootCommands>
<junit.log.traceflag>true</junit.log.traceflag>
<harness.log.traceflag>true</harness.log.traceflag>
<cts.harness.debug>true</cts.harness.debug>
<java.io.tmpdir>/tmp</java.io.tmpdir>
<project.basedir>${project.basedir}</project.basedir>
<arquillian.xml>rest-arquillian.xml</arquillian.xml>
</systemPropertyVariables>
<environmentVariables>
<GLASSFISH_HOME>${project.build.directory}/${glassfish.toplevel.dir}</GLASSFISH_HOME>
</environmentVariables>
</configuration>
</execution>
<execution>
<id>jpa-tests-javatest</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
Expand All @@ -580,15 +648,15 @@
<GLASSFISH_HOME>${project.build.directory}/${glassfish.toplevel.dir}</GLASSFISH_HOME>
<glassfish.home>${project.build.directory}/${glassfish.toplevel.dir}</glassfish.home>
<glassfish.postBootCommands>set server-config.network-config.protocols.protocol.http-listener-1.http.trace-enabled=true
create-file-user --groups guest --passwordfile ${project.basedir}/javajoe.pass javajoe
create-file-user --groups staff:mgr --passwordfile ${project.basedir}/j2ee.pass j2ee
create-jdbc-connection-pool --restype javax.sql.DataSource --datasourceclassname org.apache.derby.jdbc.ClientDataSource --property DatabaseName=derbyDB:serverName=localhost:portNumber=1527:user=cts1:password=cts1:connectionAttributes="create=true" --steadypoolsize 32 --maxpoolsize 64 cts-derby-pool
create-jdbc-connection-pool --restype javax.sql.DataSource --datasourceclassname org.apache.derby.jdbc.ClientDataSource --property DatabaseName=derbyDB:serverName=localhost:PortNumber=1527:User=cts1:Password=cts1 --steadypoolsize 32 --maxpoolsize 64 cts-derby-pool_no_tx
create-jdbc-resource --connectionpoolid cts-derby-pool jdbc/DB1
create-jdbc-resource --connectionpoolid cts-derby-pool_no_tx jdbc/DB_no_tx
list-jdbc-connection-pools
list-jdbc-resources
list-file-users</glassfish.postBootCommands>
create-file-user --groups guest --passwordfile ${project.basedir}/javajoe.pass javajoe
create-file-user --groups staff:mgr --passwordfile ${project.basedir}/j2ee.pass j2ee
create-jdbc-connection-pool --restype javax.sql.DataSource --datasourceclassname org.apache.derby.jdbc.ClientDataSource --property DatabaseName=derbyDB:serverName=localhost:portNumber=1527:user=cts1:password=cts1:connectionAttributes="create=true" --steadypoolsize 32 --maxpoolsize 64 cts-derby-pool
create-jdbc-connection-pool --restype javax.sql.DataSource --datasourceclassname org.apache.derby.jdbc.ClientDataSource --property DatabaseName=derbyDB:serverName=localhost:PortNumber=1527:User=cts1:Password=cts1 --steadypoolsize 32 --maxpoolsize 64 cts-derby-pool_no_tx
create-jdbc-resource --connectionpoolid cts-derby-pool jdbc/DB1
create-jdbc-resource --connectionpoolid cts-derby-pool_no_tx jdbc/DB_no_tx
list-jdbc-connection-pools
list-jdbc-resources
list-file-users</glassfish.postBootCommands>
<junit.log.traceflag>true</junit.log.traceflag>
<harness.log.traceflag>true</harness.log.traceflag>
<cts.harness.debug>true</cts.harness.debug>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<defaultProtocol type="Servlet 5.0" />
<engine>
<property name="deploymentExportPath">target/deployments</property>
</engine>
<extension qualifier="glassfish-descriptors">
<property name="descriptorDir">target/</property>
</extension>

<group qualifier="glassfish-servers" default="true">
<container qualifier="tck-rest" default="true">
<configuration>
<property name="glassFishHome">target/glassfish8</property>
</configuration>
</container>
</group>

</arquillian>
9 changes: 9 additions & 0 deletions jpa/platform-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@
<artifactId>arquillian-protocol-common</artifactId>
<version>${arquillian.jakarta.tck.version}</version>
</dependency>
<!-- For the CDI integration tests -->
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>

</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ee.jakarta.tck.persistence.ee.cdi;

import jakarta.inject.Qualifier;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Qualifier for selecting the CTS-EM persistence unit.
*/
@Qualifier
@Documented
@Retention(RUNTIME)
@Target({ FIELD, METHOD })
public @interface CtsEmNoTxQualifier {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ee.jakarta.tck.persistence.ee.cdi;

import jakarta.inject.Qualifier;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Qualifier for selecting the CTS-EM persistence unit.
*/
@Qualifier
@Documented
@Retention(RUNTIME)
@Target({ FIELD, METHOD })
public @interface CtsEmQualifier {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ee.jakarta.tck.persistence.ee.cdi;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

@ApplicationPath("/rest")
public class JaxRsActivator extends Application {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ee.jakarta.tck.persistence.ee.cdi;

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

/**
* Called by test client using the arquillian rest protocol
*/
@Path("/cdi-jpa")
public class RestEndpoint {
@Inject
TestBeanEM testBean;

@GET
@Path("/injectEmUsingQualifier")
public String injectEmUsingQualifier() throws Exception {
testBean.injectEmUsingQualifier();
return "PASSED";
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package ee.jakarta.tck.persistence.ee.cdi;

import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.core.Response;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import tck.arquillian.porting.lib.spi.TestArchiveProcessor;

import java.net.URI;
import java.net.URL;

import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;

/**
* Test for EntityManager lookup via CDI
*/
@ExtendWith(ArquillianExtension.class)
public class ServletEMLookupTest {
@ArquillianResource
URL contextPath;

@Deployment(name = "rest-em-lookup", testable = false)
public static WebArchive deployment(@ArquillianResource TestArchiveProcessor archiveProcessor) {
WebArchive war = ShrinkWrap.create(WebArchive.class, "rest-em-lookup.war")
.addClasses(CtsEmQualifier.class, CtsEmNoTxQualifier.class, JaxRsActivator.class,
TestBeanEM.class, RestEndpoint.class);

// Par
// the jar with the correct archive name
JavaArchive jpa_ee_entityManager = ShrinkWrap.create(JavaArchive.class, "jpa_ee_entityManager.jar");
// The class files
jpa_ee_entityManager.addClasses(
ee.jakarta.tck.persistence.ee.entityManager.Order.class
);
// The persistence.xml descriptor
URL parURL = ServletEMLookupTest.class.getResource("persistence.xml");
jpa_ee_entityManager.addAsManifestResource(parURL, "persistence.xml");
// Call the archive processor
archiveProcessor.processParArchive(jpa_ee_entityManager, ServletEMLookupTest.class, parURL);

// Web content
war.addAsLibrary(jpa_ee_entityManager);

// Call the archive processor
archiveProcessor.processWebArchive(war, ServletEMLookupTest.class, null);
return war;
}

/*
* @testName: injectEmUsingQualifierTest
*
* @assertion_ids: PERSISTENCE:JAVADOC:3318; PERSISTENCE:SPEC:1801;
* PERSISTENCE:SPEC:1804; PERSISTENCE:SPEC:1883.2;
*
* @test_Strategy: Inject an EntityManager using a qualifier and injection
*/
@Test
public void injectEmUsingQualifierTest() throws Exception {
URI appIdURI = contextPath.toURI().resolve("rest/cdi-jpa/injectEmUsingQualifier");
final Client client = ClientBuilder.newBuilder().build();
final Response response = client.target(appIdURI)
.request(APPLICATION_JSON_TYPE)
.get();
int status = response.getStatus();
Assertions.assertEquals(200, status);
response.close();
}
}
Loading