camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r685546 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/component/mock/ test/java/org/apache/camel/component/file/ test/java/org/apache/camel/component/mock/
Date Wed, 13 Aug 2008 13:33:39 GMT
Author: ningjiang
Date: Wed Aug 13 06:33:38 2008
New Revision: 685546

URL: http://svn.apache.org/viewvc?rev=685546&view=rev
Log:
CAMEL-819 applied patch with thanks to Jonathan

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java?rev=685546&r1=685545&r2=685546&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
Wed Aug 13 06:33:38 2008
@@ -22,8 +22,10 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -308,7 +310,7 @@
 
     /**
      * Adds an expectation that the given body values are received by this
-     * endpoint
+     * endpoint in the specified order
      */
     public void expectedBodiesReceived(final List bodies) {
         expectedMessageCount(bodies.size());
@@ -338,8 +340,43 @@
         List bodyList = new ArrayList();
         bodyList.addAll(Arrays.asList(bodies));
         expectedBodiesReceived(bodyList);
-    }
+    }   
+
+    /**
+     * Adds an expectation that the given body values are received by this
+     * endpoint in any order
+     */    
+    public void expectedBodiesReceivedInAnyOrder(final List bodies) {
+        expectedMessageCount(bodies.size());
+        this.expectedBodyValues = bodies;
+        this.actualBodyValues = new ArrayList();
 
+        expects(new Runnable() {
+            public void run() {
+                Set actualBodyValuesSet = new HashSet(actualBodyValues);
+                for (int i = 0; i < expectedBodyValues.size(); i++) {
+                    Exchange exchange = getReceivedExchanges().get(i);
+                    assertTrue("No exchange received for counter: " + i, exchange != null);
+
+                    Object expectedBody = expectedBodyValues.get(i);
+                    assertTrue("Message with body " + expectedBody + 
+                            " was expected but not found in " + actualBodyValuesSet, 
+                            actualBodyValuesSet.remove(expectedBody));
+                }
+            }
+        });
+    }    
+
+    /**
+     * Adds an expectation that the given body values are received by this
+     * endpoint in any order
+     */        
+    public void expectedBodiesReceivedInAnyOrder(Object... bodies) {
+        List bodyList = new ArrayList();
+        bodyList.addAll(Arrays.asList(bodies));
+        expectedBodiesReceivedInAnyOrder(bodyList);
+    }       
+    
     /**
      * Adds an expectation that messages received should have ascending values
      * of the given expression such as a user generated counter value
@@ -440,7 +477,7 @@
     }
 
     /**
-     * Adds the expection which will be invoked when enough messages are
+     * Adds the expectation which will be invoked when enough messages are
      * received
      */
     public void expects(Runnable runnable) {

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java?rev=685546&r1=685545&r2=685546&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumeSingleDirectoryOnlyTest.java
Wed Aug 13 06:33:38 2008
@@ -36,7 +36,7 @@
 
     public void testConsumeFileOnly() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedBodiesReceived("Hello World", "Bye World");
+        mock.expectedBodiesReceivedInAnyOrder("Hello World", "Bye World");
 
         assertMockEndpointsSatisifed();
     }
@@ -49,4 +49,4 @@
             }
         };
     }
-}
\ No newline at end of file
+}

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java?rev=685546&r1=685545&r2=685546&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java
Wed Aug 13 06:33:38 2008
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.component.mock;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 
@@ -60,6 +63,24 @@
         resultEndpoint.assertIsNotSatisfied();
     }
 
+    public void testExpectsBodiesInOrder() throws Exception {
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); 
+        resultEndpoint.expectedBodiesReceived(listOfMessages(11, 12, 13, 14, 15));
+
+        sendMessages(11, 12, 13, 14, 15);
+
+        resultEndpoint.assertIsSatisfied();
+    }    
+
+    public void testExpectsBodiesInAnyOrder() throws Exception {
+        MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); 
+        resultEndpoint.expectedBodiesReceivedInAnyOrder(listOfMessages(11, 12, 13, 14, 15));
+
+        sendMessages(15, 12, 14, 13, 11);
+
+        resultEndpoint.assertIsSatisfied();
+    }       
+    
     public void testNoDuplicateMessagesPass() throws Exception {
         MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); 
         resultEndpoint.expectsNoDuplicates(header("counter"));
@@ -143,10 +164,22 @@
     
     protected void sendMessages(int... counters) {
         for (int counter : counters) {
-            template.sendBodyAndHeader("direct:a", "<message>" + counter + "</message>",
+            template.sendBodyAndHeader("direct:a", createTestMessage(counter),
                     "counter", counter);
         }
     }
+
+    private String createTestMessage(int counter) {
+        return "<message>" + counter + "</message>";
+    }
+
+    protected List<String> listOfMessages(int... counters) {
+        List<String> list = new ArrayList<String>(counters.length);
+        for (int counter : counters) {
+            list.add(createTestMessage(counter));
+        }
+        return list;
+    }   
     
     protected void sendHeader(String name, String value) {
         template.sendBodyAndHeader("direct:a", "body", name, value);



Mime
View raw message