camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1227532 - in /camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept: InterceptSendToEndpointConditionalSkip2Test.java InterceptSendToEndpointConditionalSkip3Test.java
Date Thu, 05 Jan 2012 09:42:54 GMT
Author: davsclaus
Date: Thu Jan  5 09:42:54 2012
New Revision: 1227532

URL: http://svn.apache.org/viewvc?rev=1227532&view=rev
Log:
CAMEL-4809: Added more tests.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip2Test.java
      - copied, changed from r1227529, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkipTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip3Test.java

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip2Test.java
(from r1227529, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkipTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip2Test.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip2Test.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkipTest.java&r1=1227529&r2=1227532&rev=1227532&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkipTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip2Test.java
Thu Jan  5 09:42:54 2012
@@ -24,65 +24,48 @@ import org.apache.camel.builder.RouteBui
  * 
  * @version
  */
-public class InterceptSendToEndpointConditionalSkipTest extends ContextTestSupport {
+public class InterceptSendToEndpointConditionalSkip2Test extends ContextTestSupport {
 
-    /**
-     * Verify that the endpoint is only skipped if the adjacent 'when' condition is satisfied
-     */
-    public void testInterceptSendToEndpointSkipConditionSatisfied() throws Exception {
+    public void testInterceptSendToEndpointNone() throws Exception {
         getMockEndpoint("mock:a").expectedMessageCount(1);
-        getMockEndpoint("mock:skippable").expectedMessageCount(0);
-        getMockEndpoint("mock:detour").expectedMessageCount(1);
+        getMockEndpoint("mock:detour1").expectedMessageCount(0);
+        getMockEndpoint("mock:detour2").expectedMessageCount(0);
         getMockEndpoint("mock:c").expectedMessageCount(1);
 
-        template.sendBody("direct:start", "skip");
+        template.sendBody("direct:start", "Hello World");
 
         assertMockEndpointsSatisfied();
     }
 
-    /**
-     * Verify that the endpoint is not skipped if the adjacent 'when' condition evaluates
to false
-     */
-    public void testInterceptSendToEndpointSkipConditionNotSatisfied() throws Exception {
+    public void testInterceptSendToEndpoint1() throws Exception {
         getMockEndpoint("mock:a").expectedMessageCount(1);
-        getMockEndpoint("mock:skippable").expectedMessageCount(1);
-        getMockEndpoint("mock:detour").expectedMessageCount(0);
+        getMockEndpoint("mock:detour1").expectedMessageCount(1);
+        getMockEndpoint("mock:detour2").expectedMessageCount(0);
         getMockEndpoint("mock:c").expectedMessageCount(1);
 
-        template.sendBody("direct:start", "Hello World");
+        template.sendBody("direct:start", "skip1");
 
         assertMockEndpointsSatisfied();
     }
 
-    /**
-     * Verify that the conditional skip support is only activated when using interceptSendToEndpoint().when()
and not
-     * interceptSendToEndpoint().choice()..., as the choice keyword is not directly associated
with the interception behaviour and it belongs to the
-     * interception body (initiating a new routing block)
-     */
-    public void testInterceptSendToEndpointSkipConditionNoEffectChoice() throws Exception
{
-        getMockEndpoint("mock:a").expectedMessageCount(2);
-        getMockEndpoint("mock:skippableNoEffect").expectedMessageCount(0);
-        getMockEndpoint("mock:c").expectedMessageCount(2);
-
-        getMockEndpoint("mock:noSkipWhen").expectedMessageCount(1);
-        getMockEndpoint("mock:noSkipOW").expectedMessageCount(1);
+    public void testInterceptSendToEndpoint2() throws Exception {
+        getMockEndpoint("mock:a").expectedMessageCount(1);
+        getMockEndpoint("mock:detour1").expectedMessageCount(0);
+        getMockEndpoint("mock:detour2").expectedMessageCount(1);
+        getMockEndpoint("mock:c").expectedMessageCount(1);
 
-        template.sendBody("direct:startNoEffect", "skipNoEffectWhen");
-        template.sendBody("direct:startNoEffect", "Hello Camel");
+        template.sendBody("direct:start", "skip2");
 
         assertMockEndpointsSatisfied();
     }
 
-    /**
-     * Test that when multiple conditions are chained together in Java DSL, only the first
one will determine whether the endpoint is skipped or not
-     */
-    public void testInterceptSendToEndpointSkipMultipleConditions() throws Exception {
+    public void testInterceptSendToEndpointBoth() throws Exception {
         getMockEndpoint("mock:a").expectedMessageCount(1);
-        getMockEndpoint("mock:skippableMultipleConditions").expectedMessageCount(0);
-        getMockEndpoint("mock:detour").expectedMessageCount(1);
+        getMockEndpoint("mock:detour1").expectedMessageCount(1);
+        getMockEndpoint("mock:detour2").expectedMessageCount(1);
         getMockEndpoint("mock:c").expectedMessageCount(1);
 
-        template.sendBody("direct:startMultipleConditions", "skip");
+        template.sendBody("direct:start", "skip1,skip2");
 
         assertMockEndpointsSatisfied();
     }
@@ -92,35 +75,17 @@ public class InterceptSendToEndpointCond
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                // only skip if the body equals 'skip'
-                interceptSendToEndpoint("mock:skippable").skipSendToOriginalEndpoint()
-                        .when(body().isEqualTo("skip")).to("mock:detour");
-
-                // always skip with a normal with a normal choice inside instructing where
to route instead
-                interceptSendToEndpoint("mock:skippableNoEffect").skipSendToOriginalEndpoint()
-                        .choice()
-                        .when(body().isEqualTo("skipNoEffectWhen")).to("mock:noSkipWhen")
-                        .otherwise().to("mock:noSkipOW");
-
-                // in this case, the original endpoint will be skipped but no message will
be sent to mock:detour
-                interceptSendToEndpoint("mock:skippableMultipleConditions").skipSendToOriginalEndpoint()
-                        .when(body().isEqualTo("skip"))
-                        .when(body().isNotEqualTo("skip"))
-                            .to("mock:detour");
-
-                from("direct:start")
-                        .to("mock:a")
-                        .to("mock:skippable")
-                        .to("mock:c");
+                // we have 2 interceptors, which may both trigger, or either or, or none
+                interceptSendToEndpoint("mock:skip1").skipSendToOriginalEndpoint()
+                        .when(body().contains("skip1")).to("mock:detour1");
 
-                from("direct:startNoEffect")
-                        .to("mock:a")
-                        .to("mock:skippableNoEffect")
-                        .to("mock:c");
+                interceptSendToEndpoint("mock:skip2").skipSendToOriginalEndpoint()
+                        .when(body().contains("skip2")).to("mock:detour2");
 
-                from("direct:startMultipleConditions")
+                from("direct:start")
                         .to("mock:a")
-                        .to("mock:skippableMultipleConditions")
+                        .to("mock:skip1")
+                        .to("mock:skip2")
                         .to("mock:c");
             }
         };

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip3Test.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip3Test.java?rev=1227532&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip3Test.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToEndpointConditionalSkip3Test.java
Thu Jan  5 09:42:54 2012
@@ -0,0 +1,83 @@
+/**
+ * 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.intercept;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Unit tests on the conditional skip support on InterceptSendToEndpoint.
+ * 
+ * @version
+ */
+public class InterceptSendToEndpointConditionalSkip3Test extends ContextTestSupport {
+
+    public void testInterceptSendToEndpointNone() throws Exception {
+        getMockEndpoint("mock:a").expectedMessageCount(1);
+        getMockEndpoint("mock:detour1").expectedMessageCount(0);
+        getMockEndpoint("mock:detour2").expectedMessageCount(0);
+        getMockEndpoint("mock:c").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testInterceptSendToEndpoint1() throws Exception {
+        getMockEndpoint("mock:a").expectedMessageCount(1);
+        getMockEndpoint("mock:detour1").expectedMessageCount(1);
+        getMockEndpoint("mock:detour2").expectedMessageCount(0);
+        getMockEndpoint("mock:c").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "skip1");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testInterceptSendToEndpoint2() throws Exception {
+        getMockEndpoint("mock:a").expectedMessageCount(1);
+        getMockEndpoint("mock:detour1").expectedMessageCount(0);
+        getMockEndpoint("mock:detour2").expectedMessageCount(1);
+        getMockEndpoint("mock:c").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "skip2");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // we have 2 interceptors, which may both trigger, or either or, or none
+                interceptSendToEndpoint("mock:skip").skipSendToOriginalEndpoint()
+                        .when(body().contains("skip")).to("mock:detour1");
+
+                // we intercept the interceptor
+                interceptSendToEndpoint("mock:detour1").skipSendToOriginalEndpoint()
+                        .when(body().contains("skip2")).to("mock:detour2");
+
+                from("direct:start")
+                        .to("mock:a")
+                        .to("mock:skip")
+                        .to("mock:c");
+            }
+        };
+    }
+
+}



Mime
View raw message