camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r801966 - in /camel/sandbox/tuning-experiment/camel-core/src: main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java test/java/org/apache/camel/component/mock/MockEndpointMutateTest.java
Date Fri, 07 Aug 2009 12:24:20 GMT
Author: davsclaus
Date: Fri Aug  7 12:24:20 2009
New Revision: 801966

URL: http://svn.apache.org/viewvc?rev=801966&view=rev
Log:
Tuning mock mutate unit test.

Added:
    camel/sandbox/tuning-experiment/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointMutateTest.java
  (with props)
Modified:
    camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java

Modified: camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java?rev=801966&r1=801965&r2=801966&view=diff
==============================================================================
--- camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java
(original)
+++ camel/sandbox/tuning-experiment/camel-core/src/main/java/org/apache/camel/impl/CopyOnWriteMessageFacade.java
Fri Aug  7 12:24:20 2009
@@ -35,6 +35,11 @@
         this.readOnly = readOnly;
     }
 
+    public Message getReadOnlyDelegate() {
+        // TODO: experiment for mock endpoint to avoid copying received exchanges
+        return readOnly;
+    }
+
     public Message getDelegate() {
         if (copiedMessage != null) {
             return copiedMessage;

Added: camel/sandbox/tuning-experiment/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointMutateTest.java
URL: http://svn.apache.org/viewvc/camel/sandbox/tuning-experiment/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointMutateTest.java?rev=801966&view=auto
==============================================================================
--- camel/sandbox/tuning-experiment/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointMutateTest.java
(added)
+++ camel/sandbox/tuning-experiment/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointMutateTest.java
Fri Aug  7 12:24:20 2009
@@ -0,0 +1,91 @@
+/**
+ * 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.component.mock;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class MockEndpointMutateTest extends ContextTestSupport {
+
+    public void testMockMutate() throws Exception {
+        MockEndpoint a = getMockEndpoint("mock:a");
+        a.expectedMessageCount(1);
+        a.message(0).body().isEqualTo("Hello World");
+
+        MockEndpoint b = getMockEndpoint("mock:b");
+        b.expectedMessageCount(1);
+        b.message(0).body().isEqualTo("foo");
+
+        MockEndpoint c = getMockEndpoint("mock:c");
+        c.expectedMessageCount(1);
+        c.message(0).body().isEqualTo("foo");
+        c.message(0).header("bar").isEqualTo(123);
+
+        MockEndpoint d = getMockEndpoint("mock:d");
+        d.expectedMessageCount(1);
+        d.message(0).body().isEqualTo("cheese");
+        d.message(0).header("bar").isEqualTo(123);
+
+        MockEndpoint result = getMockEndpoint("mock:result");
+        result.expectedMessageCount(1);
+        result.expectedBodiesReceived("cheese");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        assertEquals("Hello World", a.getReceivedExchanges().get(0).getIn().getBody());
+        assertEquals("No headers", 0, a.getReceivedExchanges().get(0).getIn().getHeaders().size());
+
+        assertEquals("foo", b.getReceivedExchanges().get(0).getIn().getBody());
+        assertEquals("No headers", 0, b.getReceivedExchanges().get(0).getIn().getHeaders().size());
+
+        assertEquals("foo", c.getReceivedExchanges().get(0).getIn().getBody());
+        assertEquals("1 header", 1, c.getReceivedExchanges().get(0).getIn().getHeaders().size());
+        assertEquals(123, c.getReceivedExchanges().get(0).getIn().getHeader("bar"));
+
+        assertEquals("cheese", d.getReceivedExchanges().get(0).getIn().getBody());
+        assertEquals("1 header", 1, d.getReceivedExchanges().get(0).getIn().getHeaders().size());
+        assertEquals(123, d.getReceivedExchanges().get(0).getIn().getHeader("bar"));
+
+        assertEquals("cheese", result.getReceivedExchanges().get(0).getIn().getBody());
+        assertEquals("No headers", 0, result.getReceivedExchanges().get(0).getIn().getHeaders().size());
+        assertEquals(null, result.getReceivedExchanges().get(0).getIn().getHeader("bar"));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .to("mock:a")
+                        .setBody(constant("foo"))
+                    .to("mock:b")
+                        .setHeader("bar", constant(123))
+                    .to("mock:c")
+                        .setBody(constant("cheese"))
+                    .to("mock:d")
+                        .removeHeader("bar")
+                    .to("mock:result");
+            }
+        };
+    }
+}

Propchange: camel/sandbox/tuning-experiment/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointMutateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/sandbox/tuning-experiment/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointMutateTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message