camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r747883 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/model/FromType.java test/java/org/apache/camel/TestSupport.java test/java/org/apache/camel/impl/StartAndStopRoutesTest.java
Date Wed, 25 Feb 2009 18:20:07 GMT
Author: jstrachan
Date: Wed Feb 25 18:20:06 2009
New Revision: 747883

URL: http://svn.apache.org/viewvc?rev=747883&view=rev
Log:
CAMEL-1004 - added a test case showing how to stop, mutate and restart a route

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/StartAndStopRoutesTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/FromType.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/FromType.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/FromType.java?rev=747883&r1=747882&r2=747883&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/FromType.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/FromType.java Wed Feb 25 18:20:06
2009
@@ -87,6 +87,7 @@
      */
     public void setUri(String uri) {
         this.uri = uri;
+        clear();
     }
 
     public String getRef() {
@@ -101,6 +102,7 @@
      */
     public void setRef(String ref) {
         this.ref = ref;
+        clear();
     }
 
     public Endpoint getEndpoint() {
@@ -136,4 +138,9 @@
             return "no uri or ref supplied!";
         }
     }
+
+    protected void clear() {
+        this.endpoint = null;
+    }
+
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java?rev=747883&r1=747882&r2=747883&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java Wed Feb 25 18:20:06
2009
@@ -18,6 +18,7 @@
 
 import java.io.File;
 import java.util.List;
+import java.util.Collection;
 
 import junit.framework.TestCase;
 import org.apache.camel.builder.Builder;
@@ -292,7 +293,31 @@
      * Asserts that a list is of the given size
      */
     protected <T> List<T> assertListSize(List<T> list, int size) {
-        assertEquals("List should be of size: " + size + " but is: " + list, size, list.size());
+        return assertListSize("List", list, size);
+    }
+
+    /**
+     * Asserts that a list is of the given size
+     */
+    protected <T> List<T> assertListSize(String message, List<T> list,
int size) {
+        assertEquals(message + " should be of size: "
+                + size + " but is: " + list, size, list.size());
+        return list;
+    }
+
+    /**
+     * Asserts that a list is of the given size
+     */
+    protected <T> Collection<T> assertCollectionSize(Collection<T> list,
int size) {
+        return assertCollectionSize("List", list, size);
+    }
+
+    /**
+     * Asserts that a list is of the given size
+     */
+    protected <T> Collection<T> assertCollectionSize(String message, Collection<T>
list, int size) {
+        assertEquals(message + " should be of size: "
+                + size + " but is: " + list, size, list.size());
         return list;
     }
 

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/StartAndStopRoutesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/StartAndStopRoutesTest.java?rev=747883&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/StartAndStopRoutesTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/StartAndStopRoutesTest.java
Wed Feb 25 18:20:06 2009
@@ -0,0 +1,98 @@
+/**
+ *
+ * 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 org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.seda.SedaEndpoint;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.model.RouteType;
+import org.apache.camel.model.FromType;
+
+import java.util.List;
+
+/**
+ * This test stops a route, mutates it then restarts it
+ *
+ * @version $Revision: 1.1 $
+ */
+public class StartAndStopRoutesTest extends ContextTestSupport {
+    protected SedaEndpoint endpointA;
+    protected SedaEndpoint endpointB;
+    protected SedaEndpoint endpointC;
+    protected Object expectedBody = "<hello>world!</hello>";
+
+    public void testStartRouteThenStopMutateAndStartRouteAgain() throws Exception {
+        List<RouteType> routes = context.getRouteDefinitions();
+        assertCollectionSize("Route", routes, 1);
+        RouteType route = routes.get(0);
+
+        endpointA = getMandatoryEndpoint("seda:test.a", SedaEndpoint.class);
+        endpointB = getMandatoryEndpoint("seda:test.b", SedaEndpoint.class);
+        endpointC = getMandatoryEndpoint("seda:test.C", SedaEndpoint.class);
+
+        assertProduceConsumers("endpointA", endpointA, 0, 1);
+        assertProduceConsumers("endpointB", endpointB, 1, 0);
+        assertProduceConsumers("endpointC", endpointC, 0, 0);
+
+        context.stopRoute(route);
+
+        assertProduceConsumers("endpointA", endpointA, 0, 0);
+        assertProduceConsumers("endpointB", endpointB, 0, 0);
+        assertProduceConsumers("endpointC", endpointC, 0, 0);
+
+
+        // lets mutate the route...
+        FromType fromType = assertOneElement(route.getInputs());
+        fromType.setUri("seda:test.C");
+        context.startRoute(route);
+
+        assertProduceConsumers("endpointA", endpointA, 0, 0);
+        assertProduceConsumers("endpointB", endpointB, 1, 0);
+        assertProduceConsumers("endpointC", endpointC, 0, 1);
+
+
+        // now lets check it works
+        MockEndpoint results = getMockEndpoint("mock:results");
+        results.expectedBodiesReceived(expectedBody);
+
+        template.sendBody(endpointC, expectedBody);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    protected void assertProduceConsumers(String name, SedaEndpoint endpoint, int producerCount,
int consumerCount) {
+        assertCollectionSize("Producers for " + name, endpoint.getProducers(), producerCount);
+        assertCollectionSize("Consumers for " + name, endpoint.getConsumers(), consumerCount);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:test.a").
+                        to("seda:test.b").
+                        to("mock:results");
+            }
+        };
+
+    }
+
+
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/StartAndStopRoutesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message