svn commit: r565884 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/model/language/ came...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r565884 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/model/language/ came...

jstrachan-2
Author: jstrachan
Date: Tue Aug 14 12:47:31 2007
New Revision: 565884

URL: http://svn.apache.org/viewvc?view=rev&rev=565884
Log:
initial attempt at CAMEL-12; creating a DOT file for the route definitions. Also a minor refactor of the CamelContext implementations to add a way to registry route definitions along with a getter to view the route definitions

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/view/
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java
      - copied, changed from r565311, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java
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/builder/RouteBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/ExpressionType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java
    activemq/camel/trunk/components/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=565884&r1=565883&r2=565884
==============================================================================
--- 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 Tue Aug 14 12:47:31 2007
@@ -25,6 +25,7 @@
 import org.apache.camel.spi.Injector;
 import org.apache.camel.spi.Language;
 import org.apache.camel.spi.Registry;
+import org.apache.camel.model.RouteType;
 
 /**
  * Interface used to represent the context used to configure routes and the
@@ -118,6 +119,11 @@
     //-----------------------------------------------------------------------
 
     /**
+     * Returns a list of the current route definitions
+     */
+    List<RouteType> getRouteDefinitions();
+
+    /**
      * Returns the current routes in this context
      *
      * @return the current routes in this context
@@ -147,6 +153,12 @@
      */
     void addRoutes(RouteBuilder builder) throws Exception;
 
+    /**
+     * Adds a collection of route definitions to the context
+     */
+    void addRouteDefinitions(Collection<RouteType> routeDefinitions) throws Exception;
+
+    
     // Properties
     //-----------------------------------------------------------------------
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java?view=diff&rev=565884&r1=565883&r2=565884
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java Tue Aug 14 12:47:31 2007
@@ -165,7 +165,8 @@
             throw new IllegalArgumentException("No CamelContext has been injected!");
         }
         routeCollection.setCamelContext(camelContext);
-        routeCollection.populateRoutes(routes);
+        //routeCollection.populateRoutes(routes);
+        camelContext.addRouteDefinitions(routeCollection.getRoutes());
     }
 
     /**

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=565884&r1=565883&r2=565884
==============================================================================
--- 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 Tue Aug 14 12:47:31 2007
@@ -37,6 +37,7 @@
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.Service;
 import org.apache.camel.TypeConverter;
+import org.apache.camel.model.RouteType;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.converter.DefaultTypeConverter;
 import org.apache.camel.spi.ComponentResolver;
@@ -56,7 +57,6 @@
  * Represents the context used to configure routes and the policies to use.
  *
  * @version $Revision: 520517 $
- * @org.apache.xbean.XBean element="container" rootElement="true"
  */
 public class DefaultCamelContext extends ServiceSupport implements CamelContext, Service {
     private Map<String, Endpoint> endpoints = new HashMap<String, Endpoint>();
@@ -71,6 +71,7 @@
     private LanguageResolver languageResolver = new DefaultLanguageResolver();
     private Registry registry;
  private LifecycleStrategy lifecycleStrategy = new DefaultLifecycleStrategy();
+    private List<RouteType> routeDefinitions = new ArrayList<RouteType>();
 
     public DefaultCamelContext() {
     }
@@ -282,7 +283,7 @@
             this.routes.addAll(routes);
         }
         lifecycleStrategy.onRoutesAdd(routes);
-        if (isStarted()) {
+        if (shouldStartRoutes()) {
             startRoutes(routes);
         }
     }
@@ -293,6 +294,15 @@
         addRoutes(builder.getRouteList());
     }
 
+    public void addRouteDefinitions(Collection<RouteType> routeDefinitions) throws Exception {
+        this.routeDefinitions.addAll(routeDefinitions);
+        if (shouldStartRoutes()) {
+        startRouteDefinitions(routeDefinitions);
+        }
+
+    }
+
+
     // Helper methods
     // -----------------------------------------------------------------------
 
@@ -384,6 +394,11 @@
         this.lifecycleStrategy = lifecycleStrategy;
     }
 
