You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/08/17 06:41:50 UTC
svn commit: r566917 - in /activemq/camel/trunk/components/camel-spring/src:
main/java/org/apache/camel/spring/CamelContextFactoryBean.java
test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java
Author: jstrachan
Date: Thu Aug 16 21:41:49 2007
New Revision: 566917
URL: http://svn.apache.org/viewvc?view=rev&rev=566917
Log:
added test case for CAMEL-103 along with better exception messages if refresh() is not called on a GenericApplicationContext - or the AppContext is not properly injected into the factory bean
Modified:
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java
Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?view=diff&rev=566917&r1=566916&r2=566917
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Thu Aug 16 21:41:49 2007
@@ -91,9 +91,9 @@
getContext().addRouteDefinitions(routes);
LOG.debug("Found JAXB created routes: " + getRoutes());
- String[] names = applicationContext.getBeanNamesForType(SpringInstrumentationAgent.class);
+ String[] names = getApplicationContext().getBeanNamesForType(SpringInstrumentationAgent.class);
if (names.length == 1) {
- applicationContext.getBean(names[0], SpringInstrumentationAgent.class);
+ getApplicationContext().getBean(names[0], SpringInstrumentationAgent.class);
}
findRouteBuiders();
@@ -168,6 +168,9 @@
}
public ApplicationContext getApplicationContext() {
+ if (applicationContext == null) {
+ throw new IllegalArgumentException("No applicationContext has been injected!");
+ }
return applicationContext;
}
Modified: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java?view=diff&rev=566917&r1=566916&r2=566917
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java Thu Aug 16 21:41:49 2007
@@ -16,8 +16,6 @@
*/
package org.apache.camel.spring;
-import java.util.List;
-
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Processor;
@@ -26,9 +24,13 @@
import org.apache.camel.impl.EventDrivenConsumerRoute;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+
+import java.util.List;
/**
* @version $Revision$
@@ -46,6 +48,18 @@
public void testClassPathRouteLoadingUsingNamespaces() throws Exception {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/camelContextFactoryBean.xml");
+ CamelContext context = (CamelContext) applicationContext.getBean("camel3");
+ assertValidContext(context);
+ }
+
+ public void testGenericApplicationContextUsingNamespaces() throws Exception {
+ GenericApplicationContext applicationContext = new GenericApplicationContext();
+ XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext);
+ xmlReader.loadBeanDefinitions(new ClassPathResource("org/apache/camel/spring/camelContextFactoryBean.xml"));
+
+ // lets refresh to inject the applicationContext into beans
+ applicationContext.refresh();
+
CamelContext context = (CamelContext) applicationContext.getBean("camel3");
assertValidContext(context);
}