camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1003484 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/spi/ camel-core/src/test/java/org/apache/camel/processor/ components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/ components/camel-spring/src/test/reso...
Date Fri, 01 Oct 2010 11:15:03 GMT
Author: davsclaus
Date: Fri Oct  1 11:15:03 2010
New Revision: 1003484

URL: http://svn.apache.org/viewvc?rev=1003484&view=rev
Log:
Fixed test.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FlipRoutePolicy.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FlipRoutePolicyTest.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSpringPropertyPlaceholderRoute.java
  (contents, props changed)
      - copied, changed from r1003433, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRoute.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/bundle-context.properties
      - copied, changed from r1003433, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/bundle-context.cfg
Removed:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRoute.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/bundle-context.cfg
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RoutePolicy.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRouteTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRouteTest-context.xml

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RoutePolicy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RoutePolicy.java?rev=1003484&r1=1003483&r2=1003484&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RoutePolicy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/RoutePolicy.java Fri Oct  1
11:15:03 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.spi;
 
-import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Route;
 

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FlipRoutePolicy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FlipRoutePolicy.java?rev=1003484&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FlipRoutePolicy.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FlipRoutePolicy.java Fri
Oct  1 11:15:03 2010
@@ -0,0 +1,63 @@
+/**
+ * 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.processor;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Route;
+import org.apache.camel.impl.RoutePolicySupport;
+
+/**
+ * @version $Revision$
+ */
+public class FlipRoutePolicy extends RoutePolicySupport {
+
+    private final String name1;
+    private final String name2;
+
+    /**
+     * Flip the two routes
+     *
+     * @param name1 name of the first route
+     * @param name2 name of the second route
+     */
+    public FlipRoutePolicy(String name1, String name2) {
+        this.name1 = name1;
+        this.name2 = name2;
+    }
+
+    @Override
+    public void onExchangeDone(Route route, Exchange exchange) {
+        // decide which route to stop and start
+        // basically we should flip the two routes
+        String stop = route.getId().equals(name1) ? name1 : name2;
+        String start = route.getId().equals(name1) ? name2 : name1;
+
+        CamelContext context = exchange.getContext();
+        try {
+            context.getInflightRepository().remove(exchange);
+            context.stopRoute(stop);
+            context.startRoute(start);
+        } catch (Exception e) {
+            // let the exception handle handle it, which is often just to log it
+            getExceptionHandler().handleException("Error flipping routes", e);
+        }
+    }
+
+}

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FlipRoutePolicyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FlipRoutePolicyTest.java?rev=1003484&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FlipRoutePolicyTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FlipRoutePolicyTest.java
Fri Oct  1 11:15:03 2010
@@ -0,0 +1,64 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.RoutePolicy;
+
+/**
+ * @version $Revision$
+ */
+public class FlipRoutePolicyTest extends ContextTestSupport {
+
+    public void testFlipRoutePolicyTest() throws Exception {
+        MockEndpoint foo = getMockEndpoint("mock:foo");
+        foo.expectedMinimumMessageCount(5);
+
+        MockEndpoint bar = getMockEndpoint("mock:bar");
+        bar.expectedMinimumMessageCount(5);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // create the flip route policy
+                RoutePolicy policy = new FlipRoutePolicy("foo", "bar");
+
+                // use the flip route policy in the foo route
+                from("timer://foo")
+                    .routeId("foo").routePolicy(policy)
+                    .setBody().constant("Foo message")
+                    .to("log:foo")
+                    .to("mock:foo");
+
+                // use the flip route policy in the bar route and do NOT start
+                // this route on startup
+                from("timer://bar")
+                    .routeId("bar").routePolicy(policy).noAutoStartup()
+                    .setBody().constant("Bar message")
+                    .to("log:bar")
+                    .to("mock:bar");
+            }
+        };
+    }
+}

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRouteTest.java?rev=1003484&r1=1003483&r2=1003484&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRouteTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRouteTest.java
Fri Oct  1 11:15:03 2010
@@ -17,11 +17,12 @@
 package org.apache.camel.spring.placeholder;
 
 import java.io.File;
-import java.util.Calendar;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
+import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
-import org.apache.camel.util.FileUtil;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -39,8 +40,8 @@ public class SimpleLanguageWithSprinProp
 
     @Before
     public void setUp() throws Exception {
-        FileUtil.deleteFile(new File("target/outBox"));
-        FileUtil.deleteFile(new File("target/outBoxSimple"));
+        ContextTestSupport.deleteDirectory("target/outBox");
+        ContextTestSupport.deleteDirectory("target/outBoxSimple");
     }
 
     @Test
