camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rom...@apache.org
Subject svn commit: r614066 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/component/mock/MockEndpoint.java test/java/org/apache/camel/component/mock/MockEndpointTest.java
Date Tue, 22 Jan 2008 00:15:56 GMT
Author: romkal
Date: Mon Jan 21 16:15:55 2008
New Revision: 614066

URL: http://svn.apache.org/viewvc?rev=614066&view=rev
Log:
CAMEL-303 : ability to reset MockEndpoint

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/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=614066&r1=614065&r2=614066&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
Mon Jan 21 16:15:55 2008
@@ -17,15 +17,23 @@
 package org.apache.camel.component.mock;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Collection;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.camel.*;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.ExpressionComparator;
@@ -41,21 +49,22 @@
  */
 public class MockEndpoint extends DefaultEndpoint<Exchange> {
     private static final transient Log LOG = LogFactory.getLog(MockEndpoint.class);
-    private int expectedCount = -1;
+    private int expectedCount;
     private int counter;
-    private Map<Integer, Processor> processors = new HashMap<Integer, Processor>();
-    private List<Exchange> receivedExchanges = new CopyOnWriteArrayList<Exchange>();
-    private List<Throwable> failures = new CopyOnWriteArrayList<Throwable>();
-    private List<Runnable> tests = new CopyOnWriteArrayList<Runnable>();
+    private Map<Integer, Processor> processors;
+    private List<Exchange> receivedExchanges;
+    private List<Throwable> failures;
+    private List<Runnable> tests;
     private CountDownLatch latch;
-    private long sleepForEmptyTest = 1000L;
-    private long defaulResultWaitMillis = 20000L;
-    private int expectedMinimumCount = -1;
+    private long sleepForEmptyTest;
+    private long defaulResultWaitMillis;
+    private int expectedMinimumCount;
     private List expectedBodyValues;
-    private List actualBodyValues = new ArrayList();
+    private List actualBodyValues;
 
     public MockEndpoint(String endpointUri, Component component) {
         super(endpointUri, component);
+        reset();
     }
 
     public static void assertWait(long timeout, TimeUnit unit, MockEndpoint... endpoints)
throws InterruptedException {
@@ -463,6 +472,21 @@
         this.defaulResultWaitMillis = defaulResultWaitMillis;
     }
 
+    public void reset() {
+    	expectedCount = -1;
+        counter = 0;
+        processors = new HashMap<Integer, Processor>();
+        receivedExchanges = new CopyOnWriteArrayList<Exchange>();
+        failures = new CopyOnWriteArrayList<Throwable>();
+        tests = new CopyOnWriteArrayList<Runnable>();
+        latch = null;
+        sleepForEmptyTest = 1000L;
+        defaulResultWaitMillis = 20000L;
+        expectedMinimumCount = -1;
+        expectedBodyValues = null;
+        actualBodyValues = new ArrayList();
+    }
+    
     // Implementation methods
     // -------------------------------------------------------------------------
     protected synchronized void onExchange(Exchange exchange) {

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=614066&r1=614065&r2=614066&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
Mon Jan 21 16:15:55 2008
@@ -78,6 +78,22 @@
         resultEndpoint.assertIsNotSatisfied();
     }
 
+    public void testReset() throws Exception {
+    	MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
+    	resultEndpoint.expectedMessageCount(2);
+    	
+    	sendMessages(11, 12);
+    	
+    	resultEndpoint.assertIsSatisfied();
+    	resultEndpoint.reset();
+    	
+    	resultEndpoint.expectedMessageCount(3);
+    	
+    	sendMessages(11, 12, 13);
+    	
+    	resultEndpoint.assertIsSatisfied();
+    }
+    
     protected void sendMessages(int... counters) {
         for (int counter : counters) {
             template.sendBodyAndHeader("direct:a", "<message>" + counter + "</message>",



Mime
View raw message