activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r521410 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-spring/src/main/java/org/apache/camel/spring/ camel-spring/src/test/java/org/apache/camel/spring/ camel-spr...
Date Thu, 22 Mar 2007 19:19:22 GMT
Author: chirino
Date: Thu Mar 22 12:19:21 2007
New Revision: 521410

URL: http://svn.apache.org/viewvc?view=rev&rev=521410
Log:
Some small tweaks to CamelContextFactoryBeanTest

Added:
    activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java
      - copied, changed from r521400, activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringClassPathRouteLoaderTest.java
    activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/camel_context_factory_bean_test.xml
      - copied, changed from r521400, activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/findRouteBuildersOnClassPath.xml
Removed:
    activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringClassPathRouteLoaderTest.java
    activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/findRouteBuildersOnClassPath.xml
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?view=diff&rev=521410&r1=521409&r2=521410
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Thu Mar
22 12:19:21 2007
@@ -80,10 +80,12 @@
 	public Map<Endpoint, Processor> getRoutes() ;
 	
 	public void setRoutes(Map<Endpoint, Processor> routes);
-	
     public void setRoutes(RouteBuilder builder);
+    public void setRoutes(RouteFactory factory);
 
-    public void setRoutes(final RouteFactory factory);
+	public void addRoutes(Map<Endpoint, Processor> routes);
+    public void addRoutes(RouteBuilder builder);
+    public void addRoutes(RouteFactory factory);
 
     // Properties
     //-----------------------------------------------------------------------

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=521410&r1=521409&r2=521410
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Thu Mar 22 12:19:21 2007
@@ -17,13 +17,22 @@
  */
 package org.apache.camel.impl;
 