@@ -65,12 +66,10 @@ public class SimpleLanguageWithSprinProp
     }
 
     private void assertFileExists(String directory) {
-        Calendar today = Calendar.getInstance();
-        String day = String.valueOf(today.get(Calendar.DAY_OF_MONTH));
-        String month = String.valueOf(today.get(Calendar.MONTH) + 1);
-        month = month.length() == 1 ? "0" + month : month;
-        String year = String.valueOf(today.get(Calendar.YEAR));
-
-        assertTrue(new File(directory + "test-" + year + month + day + ".txt").exists());
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+        String s = sdf.format(new Date());
+        String name = directory + "test-" + s + ".txt";
+        File file = new File(name).getAbsoluteFile();
+        assertTrue("File should exist: " + name, file.exists());
     }
 }

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSpringPropertyPlaceholderRoute.java
(from r1003433, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRoute.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSpringPropertyPlaceholderRoute.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSpringPropertyPlaceholderRoute.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRoute.java&r1=1003433&r2=1003484&rev=1003484&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRoute.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSpringPropertyPlaceholderRoute.java
Fri Oct  1 11:15:03 2010
@@ -18,14 +18,13 @@ package org.apache.camel.spring.placehol
 
 import org.apache.camel.builder.RouteBuilder;
 
-public class SimpleLanguageWithSprinPropertyPlaceholderRoute extends RouteBuilder {
+public class SimpleLanguageWithSpringPropertyPlaceholderRoute extends RouteBuilder {
 
     private String fromEndpoint;
     private String toEndpoint;
 
     public void configure() throws Exception {
-        from(fromEndpoint)
-            .to(toEndpoint);
+        from(fromEndpoint).to(toEndpoint);
     }
 
     public void setFromEndpoint(String fromEndpoint) {

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

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/placeholder/SimpleLanguageWithSpringPropertyPlaceholderRoute.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRouteTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRouteTest-context.xml?rev=1003484&r1=1003483&r2=1003484&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRouteTest-context.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/SimpleLanguageWithSprinPropertyPlaceholderRouteTest-context.xml
Fri Oct  1 11:15:03 2010
@@ -25,14 +25,15 @@
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
         ">
         
-	<ctx:property-placeholder ignore-unresolvable="true" location="classpath:org/apache/camel/spring/placeholder/bundle-context.cfg"
/>
+	<ctx:property-placeholder ignore-unresolvable="true"
+                              location="classpath:org/apache/camel/spring/placeholder/bundle-context.properties"/>
 	
-	<bean id="testRoute1" class="org.apache.camel.spring.placeholder.SimpleLanguageWithSprinPropertyPlaceholderRoute">
+	<bean id="testRoute1" class="org.apache.camel.spring.placeholder.SimpleLanguageWithSpringPropertyPlaceholderRoute">
 		<property name="fromEndpoint" value="${fromEndpoint}" />
 		<property name="toEndpoint" value="${toEndpoint}" />
 	</bean>
  
-    <bean id="testRoute2" class="org.apache.camel.spring.placeholder.SimpleLanguageWithSprinPropertyPlaceholderRoute">
+    <bean id="testRoute2" class="org.apache.camel.spring.placeholder.SimpleLanguageWithSpringPropertyPlaceholderRoute">
         <property name="fromEndpoint" value="${fromEndpointSimple}" />
         <property name="toEndpoint" value="${toEndpointSimple}" />
     </bean>
@@ -41,4 +42,5 @@
 		<camel:routeBuilder ref="testRoute1"/>
         <camel:routeBuilder ref="testRoute2"/>
 	</camelContext>
+
 </beans>
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/bundle-context.properties
(from r1003433, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/bundle-context.cfg)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/bundle-context.properties?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/bundle-context.properties&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/bundle-context.cfg&r1=1003433&r2=1003484&rev=1003484&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/bundle-context.cfg
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/placeholder/bundle-context.properties
Fri Oct  1 11:15:03 2010
@@ -1,23 +1,19 @@
-#
-#
-#    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.
-#
-#
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
 fromEndpoint=direct:start
 toEndpoint=file://target/outBox?fileName=test-${date:now:yyyyMMdd}.txt
 



Mime
View raw message