-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1623 from jakartaee/issue1405
Initial draft of Jakarta Persistence/CDI EE integration tests
- Loading branch information
Showing
13 changed files
with
386 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
glassfish-runner/jpa-platform-tck/src/test/resources/rest-arquillian.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
glassfish-runner/persistence-platform-tck/src/test/resources/rest-arquillian.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
jpa/platform-tests/src/main/java/ee/jakarta/tck/persistence/ee/cdi/CtsEm2Qualifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-EM2 persistence unit. | ||
*/ | ||
@Qualifier | ||
@Documented | ||
@Retention(RUNTIME) | ||
@Target({ FIELD, METHOD }) | ||
public @interface CtsEm2Qualifier { | ||
} |
21 changes: 21 additions & 0 deletions
21
jpa/platform-tests/src/main/java/ee/jakarta/tck/persistence/ee/cdi/CtsEmNoTxQualifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
21 changes: 21 additions & 0 deletions
21
jpa/platform-tests/src/main/java/ee/jakarta/tck/persistence/ee/cdi/CtsEmQualifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
9 changes: 9 additions & 0 deletions
9
jpa/platform-tests/src/main/java/ee/jakarta/tck/persistence/ee/cdi/JaxRsActivator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
jpa/platform-tests/src/main/java/ee/jakarta/tck/persistence/ee/cdi/RestEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
|
||
|
||
} |
76 changes: 76 additions & 0 deletions
76
jpa/platform-tests/src/main/java/ee/jakarta/tck/persistence/ee/cdi/ServletEMLookupTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "jpa-cdi-em-inject", testable = false) | ||
public static WebArchive deployment(@ArquillianResource TestArchiveProcessor archiveProcessor) { | ||
WebArchive war = ShrinkWrap.create(WebArchive.class) | ||
.addClasses(CtsEmQualifier.class, CtsEm2Qualifier.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(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
jpa/platform-tests/src/main/java/ee/jakarta/tck/persistence/ee/cdi/TestBeanEM.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ee.jakarta.tck.persistence.ee.cdi; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
|
||
import java.util.logging.Logger; | ||
|
||
/** | ||
* A request scoped bean that uses the CTS-EM and CTS-EM-NOTX persistence units | ||
*/ | ||
@RequestScoped | ||
public class TestBeanEM { | ||
Logger logger = Logger.getLogger(TestBeanEM.class.getName()); | ||
|
||
//@PersistenceContext(unitName = "CTS-EM") | ||
@CtsEmQualifier | ||
@Inject | ||
private EntityManager em1; | ||
//@PersistenceContext(unitName = "CTS-EM2") | ||
@CtsEmQualifier | ||
@Inject | ||
private EntityManager em2; | ||
|
||
public void logMsg(String msg) { | ||
logger.info(msg); | ||
} | ||
public void logTrace(String msg) { | ||
logger.fine(msg); | ||
} | ||
public void logErr(String msg) { | ||
logger.severe(msg); | ||
} | ||
public void logErr(String msg, Throwable e) { | ||
logger.log(java.util.logging.Level.SEVERE, msg, e); | ||
} | ||
|
||
public void injectEmUsingQualifier() throws Exception { | ||
boolean pass1 = false; | ||
boolean pass2 = false; | ||
try { | ||
logMsg( "Test CtsEmNoTxQualifier"); | ||
if (em1 != null) { | ||
logTrace( "Received non-null EntityManager"); | ||
pass1 = true; | ||
} else { | ||
logErr( "Received null EntityManager"); | ||
} | ||
} catch (Exception e) { | ||
logErr( "Received unexpected exception", e); | ||
} | ||
try { | ||
logMsg( "Test CtsEmNoTxQualifier"); | ||
if (em2 != null) { | ||
logTrace( "Received non-null EntityManager"); | ||
pass2 = true; | ||
} else { | ||
logErr( "Received null EntityManager"); | ||
} | ||
} catch (Exception e) { | ||
logErr( "Received unexpected exception", e); | ||
} | ||
if (!pass1 || !pass2) { | ||
throw new Exception("createEntityManagerSynchronizationTypeMapTest failed"); | ||
} | ||
logMsg( "Test PASSED"); | ||
} | ||
|
||
} |
Oops, something went wrong.