Skip to content

Commit

Permalink
avoid the need to set ejb.lookup property
Browse files Browse the repository at this point in the history
on the server by introducing the ability to provide it directly to the test itself
via env-entry in ejb-jar.xml;
provide temporary hook to NOT prefix member PU names for extended.xml.composite members

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj authored and rfelcman committed Jul 8, 2022
1 parent 722dfdd commit 18eebcb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -102,7 +102,8 @@ public static Map<String, String> getDatabaseProperties(String puName) {
if (puProperties == null) {
if (puName.equals("composite-advanced") || puName.equals("xml-composite-advanced") || puName.equals("xml-extended-composite-advanced")) {
String prefix = puName;
if (puName.equals("xml-extended-composite-advanced")) {
//temporary during the rename of the xml-extended-composite-advanced members
if (!Boolean.getBoolean("el.skip.prefix-check") && puName.equals("xml-extended-composite-advanced")) {
prefix = "xml-composite-advanced";
}
String[] sessions = {"member_1", "member_2", "member_3"};
Expand Down
5 changes: 5 additions & 0 deletions jpa/org.eclipse.persistence.jpa.test.framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<artifactId>jakarta.persistence-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<scope>provided</scope>
</dependency>
<!--Other modules-->
<dependency>
<groupId>org.eclipse.persistence</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public Throwable runTest(String className, String test, Properties props) {
JUnitTestCase jpaTest = (JUnitTestCase) testInstance;
JEEPlatform.entityManager = getEntityManager();
JEEPlatform.entityManagerFactory = getEntityManagerFactory();
JEEPlatform.ejbLookup = getEjbLookup();
jpaTest.runBareServer();
} else {
testInstance.runBare();
Expand All @@ -79,4 +80,8 @@ protected EntityManager getEntityManager() {
protected EntityManagerFactory getEntityManagerFactory() {
return null;
}

protected boolean getEjbLookup() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class JEEPlatform implements ServerPlatform {
/** The variable for getting entity manager by jndi lookup, set the system property "ejb.lookup" to be true if you want jndi lookup */
public static final String EJB_LOOKUP = "ejb.lookup";

public static boolean ejbLookup = false;

/**
* Nothing required in JEE.
*/
Expand Down Expand Up @@ -170,14 +172,26 @@ public boolean isClustered() {
*/
@Override
public EntityManager getEntityManager(String persistenceUnit) {
String property = System.getProperty(EJB_LOOKUP);
if (property == null || !property.toUpperCase().equals("TRUE")){
boolean useLookup = ejbLookup || Boolean.getBoolean(EJB_LOOKUP);
if (!useLookup) {
return entityManager;
} else {
String contextName = "java:comp/env/persistence/" + persistenceUnit + "/entity-manager";
try {
return (EntityManager)new InitialContext().lookup(contextName);
} catch (NamingException exception) {
//most tests do not need the fallback lookup as the java:comp/env
//is the only namespace they should worry about
if (persistenceUnit.contains("member")) {
//retry within application space:
String appContextName = "java:app/persistence/" + persistenceUnit + "/entity-manager";
try {
return (EntityManager)new InitialContext().lookup(appContextName);
} catch (NamingException e) {
e.addSuppressed(exception);
throw new RuntimeException(e);
}
}
throw new RuntimeException(exception);
}
}
Expand All @@ -188,14 +202,26 @@ public EntityManager getEntityManager(String persistenceUnit) {
*/
@Override
public EntityManagerFactory getEntityManagerFactory(String persistenceUnit) {
String property = System.getProperty(EJB_LOOKUP);
if (property == null || !property.toUpperCase().equals("TRUE")){
boolean useLookup = ejbLookup || Boolean.getBoolean(EJB_LOOKUP);
if (!useLookup) {
return entityManagerFactory;
} else{
String contextName = "java:comp/env/persistence/" + persistenceUnit + "/factory";
try {
return (EntityManagerFactory)new InitialContext().lookup(contextName);
} catch (NamingException exception) {
//most tests do not need the fallback lookup as the java:comp/env
//is the only namespace they should worry about
if (persistenceUnit.contains("member")) {
//retry within application space:
String appContextName = "java:app/persistence/" + persistenceUnit + "/factory";
try {
return (EntityManagerFactory)new InitialContext().lookup(appContextName);
} catch (NamingException e) {
e.addSuppressed(exception);
throw new RuntimeException(e);
}
}
throw new RuntimeException(exception);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.testing.framework.server;

import jakarta.annotation.Resource;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionManagement;
Expand All @@ -23,9 +24,6 @@
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.PersistenceUnit;

import org.eclipse.persistence.testing.framework.server.GenericTestRunner;
import org.eclipse.persistence.testing.framework.server.TestRunner;

/**
* Server side JUnit test invocation implemented as a stateless session bean.
*
Expand All @@ -47,6 +45,9 @@ public SingleUnitTestRunnerBean() {
@PersistenceUnit
private EntityManagerFactory entityManagerFactory;

@Resource(name="ejbLookup")
private Boolean ejbLookup = false;

@Override
protected EntityManager getEntityManager() {
return entityManager;
Expand All @@ -56,4 +57,9 @@ protected EntityManager getEntityManager() {
protected EntityManagerFactory getEntityManagerFactory() {
return entityManagerFactory;
}

@Override
protected boolean getEjbLookup() {
return ejbLookup;
}
}

0 comments on commit 18eebcb

Please sign in to comment.