+    public List<RouteType> getRouteDefinitions() {
+        return routeDefinitions;
+    }
+
+
     // Implementation methods
     // -----------------------------------------------------------------------
 
@@ -394,9 +409,18 @@
                 startServices(component);
             }
         }
+        startRouteDefinitions(routeDefinitions);
         startRoutes(routes);
     }
 
+    protected void startRouteDefinitions(Collection<RouteType> list) throws Exception {
+        if (list != null) {
+            for (RouteType route : list) {
+                route.addRoutes(this);
+            }
+        }
+    }
+
     protected void doStop() throws Exception {
         stopServices(servicesToClose);
         if (components != null) {
@@ -508,6 +532,13 @@
     protected Endpoint convertBeanToEndpoint(String uri, Object bean) {
         throw new IllegalArgumentException("uri: " + uri + " bean: " + bean
                                            + " could not be converted to an Endpoint");
+    }
+
+    /**
+     * Should we start newly added routes?
+     */
+    protected boolean shouldStartRoutes() {
+        return isStarted() && !isStarting();
     }
 
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java?view=diff&rev=565884&r1=565883&r2=565884
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ServiceSupport.java Tue Aug 14 12:47:31 2007
@@ -36,16 +36,23 @@
 public abstract class ServiceSupport implements Service {
     private static int threadCounter;
     private AtomicBoolean started = new AtomicBoolean(false);
+    private AtomicBoolean starting = new AtomicBoolean(false);
     private AtomicBoolean stopping = new AtomicBoolean(false);
     private AtomicBoolean stopped = new AtomicBoolean(false);
     private Collection childServices;
 
     public void start() throws Exception {
         if (started.compareAndSet(false, true)) {
-            if (childServices != null) {
-                ServiceHelper.startServices(childServices);
+            starting.set(true);
+            try {
+                if (childServices != null) {
+                    ServiceHelper.startServices(childServices);
+                }
+                doStart();
+            }
+            finally {
+                starting.set(false);
             }
-            doStart();
         }
     }
 
@@ -70,6 +77,13 @@
      */
     public boolean isStarted() {
         return started.get();
+    }
+
+    /**
+     * @return true if this service is
+     */
+    public boolean isStarting() {
+        return starting.get();
     }
 
     /**

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/ExpressionType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/ExpressionType.java?view=diff&rev=565884&r1=565883&r2=565884
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/ExpressionType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/language/ExpressionType.java Tue Aug 14 12:47:31 2007
@@ -121,4 +121,8 @@
     public void setId(String value) {
         this.id = value;
     }
+
+    public Predicate getPredicate() {
+        return predicate;
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java?view=diff&rev=565884&r1=565883&r2=565884
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java Tue Aug 14 12:47:31 2007
@@ -16,28 +16,36 @@
  */
 package org.apache.camel.view;
 
+import org.apache.camel.CamelContext;
+import org.apache.camel.Predicate;
+import org.apache.camel.model.FilterType;
+import org.apache.camel.model.FromType;
+import org.apache.camel.model.ProcessorType;
+import org.apache.camel.model.RouteType;
+import org.apache.camel.model.ToType;
+import org.apache.camel.model.language.ExpressionType;
+import org.apache.camel.util.ObjectHelper;
+import static org.apache.camel.util.ObjectHelper.isNullOrBlank;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.HashMap;
 import java.util.List;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Processor;
-import org.apache.camel.Route;
-import org.apache.camel.impl.EventDrivenConsumerRoute;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import java.util.Map;
 
 /**
  * A <a href="http://www.graphviz.org/">DOT</a> file creator plugin which
  * creates a DOT file showing the current routes
- *
+ *
  * @version $Revision: 523881 $
  */
 public class RouteDotGenerator {
     private static final transient Log LOG = LogFactory.getLog(RouteDotGenerator.class);
     private String file = "CamelRoutes.dot";
+    private Map<Object, String> idMap = new HashMap<Object, String>();
 
     public String getFile() {
         return file;
@@ -52,32 +60,157 @@
 
     public void drawRoutes(CamelContext context) throws IOException {
         PrintWriter writer = new PrintWriter(new FileWriter(file));
-        generateFile(writer, context);
+        try {
+            generateFile(writer, context);
+        }
+        finally {
+            writer.close();
+        }
     }
 
     protected void generateFile(PrintWriter writer, CamelContext context) {
         writer.println("digraph \"Camel Routes\" {");
         writer.println();
-        writer.println("label=\"Camel Container: " + context + "\"];");
+        /*writer.println("label=\"Camel Context: " + context + "\"];");
         writer.println();
+        */
         writer.println("node [style = \"rounded,filled\", fillcolor = yellow, "
-                       + "fontname=\"Helvetica-Oblique\"];");
+                + "fontname=\"Helvetica-Oblique\"];");
+        writer.println();
+        printRoutes(writer, context.getRouteDefinitions());
+
+        writer.println("}");
+    }
+
+    protected void printRoutes(PrintWriter writer, List<RouteType> routes) {
+        for (RouteType route : routes) {
+            List<FromType> inputs = route.getInputs();
+            for (FromType input : inputs) {
+                printRoute(writer, route, input);
+            }
+            writer.println();
+        }
+    }
+
+    protected void printRoute(PrintWriter writer, RouteType route, FromType input) {
+        String ref = input.getRef();
+        if (isNullOrBlank(ref)) {
+            ref = input.getUri();
+        }
+        String fromID = getID(ref);
+
+        writer.println();
+        writer.print(fromID);
+        writer.println(" [");
+        writer.println("label = \"" + ref + "\"");
+        writer.println("];");
+        writer.println();
+
+        List<ProcessorType> outputs = route.getOutputs();
+        for (ProcessorType output : outputs) {
+            printNode(writer, fromID, output);
+        }
+
+/*
+        writer.print(r);
+        writer.print(" -> ");
+        if (r instanceof EventDrivenConsumerRoute) {
+            EventDrivenConsumerRoute consumerRoute = (EventDrivenConsumerRoute)r;
+            Processor p = consumerRoute.getProcessor();
+            writer.println(p);
+        }
+*/
+    }
+
+    protected String printNode(PrintWriter writer, String fromID, ProcessorType node) {
+        String toID = getID(node);
+
         writer.println();
-        printRoutes(writer, context.getRoutes());
+        writer.print(toID);
+        writer.println(" [");
+        printNodeAttributes(writer, node, fromID);
+        writer.println("];");
+        writer.println();
+
+        writer.print(fromID);
+        writer.print(" -> ");
+        writer.print(toID);
+        writer.println(" [");
+        // TODO customize the line!
+        writer.println("];");
+
+        // now lets write any children
+        List<ProcessorType> outputs = node.getOutputs();
+        for (ProcessorType output : outputs) {
+            printNode(writer, toID, output);
+        }
+        return toID;
     }
 
-    protected void printRoutes(PrintWriter writer, List<Route> routes) {
-        for (Route r : routes) {
-            Endpoint end = r.getEndpoint();
-            writer.print(end.getEndpointUri());
-            writer.print(" -> ");
-            writer.print(r);
-            writer.print(" -> ");
-            if (r instanceof EventDrivenConsumerRoute) {
-                EventDrivenConsumerRoute consumerRoute = (EventDrivenConsumerRoute)r;
-                Processor p = consumerRoute.getProcessor();
-                writer.println(p);
+    protected class NodeData {
+        public String image;
+        public String label;
+    }
+
+    protected void printNodeAttributes(PrintWriter writer, ProcessorType node, String id) {
+        NodeData nodeData = new NodeData();
+        configureNodeData(node, nodeData);
+
+        String label = nodeData.label;
+        if (label == null) {
+            label = node.toString();
+        }
+        writer.println("label = \"" + label + "\"");
+
+        String image = nodeData.image;
+        if (image != null) {
+            writer.println("shapefile = \"" + image + "\"");
+            writer.println("shape = custom");
+        }
+    }
+
+    protected void configureNodeData(ProcessorType node, NodeData nodeData) {
+        if (node instanceof FilterType) {
+            FilterType filterType = (FilterType) node;
+            nodeData.image = "http://www.enterpriseintegrationpatterns.com/img/MessageFilterIcon.gif";
+            nodeData.label = getLabel(filterType.getExpression());
+        }
+        else if (node instanceof ToType) {
+            ToType toType = (ToType) node;
+            String ref = toType.getRef();
+            if (isNullOrBlank(ref)) {
+                ref = toType.getUri();
+            }
+            nodeData.label = ref;
+        }
+    }
+
+    protected String getLabel(ExpressionType expression) {
+        if (expression != null) {
+            String language = expression.getExpression();
+            if (ObjectHelper.isNullOrBlank(language)) {
+                Predicate predicate = expression.getPredicate();
+                if (predicate != null) {
+                    return predicate.toString();
+                }
             }
+            else {
+                return language;
+            }
+        }
+        return "";
+    }
+
+    protected String getImageUrl(ProcessorType node) {
+        return null;
+    }
+
+    protected String getID(Object node) {
+        String answer = idMap.get(node);
+        if (answer == null) {
+            answer = "node" + (idMap.size() + 1);
+            idMap.put(node, answer);
         }
+        return answer;
     }
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java?view=diff&rev=565884&r1=565883&r2=565884
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java Tue Aug 14 12:47:31 2007
@@ -22,7 +22,9 @@
 
 import org.apache.camel.builder.Builder;
 import org.apache.camel.builder.ValueBuilder;
+import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -224,5 +226,17 @@
     protected <T> List<T> assertListSize(List<T> list, int size) {
         assertEquals("List should be of size: " + size + " but is: " + list, size, list.size());
         return list;
+    }
+
+    /**
+     * A helper method to create a list of Route objects for a given route builder
+     */
+    protected List<Route> getRouteList(RouteBuilder builder) throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        context.addRoutes(builder);
+        context.start();
+        List<Route> answer = context.getRoutes();
+        context.stop();
+        return answer;
     }
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java?view=diff&rev=565884&r1=565883&r2=565884
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/ErrorHandlerTest.java Tue Aug 14 12:47:31 2007
@@ -17,7 +17,6 @@
 package org.apache.camel.builder;
 
 import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Route;
 import org.apache.camel.TestSupport;
@@ -29,14 +28,14 @@
 import org.apache.camel.processor.SendProcessor;
 
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 
 /**
  * @version $Revision$
  */
 public class ErrorHandlerTest extends TestSupport {
-    public void testOverloadingTheDefaultErrorHandler() throws Exception {
+
+    // TODO
+    public void TODO_testOverloadingTheDefaultErrorHandler() throws Exception {
         // START SNIPPET: e1
         RouteBuilder builder = new RouteBuilder() {
             public void configure() {
@@ -46,25 +45,22 @@
         };
         // END SNIPPET: e1
 
-        List<Route> list = builder.getRouteList();
+        List<Route> list = getRouteList(builder);
         assertEquals("Number routes createdÊ" + list, 1, list.size());
         for (Route route : list) {
-            log.info("Found: " + route);
-        }
-/*
-        for (Map.Entry<Endpoint<Exchange>, Processor> route : routes) {
-            Endpoint<Exchange> key = route.getKey();
+            Endpoint key = route.getEndpoint();
             assertEquals("From endpoint", "seda:a", key.getEndpointUri());
-            Processor
-                    processor = route.getValue();
-            LoggingErrorHandler loggingProcessor =
-                    assertIsInstanceOf(LoggingErrorHandler.class, processor);
+
+            EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
+            Processor processor = consumerRoute.getProcessor();
+
+            LoggingErrorHandler loggingProcessor = assertIsInstanceOf(LoggingErrorHandler.class, processor);
+            SendProcessor sendProcessor = assertIsInstanceOf(SendProcessor.class, loggingProcessor.getOutput());
+            log.debug("Found sendProcessor: " + sendProcessor);
         }
-*/
     }
 
-    public void
-    testOverloadingTheHandlerOnASingleRoute() throws Exception {
+    public void   testOverloadingTheHandlerOnASingleRoute() throws Exception {
 
         // START SNIPPET: e2
         RouteBuilder builder = new RouteBuilder() {
@@ -76,26 +72,21 @@
         };
         // END SNIPPET: e2
 
-/*
-        Map<Endpoint,
-                Processor> routeMap = builder.getRouteMap();
-        log.debug(routeMap);
-        Set<Map.Entry<Endpoint,
-                Processor>> routes = routeMap.entrySet();
-        assertEquals("Number routes createdÊ", 2, routes.size());
-        for (Map.Entry<Endpoint,
-                Processor> route : routes) {
-            Endpoint key = route.getKey();
+        List<Route> list = getRouteList(builder);
+        assertEquals("Number routes createdÊ" + list, 2, list.size());
+        for (Route route : list) {
+            Endpoint key = route.getEndpoint();
             String endpointUri = key.getEndpointUri();
-            Processor processor =
-                    route.getValue();
+            EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
+            Processor processor = consumerRoute.getProcessor();
+
+            SendProcessor sendProcessor = null;
             if (endpointUri.equals("seda:a")) {
                 LoggingErrorHandler
                         loggingProcessor = assertIsInstanceOf(LoggingErrorHandler.class,
                         processor);
                 Processor outputProcessor = loggingProcessor.getOutput();
-                SendProcessor sendProcessor = assertIsInstanceOf(SendProcessor.class,
-                        outputProcessor);
+                sendProcessor = assertIsInstanceOf(SendProcessor.class, outputProcessor);
             }
             else {
                 assertEquals("From endpoint", "seda:b",
@@ -104,9 +95,10 @@
                         assertIsInstanceOf(DeadLetterChannel.class, processor);
                 Processor
                         outputProcessor = deadLetterChannel.getOutput();
-                SendProcessor sendProcessor = assertIsInstanceOf(SendProcessor.class, outputProcessor);
+                sendProcessor = assertIsInstanceOf(SendProcessor.class, outputProcessor);
+            }
+            log.debug("For " + endpointUri + " using: " + sendProcessor);
         }
-*/
     }
 
     public void testConfigureDeadLetterChannel() throws Exception {
@@ -118,30 +110,22 @@
             }
         };
         // END SNIPPET: e3
-/*
-        Map<Endpoint,
-                Processor> routeMap = builder.getRouteMap();
-        Set<Map.Entry<Endpoint,
-                Processor>> routes = routeMap.entrySet();
-        assertEquals("Number routes created ", 1, routes.size());
-        for (Map.Entry<Endpoint,
-                Processor> route : routes) {
-            Endpoint key = route.getKey();
+
+        List<Route> list = getRouteList(builder);
+        assertEquals("Number routes createdÊ" + list, 1, list.size());
+        for (Route route : list) {
+            Endpoint key = route.getEndpoint();
             assertEquals("From endpoint", "seda:a", key.getEndpointUri());
-            Processor
-                    processor = route.getValue();
-            DeadLetterChannel deadLetterChannel =
-                    assertIsInstanceOf(DeadLetterChannel.class, processor);
-            Endpoint
-                    deadLetterEndpoint = assertIsInstanceOf(Endpoint.class,
-                    deadLetterChannel.getDeadLetter());
-            assertEndpointUri(deadLetterEndpoint,
-                    "seda:errors");
+
+            EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
+            Processor processor = consumerRoute.getProcessor();
+
+            assertIsInstanceOf(DeadLetterChannel.class, processor);
         }
-*/
     }
 
-    public void  testConfigureDeadLetterChannelWithCustomRedeliveryPolicy() throws Exception {
+    // TODO
+    public void TODO_testConfigureDeadLetterChannelWithCustomRedeliveryPolicy() throws Exception {
         // START SNIPPET: e4
         RouteBuilder builder = new
                 RouteBuilder() {
@@ -152,33 +136,22 @@
                 };
         // END SNIPPET: e4
 
-/*
-        Map<Endpoint,
-                Processor> routeMap = builder.getRouteMap();
-        Set<Map.Entry<Endpoint,
-                Processor>> routes = routeMap.entrySet();
-        assertEquals("Number routes created ", 1, routes.size());
-        for (Map.Entry<Endpoint,
-                Processor> route : routes) {
-            Endpoint key = route.getKey();
+        List<Route> list = getRouteList(builder);
+        assertEquals("Number routes createdÊ" + list, 1, list.size());
+        for (Route route : list) {
+            Endpoint key = route.getEndpoint();
             assertEquals("From endpoint", "seda:a", key.getEndpointUri());
-            Processor
-                    processor = route.getValue();
-            DeadLetterChannel deadLetterChannel =
-                    assertIsInstanceOf(DeadLetterChannel.class, processor);
-            Endpoint
-                    deadLetterEndpoint = assertIsInstanceOf(Endpoint.class,
-                    deadLetterChannel.getDeadLetter());
-            assertEndpointUri(deadLetterEndpoint,
-                    "seda:errors");
-            RedeliveryPolicy redeliveryPolicy =
-                    deadLetterChannel.getRedeliveryPolicy();
-            assertEquals("getMaximumRedeliveries()", 2,
-                    redeliveryPolicy.getMaximumRedeliveries());
-            assertEquals("isUseExponentialBackOff()", true,
-                    redeliveryPolicy.isUseExponentialBackOff());
+
+            EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
+            Processor processor = consumerRoute.getProcessor();
+
+            DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, processor);
+
+            RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy();
+
+            assertEquals("getMaximumRedeliveries()", 2, redeliveryPolicy.getMaximumRedeliveries());
+            assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
         }
-*/
     }
 
     public void testDisablingInheritenceOfErrorHandlers() throws Exception {
@@ -192,7 +165,7 @@
         };
         // END SNIPPET: e5
 
-        List<Route> routes = builder.getRouteList();
+        List<Route> routes = getRouteList(builder);
         assertEquals("Number routes created", 1, routes.size());
         for (Route route : routes) {
             Endpoint key = route.getEndpoint();
@@ -203,6 +176,7 @@
             LoggingErrorHandler loggingProcessor = assertIsInstanceOf(LoggingErrorHandler.class, processor);
             FilterProcessor filterProcessor = assertIsInstanceOf(FilterProcessor.class, loggingProcessor.getOutput());
             SendProcessor sendProcessor = assertIsInstanceOf(SendProcessor.class, filterProcessor.getProcessor());
+            log.debug("Found sendProcessor: " + sendProcessor);
         }
     }
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java?view=diff&rev=565884&r1=565883&r2=565884
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java Tue Aug 14 12:47:31 2007
@@ -16,9 +16,7 @@
  */
 package org.apache.camel.builder;
 
-import java.util.ArrayList;
-import java.util.List;
-
+import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
@@ -26,6 +24,7 @@
 import org.apache.camel.Route;
 import org.apache.camel.TestSupport;
 import org.apache.camel.impl.EventDrivenConsumerRoute;
+import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.processor.ChoiceProcessor;
 import org.apache.camel.processor.DeadLetterChannel;
 import org.apache.camel.processor.DelegateProcessor;
@@ -36,9 +35,11 @@
 import org.apache.camel.processor.Splitter;
 import org.apache.camel.processor.idempotent.IdempotentConsumer;
 import org.apache.camel.processor.idempotent.MemoryMessageIdRepository;
-
 import static org.apache.camel.processor.idempotent.MemoryMessageIdRepository.memoryMessageIdRepository;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @version $Revision$
  */
@@ -55,7 +56,7 @@
             }
         };
         // END SNIPPET: e1
-        return builder.getRouteList();
+        return getRouteList(builder);
     }
 
     public void testSimpleRoute() throws Exception {
@@ -80,7 +81,7 @@
             }
         };
         // END SNIPPET: e2
-        return builder.getRouteList();
+        return getRouteList(builder);
     }
 
     public void testSimpleRouteWithHeaderPredicate() throws Exception {
@@ -111,7 +112,7 @@
             }
         };
         // END SNIPPET: e3
-        return builder.getRouteList();
+        return getRouteList(builder);
     }
 
     public void testSimpleRouteWithChoice() throws Exception {
@@ -153,7 +154,7 @@
             }
         };
         // END SNIPPET: e4
-        return builder.getRouteList();
+        return getRouteList(builder);
     }
 
     public void testCustomProcessor() throws Exception {
@@ -177,7 +178,7 @@
             }
         };
         // END SNIPPET: e5