-import org.apache.camel.*;
-import org.apache.camel.builder.RouteBuilder;
-
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.concurrent.Callable;
 
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointResolver;
+import org.apache.camel.ExchangeConverter;
+import org.apache.camel.Processor;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.RouteFactory;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.builder.RouteBuilder;
+
 /**
  * Represents the context used to configure routes and the policies to use.
  *
@@ -155,6 +164,29 @@
             }
         };
         setRoutes(builder);
+    }
+
+    public void addRoutes(Map<Endpoint, Processor> routes) {
+    	if( this.routes == null ) {
+    		this.routes = new LinkedHashMap<Endpoint, Processor>(routes);
+    	} else {
+    		this.routes.putAll(routes);
+    	}
+    }
+
+    public void addRoutes(RouteBuilder builder) {
+        // lets now add the routes from the builder
+        builder.setContext(this);
+        addRoutes(builder.getRouteMap());
+    }
+
+    public void addRoutes(final RouteFactory factory) {
+        RouteBuilder builder = new RouteBuilder(this) {
+            public void configure() {
+                factory.build(this);
+            }
+        };
+        addRoutes(builder);
     }
 
     // Properties

Modified: activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?view=diff&rev=521410&r1=521409&r2=521410
==============================================================================
--- activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++ activemq/camel/trunk/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Thu Mar 22 12:19:21 2007
@@ -38,7 +38,8 @@
 public class CamelContextFactoryBean implements FactoryBean, InitializingBean, DisposableBean,
ApplicationContextAware {
     private CamelContext context;
     private boolean singleton = true;
-    private List<RouteBuilder> routeBuilders = new ArrayList<RouteBuilder>();
+    private RouteBuilder routeBuilder;
+    private List<RouteBuilder> additionalBuilders = new ArrayList<RouteBuilder>();
     private String[] packages = {};
     private ApplicationContext applicationContext;
 
@@ -83,18 +84,13 @@
         this.context = context;
     }
 
-    public List<RouteBuilder> getRouteBuilders() {
-        return routeBuilders;
-    }
-
-    /**
-     * Sets the {@link RouteBuilder} instances to be installed in this context
-     *
-     * @param routeBuilders the route builders to activate on startup
-     */
-    public void setRouteBuilders(List<RouteBuilder> routeBuilders) {
-        this.routeBuilders = routeBuilders;
-    }
+	public RouteBuilder getRouteBuilder() {
+		return routeBuilder;
+	}
+
+	public void setRouteBuilder(RouteBuilder routeBuilder) {
+		this.routeBuilder = routeBuilder;
+	}
 
     public ApplicationContext getApplicationContext() {
         return applicationContext;
@@ -120,9 +116,11 @@
      * Strategy to install all available routes into the context
      */
     protected void installRoutes() {
-        for (RouteBuilder routeBuilder : routeBuilders) {
-            getContext().setRoutes(routeBuilder);
+        for (RouteBuilder routeBuilder : additionalBuilders) {
+            getContext().addRoutes(routeBuilder);
         }
+        if( routeBuilder!=null )
+        	getContext().addRoutes(routeBuilder);
     }
 
     /**
@@ -131,7 +129,7 @@
     protected void findRouteBuiders() throws IllegalAccessException, InstantiationException
{
         if (packages != null && packages.length > 0) {
             RouteBuilderFinder finder = new RouteBuilderFinder(this);
-            finder.appendBuilders(getRouteBuilders());
+            finder.appendBuilders(additionalBuilders);
         }
     }
 }

Copied: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java
(from r521400, activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringClassPathRouteLoaderTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java?view=diff&rev=521410&p1=activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringClassPathRouteLoaderTest.java&r1=521400&p2=activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java&r2=521410
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/SpringClassPathRouteLoaderTest.java
(original)
+++ activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/CamelContextFactoryBeanTest.java
Thu Mar 22 12:19:21 2007
@@ -17,27 +17,26 @@
  */
 package org.apache.camel.spring;
 
-import junit.framework.TestCase;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-import org.springframework.context.ApplicationContext;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Processor;
 import org.apache.camel.TestSupport;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
-import java.util.Map;
-import java.util.Set;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
  * @version $Revision$
  */
-public class SpringClassPathRouteLoaderTest extends TestSupport {
-    private static final transient Log log = LogFactory.getLog(SpringClassPathRouteLoaderTest.class);
+public class CamelContextFactoryBeanTest extends TestSupport {
+    private static final transient Log log = LogFactory.getLog(CamelContextFactoryBeanTest.class);
     
-    public void testLoadingRouteBuildresOnTheClassPathViaSpringXml() throws Exception {
-        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/findRouteBuildersOnClassPath.xml");
+    public void testClassPathRouteLoading() throws Exception {
+        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/camel_context_factory_bean_test.xml");
 
         CamelContext context = (CamelContext) applicationContext.getBean("camel");
         assertNotNull("No context found!", context);
@@ -55,4 +54,24 @@
             assertEndpointUri(key, "queue:test.a");
         }
     }
+    
+    public void testXMLRouteLoading() throws Exception {
+        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/camel_context_factory_bean_test.xml");
+
+        CamelContext context = (CamelContext) applicationContext.getBean("camel2");
+        assertNotNull("No context found!", context);
+
+        Map<Endpoint,Processor> map = context.getRoutes();
+        log.debug("Found routes: " + map);
+
+        Set<Map.Entry<Endpoint,Processor>> entries = map.entrySet();
+        assertEquals("One Route should be found", 1, entries.size());
+
+        for (Map.Entry<Endpoint, Processor> entry : entries) {
+            Endpoint key = entry.getKey();
+            Processor processor = entry.getValue();
+            assertEndpointUri(key, "queue:test.c");
+        }
+    }
+
 }

Copied: activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/camel_context_factory_bean_test.xml
(from r521400, activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/findRouteBuildersOnClassPath.xml)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/camel_context_factory_bean_test.xml?view=diff&rev=521410&p1=activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/findRouteBuildersOnClassPath.xml&r1=521400&p2=activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/camel_context_factory_bean_test.xml&r2=521410
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/findRouteBuildersOnClassPath.xml
(original)
+++ activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/camel_context_factory_bean_test.xml
Thu Mar 22 12:19:21 2007
@@ -17,11 +17,28 @@
 -->
 <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-2.0.xsd">
+    xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+       http://activemq.apache.org/camel/schema/camel-1.0.xsd http://activemq.apache.org/camel/schema/camel-1.0.xsd
+    ">
 
   <!-- START SNIPPET: example -->
   <bean id="camel" class="org.apache.camel.spring.CamelContextFactoryBean">
     <property name="packages" value="org.apache.camel.spring.example"/>
   </bean>
   <!-- END SNIPPET: example -->
+  
+  <!-- START SNIPPET: example2 -->
+  <bean id="camel2" class="org.apache.camel.spring.CamelContextFactoryBean">
+    <property name="routeBuilder">
+	    <routeBuilder xmlns="http://activemq.apache.org/camel/schema/camel-1.0.xsd">
+	       <route>
+	         <from uri="queue:test.c"/>
+	         <to uri="queue:test.d"/>
+	       </route>
+	    </routeBuilder>
+    </property>
+  </bean>
+  <!-- END SNIPPET: example2 -->
+  
 </beans>



Mime
View raw message