diff --git a/foundation/org.eclipse.persistence.core.test.framework/src/main/java/org/eclipse/persistence/testing/framework/junit/JUnitTestCaseHelper.java b/foundation/org.eclipse.persistence.core.test.framework/src/main/java/org/eclipse/persistence/testing/framework/junit/JUnitTestCaseHelper.java index 2ca544eb9bb..79c38ededcd 100644 --- a/foundation/org.eclipse.persistence.core.test.framework/src/main/java/org/eclipse/persistence/testing/framework/junit/JUnitTestCaseHelper.java +++ b/foundation/org.eclipse.persistence.core.test.framework/src/main/java/org/eclipse/persistence/testing/framework/junit/JUnitTestCaseHelper.java @@ -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 @@ -102,7 +102,8 @@ public static Map 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"}; diff --git a/jpa/org.eclipse.persistence.jpa.test.framework/pom.xml b/jpa/org.eclipse.persistence.jpa.test.framework/pom.xml index 286d7b1d373..481baf1a6ed 100644 --- a/jpa/org.eclipse.persistence.jpa.test.framework/pom.xml +++ b/jpa/org.eclipse.persistence.jpa.test.framework/pom.xml @@ -37,6 +37,11 @@ jakarta.persistence-api provided + + jakarta.annotation + jakarta.annotation-api + provided + org.eclipse.persistence diff --git a/jpa/org.eclipse.persistence.jpa.test.framework/src/main/java/org/eclipse/persistence/testing/framework/server/GenericTestRunner.java b/jpa/org.eclipse.persistence.jpa.test.framework/src/main/java/org/eclipse/persistence/testing/framework/server/GenericTestRunner.java index e312f60d7d5..83754ab42ba 100644 --- a/jpa/org.eclipse.persistence.jpa.test.framework/src/main/java/org/eclipse/persistence/testing/framework/server/GenericTestRunner.java +++ b/jpa/org.eclipse.persistence.jpa.test.framework/src/main/java/org/eclipse/persistence/testing/framework/server/GenericTestRunner.java @@ -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(); @@ -79,4 +80,8 @@ protected EntityManager getEntityManager() { protected EntityManagerFactory getEntityManagerFactory() { return null; } + + protected boolean getEjbLookup() { + return false; + } } diff --git a/jpa/org.eclipse.persistence.jpa.test.framework/src/main/java/org/eclipse/persistence/testing/framework/server/JEEPlatform.java b/jpa/org.eclipse.persistence.jpa.test.framework/src/main/java/org/eclipse/persistence/testing/framework/server/JEEPlatform.java index 3af9d881297..8b162759802 100644 --- a/jpa/org.eclipse.persistence.jpa.test.framework/src/main/java/org/eclipse/persistence/testing/framework/server/JEEPlatform.java +++ b/jpa/org.eclipse.persistence.jpa.test.framework/src/main/java/org/eclipse/persistence/testing/framework/server/JEEPlatform.java @@ -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. */ @@ -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); } } @@ -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); } } diff --git a/jpa/org.eclipse.persistence.jpa.test.framework/src/main/java/org/eclipse/persistence/testing/framework/server/SingleUnitTestRunnerBean.java b/jpa/org.eclipse.persistence.jpa.test.framework/src/main/java/org/eclipse/persistence/testing/framework/server/SingleUnitTestRunnerBean.java index 490563db714..03636521dc1 100644 --- a/jpa/org.eclipse.persistence.jpa.test.framework/src/main/java/org/eclipse/persistence/testing/framework/server/SingleUnitTestRunnerBean.java +++ b/jpa/org.eclipse.persistence.jpa.test.framework/src/main/java/org/eclipse/persistence/testing/framework/server/SingleUnitTestRunnerBean.java @@ -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; @@ -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. * @@ -47,6 +45,9 @@ public SingleUnitTestRunnerBean() { @PersistenceUnit private EntityManagerFactory entityManagerFactory; + @Resource(name="ejbLookup") + private Boolean ejbLookup = false; + @Override protected EntityManager getEntityManager() { return entityManager; @@ -56,4 +57,9 @@ protected EntityManager getEntityManager() { protected EntityManagerFactory getEntityManagerFactory() { return entityManagerFactory; } + + @Override + protected boolean getEjbLookup() { + return ejbLookup; + } }