-        return builder.getRouteList();
+        return getRouteList(builder);
     }
 
     public void testCustomProcessorWithFilter() throws Exception {
@@ -205,7 +206,7 @@
             }
         };
         // END SNIPPET: e6
-        return builder.getRouteList();
+        return getRouteList(builder);
     }
 
     public void testWireTap() throws Exception {
@@ -246,7 +247,7 @@
             }
         };
         // END SNIPPET: e7
-        return builder.getRouteList();
+        return getRouteList(builder);
     }
 
     public void testRouteWithInterceptor() throws Exception {
@@ -280,7 +281,7 @@
         };
         // END SNIPPET: e7
 
-        List<Route> routes = builder.getRouteList();
+        List<Route> routes = getRouteList(builder);
         log.debug("Created routes: " + routes);
 
         assertEquals("Number routes created", 2, routes.size());
@@ -310,7 +311,7 @@
             }
         };
         // END SNIPPET: e8
-        return builder.getRouteList();
+        return getRouteList(builder);
     }
 
     protected List<Route> buildDynamicRecipientList() throws Exception {
@@ -321,7 +322,7 @@
             }
         };
         // END SNIPPET: e9
-        return builder.getRouteList();
+        return getRouteList(builder);
     }
 
     public void testRouteDynamicReceipentList() throws Exception {
@@ -348,7 +349,7 @@
             }
         };
         // END SNIPPET: splitter
