You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/02/01 13:21:20 UTC

svn commit: r905269 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/mock/MockEndpoint.java test/java/org/apache/camel/component/mock/MockEndpointTest.java

Author: davsclaus
Date: Mon Feb  1 12:21:20 2010
New Revision: 905269

URL: http://svn.apache.org/viewvc?rev=905269&view=rev
Log:
CAMEL-2434: Better failure messages for expected header or property.

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

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java?rev=905269&r1=905268&r2=905269&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java Mon Feb  1 12:21:20 2010
@@ -331,10 +331,8 @@
                     assertTrue("There is no type conversion possible from " + actualHeader.getClass().getName() 
                             + " to " + headerValue.getClass().getName(), actualValue != null);
                 }
-                assertEquals("Header of message", headerValue, actualValue);
+                assertEquals("Header with name " + headerName, headerValue, actualValue);
             }
-
-
         });
     }
 
@@ -354,7 +352,7 @@
                 assertTrue("No property with name " + propertyName + " found.", actualProperty != null);
 
                 Object actualValue = getCamelContext().getTypeConverter().convertTo(actualProperty.getClass(), propertyValue);
-                assertEquals("Property of message", actualValue, actualProperty);
+                assertEquals("Property with name " + propertyName, actualValue, actualProperty);
             }
         });
     }
@@ -457,7 +455,7 @@
     }
 
     /**
-     * Adds an expection that a file exists with the given name
+     * Adds an expectation that a file exists with the given name
      *
      * @param name name of file, will cater for / and \ on different OS platforms
      */
@@ -466,7 +464,7 @@
     }
 
     /**
-     * Adds an expection that a file exists with the given name
+     * Adds an expectation that a file exists with the given name
      * <p/>
      * Will wait at most 5 seconds while checking for the existence of the file.
      *

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java?rev=905269&r1=905268&r2=905269&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java Mon Feb  1 12:21:20 2010
@@ -417,10 +417,72 @@
         } catch (Exception e) {
             // not possible
         }
-        
+
         assertEquals(0, mock.getFailures().size());
     }
 
+    public void testHeaderMissing() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedHeaderReceived("foo", 123);
+        mock.expectedHeaderReceived("bar", "cheese");
+        
+        template.sendBodyAndHeader("direct:a", "Hello World", "foo", 123);
+
+        try {
+            assertMockEndpointsSatisfied();
+            fail("Should have thrown exception");
+        } catch (AssertionError e) {
+            assertEquals("mock://result No header with name bar found.", e.getMessage());
+        }
+    }
+
+    public void testHeaderInvalidValue() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedHeaderReceived("bar", "cheese");
+
+        template.sendBodyAndHeader("direct:a", "Hello World", "bar", "beer");
+
+        try {
+            assertMockEndpointsSatisfied();
+            fail("Should have thrown exception");
+        } catch (AssertionError e) {
+            assertEquals("mock://result Header with name bar. Expected: <cheese> but was: <beer>", e.getMessage());
+        }
+    }
+    
+    public void testPropertyMissing() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedPropertyReceived("foo", 123);
+        mock.expectedPropertyReceived("bar", "cheese");
+
+        template.sendBodyAndProperty("direct:a", "Hello World", "foo", 123);
+
+        try {
+            assertMockEndpointsSatisfied();
+            fail("Should have thrown exception");
+        } catch (AssertionError e) {
+            assertEquals("mock://result No property with name bar found.", e.getMessage());
+        }
+    }
+
+    public void testPropertyInvalidValue() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        mock.expectedPropertyReceived("bar", "cheese");
+
+        template.sendBodyAndProperty("direct:a", "Hello World", "bar", "beer");
+
+        try {
+            assertMockEndpointsSatisfied();
+            fail("Should have thrown exception");
+        } catch (AssertionError e) {
+            assertEquals("mock://result Property with name bar. Expected: <cheese> but was: <beer>", e.getMessage());
+        }
+    }
+
     protected void sendMessages(int... counters) {
         for (int counter : counters) {
             template.sendBodyAndHeader("direct:a", createTestMessage(counter), "counter", counter);