activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r521678 - in /activemq/camel/trunk: camel-core/src/test/java/org/apache/camel/ camel-script/src/test/java/org/apache/camel/builder/script/
Date Fri, 23 Mar 2007 11:36:34 GMT
Author: jstrachan
Date: Fri Mar 23 04:36:33 2007
New Revision: 521678

URL: http://svn.apache.org/viewvc?view=rev&rev=521678
Log:
refactored the test cases to put more useful helper methods in TestSupport

Removed:
    activemq/camel/trunk/camel-script/src/test/java/org/apache/camel/builder/script/ScriptTestSupport.java
Modified:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
    activemq/camel/trunk/camel-script/src/test/java/org/apache/camel/builder/script/GroovyTest.java

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java?view=diff&rev=521678&r1=521677&r2=521678
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java Fri Mar
23 04:36:33 2007
@@ -40,4 +40,45 @@
     protected void assertEndpointUri(Endpoint<Exchange> endpoint, String uri) {
         assertEquals("Endoint uri for: " + endpoint, uri, endpoint.getEndpointUri());
     }
+
+    /**
+     * Asserts the In message on the exchange contains the expected value
+     */
+    protected void assertInMessageHeader(Exchange exchange, String name, Object expected)
{
+        assertMessageHeader(exchange.getIn(), name, expected);
+    }
+
+    /**
+     * Asserts the Out message on the exchange contains the expected value
+     */
+    protected void assertOutMessageHeader(Exchange exchange, String name, Object expected)
{
+        assertMessageHeader(exchange.getOut(), name, expected);
+    }
+
+    protected void assertMessageHeader(Message message, String name, Object expected) {
+        Object value = message.getHeader(name);
+        assertEquals("Header: " + name + " on Message: " + message, expected, value);
+    }
+
+    /**
+     * Asserts that the given expression when evaluated returns the given answer
+     */
+    protected void assertExpression(Expression expression, Exchange exchange, Object expected)
{
+        Object value = expression.evaluate(exchange);
+
+        log.debug("Evaluated expression: " + expression + " on exchange: " + exchange + "
result: " + value);
+
+        assertEquals("Expression: " + expression + " on Exchange: " + exchange, expected,
value);
+    }
+
+    /**
+     * Asserts that the predicate returns the expected value on the exchange
+     */
+    protected void assertPredicate(Predicate expression, Exchange exchange, boolean expected)
{
+        boolean value = expression.matches(exchange);
+
+        log.debug("Evaluated predicate: " + expression + " on exchange: " + exchange + "
result: " + value);
+
+        assertEquals("Predicate: " + expression + " on Exchange: " + exchange, expected,
value);
+    }
 }

Modified: activemq/camel/trunk/camel-script/src/test/java/org/apache/camel/builder/script/GroovyTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-script/src/test/java/org/apache/camel/builder/script/GroovyTest.java?view=diff&rev=521678&r1=521677&r2=521678
==============================================================================
--- activemq/camel/trunk/camel-script/src/test/java/org/apache/camel/builder/script/GroovyTest.java
(original)
+++ activemq/camel/trunk/camel-script/src/test/java/org/apache/camel/builder/script/GroovyTest.java
Fri Mar 23 04:36:33 2007
@@ -18,9 +18,8 @@
 package org.apache.camel.builder.script;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.Expression;
-import org.apache.camel.Predicate;
-import static org.apache.camel.builder.script.ScriptBuilder.*;
+import org.apache.camel.TestSupport;
+import static org.apache.camel.builder.script.ScriptBuilder.groovy;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.DefaultExchange;
 import org.apache.commons.logging.Log;
@@ -29,7 +28,7 @@
 /**
  * @version $Revision$
  */
-public class GroovyTest extends ScriptTestSupport {
+public class GroovyTest extends TestSupport {
     private static final transient Log log = LogFactory.getLog(GroovyTest.class);
 
     protected Exchange exchange;
@@ -40,10 +39,6 @@
         assertExpression(groovy("exchange.in.headers['doesNotExist']"), exchange, null);
     }
     
-    public void testPredicateUsingScriptAttribute() throws Exception {
-        assertPredicate(groovy("request.headers.name == hacker").attribute("hacker", "James"),
exchange, true);
-    }
-
     public void testPredicateEvaluation() throws Exception {
         assertPredicate(groovy("exchange.in.headers.name == 'James'"), exchange, true);
         assertPredicate(groovy("exchange.in.headers.name == 'Hiram'"), exchange, false);
@@ -51,6 +46,16 @@
         assertPredicate(groovy("request.headers.name == 'James'"), exchange, true);
     }
 
+    public void testProcessorMutatesTheExchange() throws Exception {
+        groovy("request.headers.myNewHeader = 'ABC'").onExchange(exchange);
+
+        assertInMessageHeader(exchange, "myNewHeader", "ABC");
+    }
+
+    public void testPredicateUsingScriptAttribute() throws Exception {
+        assertPredicate(groovy("request.headers.name == hacker").attribute("hacker", "James"),
exchange, true);
+    }
+
     public void testInvalidExpressionFailsWithMeaningfulException() throws Exception {
         try {
             groovy("exchange.doesNotExist").evaluate(exchange);
@@ -62,29 +67,6 @@
             assertTrue("The message should include 'doesNotExist' but was: " + message, message.contains("doesNotExist"));
         }
     }
-
-    /**
-     * Asserts that the given expression when evaluated returns the given answer
-     */
-    protected void assertExpression(Expression expression, Exchange exchange, Object expected)
{
-        Object value = expression.evaluate(exchange);
-        
-        log.debug("Evaluated expression: " + expression + " on exchange: " + exchange + "
result: " + value);
-
-        assertEquals("Expression: " + expression + " on Exchange: " + exchange, expected,
value);
-    }
-
-    /**
-     * Asserts that the predicate returns the expected value on the exchange
-     */
-    protected void assertPredicate(Predicate expression, Exchange exchange, boolean expected)
{
-        boolean value = expression.matches(exchange);
-
-        log.debug("Evaluated predicate: " + expression + " on exchange: " + exchange + "
result: " + value);
-
-        assertEquals("Predicate: " + expression + " on Exchange: " + exchange, expected,
value);
-    }
-
 
     @Override
     protected void setUp() throws Exception {



Mime
View raw message