You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/02/10 17:52:41 UTC

svn commit: r1444563 - in /camel/trunk/components/camel-spring/src: main/java/org/apache/camel/spring/spi/ test/java/org/apache/camel/spring/spi/ test/resources/org/apache/camel/spring/spi/

Author: davsclaus
Date: Sun Feb 10 16:52:40 2013
New Revision: 1444563

URL: http://svn.apache.org/r1444563
Log:
CAMEL-6057: camel-spring now lookup in ancestor application contexts when using the Registry. Thanks to Vitalii Tymchyshyn for the patch.

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/spi/
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/spi/ParentContextRegistryTest.java   (with props)
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestChild.xml   (with props)
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestParent.xml   (with props)
Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/ApplicationContextRegistry.java

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/ApplicationContextRegistry.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/ApplicationContextRegistry.java?rev=1444563&r1=1444562&r2=1444563&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/ApplicationContextRegistry.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/ApplicationContextRegistry.java Sun Feb 10 16:52:40 2013
@@ -22,6 +22,7 @@ import java.util.Set;
 
 import org.apache.camel.NoSuchBeanException;
 import org.apache.camel.spi.Registry;
+import org.springframework.beans.factory.BeanFactoryUtils;
 import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 import org.springframework.context.ApplicationContext;
@@ -75,13 +76,13 @@ public class ApplicationContextRegistry 
 
     @Override
     public <T> Set<T> findByType(Class<T> type) {
-        Map<String, T> map = applicationContext.getBeansOfType(type);
+        Map<String, T> map = findByTypeWithName(type);
         return new HashSet<T>(map.values());
     }
 
     @Override
     public <T> Map<String, T> findByTypeWithName(Class<T> type) {
-        return applicationContext.getBeansOfType(type);
+        return BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, type);
     }
 
     @Override

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/spi/ParentContextRegistryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/spi/ParentContextRegistryTest.java?rev=1444563&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/spi/ParentContextRegistryTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/spi/ParentContextRegistryTest.java Sun Feb 10 16:52:40 2013
@@ -0,0 +1,55 @@
+/**
+ * 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.spring.spi;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class ParentContextRegistryTest extends SpringTestSupport {
+    private static final List<String> EXPECTED_BEAN = Collections.singletonList("TestValue");
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        ClassPathXmlApplicationContext parentContext = new ClassPathXmlApplicationContext(
+                "parentContextRegistryTestParent.xml", ParentContextRegistryTest.class);
+        return new ClassPathXmlApplicationContext(
+                new String[]{"parentContextRegistryTestChild.xml"},
+                ParentContextRegistryTest.class, parentContext
+        );
+    }
+
+    public void testLookupByName() {
+        assertEquals(EXPECTED_BEAN, context.getRegistry().lookupByName("testParentBean"));
+    }
+
+    public void testLookupByNameAndType() {
+        assertEquals(EXPECTED_BEAN, context.getRegistry().lookupByNameAndType("testParentBean", List.class));
+    }
+
+    public void testFindByType() {
+        assertEquals(Collections.singleton(EXPECTED_BEAN), context.getRegistry().findByType(List.class));
+    }
+
+    public void testFindByTypeWithName() {
+        assertEquals(Collections.singletonMap("testParentBean", EXPECTED_BEAN),
+                context.getRegistry().findByTypeWithName(List.class));
+    }
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/spi/ParentContextRegistryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/spi/ParentContextRegistryTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestChild.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestChild.xml?rev=1444563&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestChild.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestChild.xml Sun Feb 10 16:52:40 2013
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+    <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring"/>
+</beans>
\ No newline at end of file

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestChild.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestChild.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestChild.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestParent.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestParent.xml?rev=1444563&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestParent.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestParent.xml Sun Feb 10 16:52:40 2013
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
+       ">
+    <util:list id="testParentBean">
+        <value>TestValue</value>
+    </util:list>
+</beans>
\ No newline at end of file

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestParent.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestParent.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/spi/parentContextRegistryTestParent.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml