This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9b24690cdc2e9905c0f42e048c9d02e42ddbe438 Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Wed Mar 4 00:02:05 2020 +0100 Completely remove the deprecated JndiRegistry --- .../camel/component/fhir/FhirConfigurationIT.java | 2 +- .../google/calendar/CalendarConfigurationTest.java | 2 +- .../google/drive/DriveConfigurationTest.java | 2 +- .../google/mail/GmailConfigurationTest.java | 2 +- .../google/sheets/SheetsConfigurationTest.java | 2 +- .../camel/component/netty/NettyRedeliveryTest.java | 2 +- .../apache/camel/test/junit4/CamelTestSupport.java | 71 +------------------ .../org/apache/camel/impl/DefaultCamelContext.java | 15 ---- .../java/org/apache/camel/impl/JndiRegistry.java | 61 ---------------- .../bean/BeanLookupUsingJndiRegistryIssueTest.java | 4 +- .../apache/camel/impl/GetRegistryAsTypeTest.java | 5 +- .../org/apache/camel/impl/JndiRegistryTest.java | 81 ---------------------- .../impl/LifecycleStrategyFailOnStartupTest.java | 3 +- .../camel/impl/LifecycleStrategyServiceTest.java | 3 +- .../camel/impl/MultipleLifecycleStrategyTest.java | 3 +- 15 files changed, 16 insertions(+), 242 deletions(-) diff --git a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/FhirConfigurationIT.java b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/FhirConfigurationIT.java index 4f4a212..e3d0f85 100644 --- a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/FhirConfigurationIT.java +++ b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/FhirConfigurationIT.java @@ -43,7 +43,7 @@ public class FhirConfigurationIT extends AbstractFhirTestSupport { @Override protected CamelContext createCamelContext() throws Exception { - final CamelContext context = new DefaultCamelContext(createRegistry()); + final CamelContext context = new DefaultCamelContext(createCamelRegistry()); // add FhirComponent to Camel context but don't set up componentConfiguration final FhirComponent component = new FhirComponent(context); diff --git a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarConfigurationTest.java b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarConfigurationTest.java index 5ea1e26..ff549d9 100644 --- a/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarConfigurationTest.java +++ b/components/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/CalendarConfigurationTest.java @@ -45,7 +45,7 @@ public class CalendarConfigurationTest extends AbstractGoogleCalendarTestSupport @Override protected CamelContext createCamelContext() throws Exception { - final CamelContext context = new DefaultCamelContext(createRegistry()); + final CamelContext context = new DefaultCamelContext(createCamelRegistry()); // add GoogleCalendarComponent to Camel context but don't set up configuration final GoogleCalendarComponent component = new GoogleCalendarComponent(context); diff --git a/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveConfigurationTest.java b/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveConfigurationTest.java index 70984f5..f2f94fe 100644 --- a/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveConfigurationTest.java +++ b/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveConfigurationTest.java @@ -33,7 +33,7 @@ public class DriveConfigurationTest extends AbstractGoogleDriveTestSupport { @Override protected CamelContext createCamelContext() throws Exception { - final CamelContext context = new DefaultCamelContext(createRegistry()); + final CamelContext context = new DefaultCamelContext(createCamelRegistry()); // add GoogleDriveComponent to Camel context but don't set up configuration final GoogleDriveComponent component = new GoogleDriveComponent(context); diff --git a/components/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/GmailConfigurationTest.java b/components/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/GmailConfigurationTest.java index bb8a98e..4a00e0b 100644 --- a/components/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/GmailConfigurationTest.java +++ b/components/camel-google-mail/src/test/java/org/apache/camel/component/google/mail/GmailConfigurationTest.java @@ -38,7 +38,7 @@ public class GmailConfigurationTest extends AbstractGoogleMailTestSupport { @Override protected CamelContext createCamelContext() throws Exception { - final CamelContext context = new DefaultCamelContext(createRegistry()); + final CamelContext context = new DefaultCamelContext(createCamelRegistry()); // add GoogleMailComponent to Camel context but don't set up configuration final GoogleMailComponent component = new GoogleMailComponent(context); diff --git a/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/SheetsConfigurationTest.java b/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/SheetsConfigurationTest.java index 2275ba1..2fd2c08 100644 --- a/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/SheetsConfigurationTest.java +++ b/components/camel-google-sheets/src/test/java/org/apache/camel/component/google/sheets/SheetsConfigurationTest.java @@ -31,7 +31,7 @@ public class SheetsConfigurationTest extends CamelTestSupport { @Override protected CamelContext createCamelContext() throws Exception { - final CamelContext context = new DefaultCamelContext(createRegistry()); + final CamelContext context = new DefaultCamelContext(createCamelRegistry()); // add GoogleSheetsComponent to Camel context but don't set up configuration final GoogleSheetsComponent component = new GoogleSheetsComponent(context); diff --git a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyRedeliveryTest.java b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyRedeliveryTest.java index 8829d9d..f3e0f66 100644 --- a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyRedeliveryTest.java +++ b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyRedeliveryTest.java @@ -135,7 +135,7 @@ public class NettyRedeliveryTest extends CamelTestSupport { @Override protected CamelContext createCamelContext() throws Exception { // Override the error handler executor service such that we can track the tasks created - CamelContext context = new DefaultCamelContext(createRegistry()) { + CamelContext context = new DefaultCamelContext(createCamelRegistry()) { @Override public ScheduledExecutorService getErrorHandlerExecutorService() { return getScheduledExecutorService(); diff --git a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java index e9252e4..a515576 100644 --- a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java +++ b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.Properties; @@ -42,8 +41,6 @@ import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import javax.management.ReflectionException; -import javax.naming.Context; -import javax.naming.InitialContext; import org.apache.camel.CamelContext; import org.apache.camel.ConsumerTemplate; @@ -72,7 +69,6 @@ import org.apache.camel.builder.AdviceWithRouteBuilder; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.DefaultCamelContext; -import org.apache.camel.impl.JndiRegistry; import org.apache.camel.impl.engine.InterceptSendToMockEndpointStrategy; import org.apache.camel.model.Model; import org.apache.camel.model.ModelCamelContext; @@ -827,22 +823,7 @@ public abstract class CamelTestSupport extends TestSupport { protected CamelContext createCamelContext() throws Exception { // for backwards compatibility - Registry registry = createRegistry(); - if (registry instanceof FakeJndiRegistry) { - boolean inUse = ((FakeJndiRegistry) registry).isInUse(); - if (!inUse) { - registry = null; - } - } - if (registry != null) { - String msg = "createRegistry() from camel-test is deprecated. Use createCamelRegistry if you want to control which registry to use, however" - + " if you need to bind beans to the registry then this is possible already with the bind method on registry," - + " and there is no need to override this method."; - LOG.warn(msg); - } else { - registry = createCamelRegistry(); - } - + Registry registry = createCamelRegistry(); CamelContext context; if (registry != null) { context = new DefaultCamelContext(registry); @@ -870,56 +851,6 @@ public abstract class CamelTestSupport extends TestSupport { } /** - * @deprecated use createCamelRegistry if you want to control which registry to use, however - * if you need to bind beans to the registry then this is possible already with the bind method on registry, - * and there is no need to override this method. - */ - @Deprecated - protected JndiRegistry createRegistry() throws Exception { - return new FakeJndiRegistry(createJndiContext()); - } - - /** - * @deprecated use createCamelRegistry if you want to control which registry to use, however - * if you need to bind beans to the registry then this is possible already with the bind method on registry, - * and there is no need to use JndiRegistry and override this method. - */ - @Deprecated - protected Context createJndiContext() throws Exception { - Properties properties = new Properties(); - - // jndi.properties is optional - InputStream in = getClass().getClassLoader().getResourceAsStream("jndi.properties"); - if (in != null) { - LOG.debug("Using jndi.properties from classpath root"); - properties.load(in); - } else { - properties.put("java.naming.factory.initial", "org.apache.camel.support.jndi.CamelInitialContextFactory"); - } - return new InitialContext(new Hashtable<>(properties)); - } - - private class FakeJndiRegistry extends JndiRegistry { - - private boolean inUse; - - public FakeJndiRegistry(Context context) { - super(context); - } - - @Override - public void bind(String name, Object object) { - super.bind(name, object); - inUse = true; - } - - public boolean isInUse() { - // only if the end user bind beans then its in use - return inUse; - } - } - - /** * Factory method which derived classes can use to create a {@link RouteBuilder} * to define the routes for testing */ diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java index 5edb552..6fc27c8 100644 --- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java +++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java @@ -18,8 +18,6 @@ package org.apache.camel.impl; import java.util.Map; -import javax.naming.Context; - import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; import org.apache.camel.TypeConverter; @@ -129,19 +127,6 @@ public class DefaultCamelContext extends AbstractModelCamelContext { } /** - * Creates the {@link CamelContext} using the given JNDI context as the - * registry - * - * @param jndiContext the JNDI context - * @deprecated create a new {@link JndiRegistry} and use the constructor - * that accepts this registry. - */ - @Deprecated - public DefaultCamelContext(Context jndiContext) { - this(new JndiRegistry(jndiContext)); - } - - /** * Creates the {@link CamelContext} using the given registry * * @param registry the registry diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/JndiRegistry.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/JndiRegistry.java deleted file mode 100644 index d79965b..0000000 --- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/JndiRegistry.java +++ /dev/null @@ -1,61 +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 - * - * http://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.camel.impl; - -import java.util.Map; - -import javax.naming.Context; -import javax.naming.NamingException; - -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.spi.Registry; -import org.apache.camel.support.jndi.JndiBeanRepository; - -/** - * A {@link Registry} implementation which looks up the objects in JNDI - * - * @deprecated use {@link JndiBeanRepository} instead. - */ -@Deprecated -public class JndiRegistry extends JndiBeanRepository implements Registry { - - public JndiRegistry() { - } - - public JndiRegistry(Map environment) { - super(environment); - } - - public JndiRegistry(Context context) { - super(context); - } - - public JndiRegistry(boolean standalone) { - super(standalone); - } - - @Override - public void bind(String id, Class<?> type, Object bean) throws RuntimeCamelException { - try { - Object object = wrap(bean); - getContext().bind(id, object); - } catch (NamingException e) { - throw new RuntimeCamelException(e); - } - } - -} diff --git a/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanLookupUsingJndiRegistryIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanLookupUsingJndiRegistryIssueTest.java index 799b8c1..30627bc 100644 --- a/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanLookupUsingJndiRegistryIssueTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanLookupUsingJndiRegistryIssueTest.java @@ -19,6 +19,8 @@ package org.apache.camel.component.bean; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.support.DefaultRegistry; +import org.apache.camel.support.jndi.JndiBeanRepository; import org.apache.camel.support.jndi.JndiContext; import org.junit.Assert; import org.junit.Test; @@ -30,7 +32,7 @@ public class BeanLookupUsingJndiRegistryIssueTest extends Assert { JndiContext jndi = new JndiContext(); jndi.bind("foo", new MyOtherDummyBean()); - CamelContext camel = new DefaultCamelContext(jndi); + CamelContext camel = new DefaultCamelContext(new DefaultRegistry(new JndiBeanRepository(jndi))); camel.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/GetRegistryAsTypeTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/GetRegistryAsTypeTest.java index 7bfc37e..1b5f969 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/GetRegistryAsTypeTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/GetRegistryAsTypeTest.java @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.camel.CamelContext; import org.apache.camel.support.DefaultRegistry; import org.apache.camel.support.SimpleRegistry; +import org.apache.camel.support.jndi.JndiBeanRepository; import org.junit.Assert; import org.junit.Test; @@ -35,7 +36,7 @@ public class GetRegistryAsTypeTest extends Assert { assertNotNull(context.getRegistry()); assertNull(context.getRegistry(Map.class)); - assertNull(context.getRegistry(JndiRegistry.class)); + assertNull(context.getRegistry(JndiBeanRepository.class)); assertNull(context.getRegistry(SimpleRegistry.class)); context.stop(); @@ -51,7 +52,7 @@ public class GetRegistryAsTypeTest extends Assert { // simple extends Map assertNotNull(context.getRegistry(Map.class)); - assertNull(context.getRegistry(JndiRegistry.class)); + assertNull(context.getRegistry(JndiBeanRepository.class)); context.stop(); } diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/JndiRegistryTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/JndiRegistryTest.java deleted file mode 100644 index 4c995ad..0000000 --- a/core/camel-core/src/test/java/org/apache/camel/impl/JndiRegistryTest.java +++ /dev/null @@ -1,81 +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 - * - * http://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.camel.impl; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.camel.NoSuchBeanException; -import org.apache.camel.language.simple.SimpleLanguage; -import org.apache.camel.spi.Language; -import org.apache.camel.support.jndi.JndiTest; -import org.junit.Assert; -import org.junit.Test; - -@SuppressWarnings("deprecation") -public class JndiRegistryTest extends Assert { - - @Test - public void testLookupByType() throws Exception { - JndiRegistry jndi = new JndiRegistry(JndiTest.createInitialContext()); - jndi.bind("foo", new SimpleLanguage()); - jndi.bind("bar", "Hello bar"); - - assertEquals("Hello bar", jndi.lookupByName("bar")); - assertEquals("Hello bar", jndi.lookupByName("bar")); - assertEquals("Hello bar", jndi.lookupByNameAndType("bar", String.class)); - assertNull(jndi.lookupByName("unknown")); - assertNull(jndi.lookupByName("unknown")); - - try { - assertNull(jndi.lookupByNameAndType("bar", Language.class)); - fail("Should throw exception"); - } catch (NoSuchBeanException e) { - // expected - } - - assertNotNull(jndi.lookupByNameAndType("foo", Language.class)); - assertNotNull(jndi.lookupByNameAndType("foo", SimpleLanguage.class)); - assertSame(jndi.lookupByNameAndType("foo", Language.class), jndi.lookupByNameAndType("foo", SimpleLanguage.class)); - - Map<String, ?> set = jndi.findByTypeWithName(Language.class); - assertNotNull(set); - assertEquals(1, set.size()); - - String key = set.keySet().iterator().next(); - assertEquals("foo", key); - assertSame(jndi.lookupByName("foo"), set.values().iterator().next()); - } - - @Test - public void testStandalone() throws Exception { - JndiRegistry jndi = new JndiRegistry(true); - jndi.bind("bar", "Hello bar"); - assertEquals("Hello bar", jndi.lookupByName("bar")); - } - - @Test - public void testCamelContextFactory() throws Exception { - Map<Object, Object> env = new HashMap<>(); - env.put("java.naming.factory.initial", "org.apache.camel.support.jndi.CamelInitialContextFactory"); - - JndiRegistry jndi = new JndiRegistry(env); - jndi.bind("bar", "Hello bar"); - assertEquals("Hello bar", jndi.lookupByName("bar")); - } - -} diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyFailOnStartupTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyFailOnStartupTest.java index bdd6c4a..8a73d24 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyFailOnStartupTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyFailOnStartupTest.java @@ -19,7 +19,6 @@ package org.apache.camel.impl; import org.apache.camel.CamelContext; import org.apache.camel.TestSupport; import org.apache.camel.VetoCamelContextStartException; -import org.apache.camel.support.jndi.JndiContext; import org.junit.Test; public class LifecycleStrategyFailOnStartupTest extends TestSupport { @@ -27,7 +26,7 @@ public class LifecycleStrategyFailOnStartupTest extends TestSupport { private MyLifecycleStrategy dummy1 = new MyLifecycleStrategy(); protected CamelContext createCamelContext() throws Exception { - CamelContext context = new DefaultCamelContext(new JndiContext()); + CamelContext context = new DefaultCamelContext(); context.addLifecycleStrategy(dummy1); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyServiceTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyServiceTest.java index 2cc0072..9625c9f 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyServiceTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/LifecycleStrategyServiceTest.java @@ -19,7 +19,6 @@ package org.apache.camel.impl; import org.apache.camel.CamelContext; import org.apache.camel.Service; import org.apache.camel.TestSupport; -import org.apache.camel.support.jndi.JndiContext; import org.junit.Test; public class LifecycleStrategyServiceTest extends TestSupport { @@ -27,7 +26,7 @@ public class LifecycleStrategyServiceTest extends TestSupport { private MyLifecycleStrategy dummy1 = new MyLifecycleStrategy(); protected CamelContext createCamelContext() throws Exception { - CamelContext context = new DefaultCamelContext(new JndiContext()); + CamelContext context = new DefaultCamelContext(); context.addLifecycleStrategy(dummy1); return context; } diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java index b636e2e..7a34a4c 100644 --- a/core/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java +++ b/core/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java @@ -23,7 +23,6 @@ import org.apache.camel.CamelContext; import org.apache.camel.Component; import org.apache.camel.TestSupport; import org.apache.camel.component.log.LogComponent; -import org.apache.camel.support.jndi.JndiContext; import org.junit.Test; public class MultipleLifecycleStrategyTest extends TestSupport { @@ -32,7 +31,7 @@ public class MultipleLifecycleStrategyTest extends TestSupport { private DummyLifecycleStrategy dummy2 = new DummyLifecycleStrategy(); protected CamelContext createCamelContext() throws Exception { - CamelContext context = new DefaultCamelContext(new JndiContext()); + CamelContext context = new DefaultCamelContext(); context.addLifecycleStrategy(dummy1); context.addLifecycleStrategy(dummy2); return context;