-        return builder.getRouteList();
+        return getRouteList(builder);
     }
 
     public void testSplitter() throws Exception {
@@ -376,7 +377,7 @@
             }
         };
         // END SNIPPET: idempotent
-        return builder.getRouteList();
+        return getRouteList(builder);
     }
 
     public void testIdempotentConsumer() throws Exception {

Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java (from r565311, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java?view=diff&rev=565884&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java&r1=565311&p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java&r2=565884
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/view/DotViewTest.java Tue Aug 14 12:47:31 2007
@@ -14,36 +14,26 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.processor;
+package org.apache.camel.view;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
+
+import java.io.File;
 
 /**
  * @version $Revision: 1.1 $
  */
-public class FilterTest extends ContextTestSupport {
-
-    public void testSendMatchingMessage() throws Exception {
-        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
-        resultEndpoint.expectedMessageCount(1);
-
-        template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
-
-        resultEndpoint.assertIsSatisfied();
-    }
-
-    public void testSendNotMatchingMessage() throws Exception {
-        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
-        resultEndpoint.expectedMessageCount(0);
+public class DotViewTest extends ContextTestSupport {
+    protected RouteDotGenerator generator = new RouteDotGenerator();
 
-        template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
-
-        resultEndpoint.assertIsSatisfied();
+    public void testDotFile() throws Exception {
+        new File("target").mkdirs();
+        
+        generator.setFile("target/Example.dot");
+        generator.drawRoutes(context);
     }
 
-
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
@@ -52,4 +42,4 @@
         };
     }
 
-}
+}
\ No newline at end of file

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=565884&r1=565883&r2=565884
==============================================================================
--- 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 Tue Aug 14 12:47:31 2007
@@ -88,7 +88,7 @@
     public void afterPropertiesSet() throws Exception {
 
         // lets force any lazy creation
-        getContext();
+        getContext().addRouteDefinitions(routes);
 
         LOG.debug("Found JAXB created routes: " + getRoutes());
         String[] names = applicationContext.getBeanNamesForType(SpringInstrumentationAgent.class);
@@ -203,9 +203,6 @@
         }
         if (routeBuilder != null) {
             getContext().addRoutes(routeBuilder);
-        }
-        for (RouteType route : routes) {
-            route.addRoutes(getContext());
         }
     }