You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2026/05/13 19:31:14 UTC
(cayenne) 03/05: getting rid of Spring test dependency
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit 684b555cd0a400eeadfd26e97659e041f4f07937
Author: Andrus Adamchik <an...@objectstyle.com>
AuthorDate: Wed May 13 15:12:23 2026 -0400
getting rid of Spring test dependency
---
cayenne/pom.xml | 17 --
.../runtime/JNDIDataSourceFactoryIT.java | 1 -
.../cayenne/configuration/runtime/JNDISetup.java | 241 +++++++++++++++++++++
.../java/org/apache/cayenne/unit/JNDISetup.java | 57 -----
pom.xml | 20 --
5 files changed, 241 insertions(+), 95 deletions(-)
diff --git a/cayenne/pom.xml b/cayenne/pom.xml
index eecf911c5..686fc8930 100644
--- a/cayenne/pom.xml
+++ b/cayenne/pom.xml
@@ -62,23 +62,6 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-mock</artifactId>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <!-- do not need this one -->
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>com.mockrunner</groupId>
<artifactId>mockrunner-jdbc</artifactId>
diff --git a/cayenne/src/test/java/org/apache/cayenne/configuration/runtime/JNDIDataSourceFactoryIT.java b/cayenne/src/test/java/org/apache/cayenne/configuration/runtime/JNDIDataSourceFactoryIT.java
index 57037a439..85a114888 100644
--- a/cayenne/src/test/java/org/apache/cayenne/configuration/runtime/JNDIDataSourceFactoryIT.java
+++ b/cayenne/src/test/java/org/apache/cayenne/configuration/runtime/JNDIDataSourceFactoryIT.java
@@ -21,7 +21,6 @@ package org.apache.cayenne.configuration.runtime;
import com.mockrunner.mock.jdbc.MockDataSource;
import org.apache.cayenne.configuration.DataNodeDescriptor;
import org.apache.cayenne.di.Injector;
-import org.apache.cayenne.unit.JNDISetup;
import org.apache.cayenne.unit.di.runtime.CayenneProjects;
import org.apache.cayenne.unit.di.runtime.CayenneTestsEnv;
import org.junit.jupiter.api.extension.RegisterExtension;
diff --git a/cayenne/src/test/java/org/apache/cayenne/configuration/runtime/JNDISetup.java b/cayenne/src/test/java/org/apache/cayenne/configuration/runtime/JNDISetup.java
new file mode 100644
index 000000000..978a27882
--- /dev/null
+++ b/cayenne/src/test/java/org/apache/cayenne/configuration/runtime/JNDISetup.java
@@ -0,0 +1,241 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.configuration.runtime;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
+import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.InitialContextFactoryBuilder;
+import javax.naming.spi.NamingManager;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A helper to setup a shared test JNDI environment.
+ */
+class JNDISetup {
+
+ private static final Logger logger = LoggerFactory.getLogger(JNDISetup.class);
+
+ private static final String ENV_SUBCONTEXT = "java:comp/env";
+
+ private static final Map<String, Object> BINDINGS = new ConcurrentHashMap<>();
+
+ private static volatile boolean setup;
+
+ public static void doSetup() {
+ if (setup) {
+ return;
+ }
+ synchronized (JNDISetup.class) {
+ if (setup) {
+ return;
+ }
+ try {
+ NamingManager.setInitialContextFactoryBuilder(new InMemoryContextFactoryBuilder());
+ } catch (NamingException e) {
+ logger.error("Can't perform JNDI setup, ignoring...", e);
+ }
+ setup = true;
+ }
+ }
+
+ private static class InMemoryContextFactoryBuilder implements InitialContextFactoryBuilder {
+ @Override
+ public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment) {
+ return env -> new InMemoryContext("");
+ }
+ }
+
+ private static class InMemoryContext implements Context {
+
+ private final String prefix;
+
+ InMemoryContext(String prefix) {
+ this.prefix = prefix;
+ }
+
+ private String fullName(String name) {
+ return prefix.isEmpty() ? name : prefix + "/" + name;
+ }
+
+ @Override
+ public Object lookup(String name) throws NamingException {
+ String key = fullName(name);
+ if (ENV_SUBCONTEXT.equals(key)) {
+ return new InMemoryContext(key);
+ }
+ Object value = BINDINGS.get(key);
+ if (value == null) {
+ throw new NameNotFoundException(key);
+ }
+ return value;
+ }
+
+ @Override
+ public Object lookup(Name name) throws NamingException {
+ return lookup(name.toString());
+ }
+
+ @Override
+ public void bind(String name, Object obj) {
+ BINDINGS.put(fullName(name), obj);
+ }
+
+ @Override
+ public void bind(Name name, Object obj) {
+ bind(name.toString(), obj);
+ }
+
+ @Override
+ public void rebind(String name, Object obj) {
+ BINDINGS.put(fullName(name), obj);
+ }
+
+ @Override
+ public void rebind(Name name, Object obj) {
+ rebind(name.toString(), obj);
+ }
+
+ @Override
+ public void unbind(String name) {
+ BINDINGS.remove(fullName(name));
+ }
+
+ @Override
+ public void unbind(Name name) {
+ unbind(name.toString());
+ }
+
+ @Override
+ public void close() {
+ }
+
+ @Override
+ public void rename(Name oldName, Name newName) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public void rename(String oldName, String newName) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public void destroySubcontext(Name name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public void destroySubcontext(String name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public Context createSubcontext(Name name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public Context createSubcontext(String name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public Object lookupLink(Name name) throws NamingException {
+ return lookup(name);
+ }
+
+ @Override
+ public Object lookupLink(String name) throws NamingException {
+ return lookup(name);
+ }
+
+ @Override
+ public NameParser getNameParser(Name name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public NameParser getNameParser(String name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public Name composeName(Name name, Name prefix) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public String composeName(String name, String prefix) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ @Override
+ public Object addToEnvironment(String propName, Object propVal) {
+ return null;
+ }
+
+ @Override
+ public Object removeFromEnvironment(String propName) {
+ return null;
+ }
+
+ @Override
+ public Hashtable<?, ?> getEnvironment() {
+ return new Hashtable<>();
+ }
+
+ @Override
+ public String getNameInNamespace() {
+ return prefix;
+ }
+ }
+}
diff --git a/cayenne/src/test/java/org/apache/cayenne/unit/JNDISetup.java b/cayenne/src/test/java/org/apache/cayenne/unit/JNDISetup.java
deleted file mode 100644
index cb50c8370..000000000
--- a/cayenne/src/test/java/org/apache/cayenne/unit/JNDISetup.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ****************************************************************/
-package org.apache.cayenne.unit;
-
-import javax.naming.NamingException;
-import javax.naming.spi.NamingManager;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.mock.jndi.SimpleNamingContextBuilder;
-
-/**
- * A helper class to setup a shared test JNDI environment.
- */
-public class JNDISetup {
-
- private static Logger logger = LoggerFactory.getLogger(JNDISetup.class);
-
- private static volatile boolean setup;
-
- public static void doSetup() {
- if (!setup) {
-
- synchronized (JNDISetup.class) {
-
- if (!setup) {
- try {
- NamingManager
- .setInitialContextFactoryBuilder(new SimpleNamingContextBuilder());
- }
- catch (NamingException e) {
- logger.error("Can't perform JNDI setup, ignoring...", e);
- }
-
- setup = true;
- }
- }
- }
- }
-
-}
diff --git a/pom.xml b/pom.xml
index dd3b1ea84..91241a6b2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -383,26 +383,6 @@
<artifactId>mockrunner-jdbc</artifactId>
<version>2.0.7</version>
</dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>5.3.39</version>
- <exclusions>
- <exclusion>
- <groupId>xerces</groupId>
- <artifactId>xerces</artifactId>
- </exclusion>
- <exclusion>
- <groupId>xml-apis</groupId>
- <artifactId>xml-apis</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-mock</artifactId>
- <version>2.0.8</version>
- </dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>