camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r575882 - in /activemq/camel/trunk: camel-core/src/test/java/org/apache/camel/ components/camel-velocity/src/main/java/org/apache/camel/component/velocity/ components/camel-velocity/src/test/java/org/apache/camel/component/velocity/
Date Sat, 15 Sep 2007 06:50:57 GMT
Author: jstrachan
Date: Fri Sep 14 23:50:56 2007
New Revision: 575882

URL: http://svn.apache.org/viewvc?rev=575882&view=rev
Log:
fixed test case for CAMEL-147

Modified:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/TestSupport.java
    activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
    activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.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?rev=575882&r1=575881&r2=575882&view=diff
==============================================================================
--- 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 Sep
14 23:50:56 2007
@@ -147,6 +147,27 @@
         return assertMessageHeader(exchange.getOut(), name, expected);
     }
 
+    /**
+     * Asserts that the given exchange has an OUT message of the given body value
+     * @param exchange the exchange which should have an OUT message
+     * @param expected the expected value of the OUT message
+     * @throws InvalidPayloadException
+     */
+    protected void assertOutMessageBodyEquals(Exchange exchange, Object expected) throws
InvalidPayloadException {
+        assertNotNull("Should have a response exchange!", exchange);
+
+        Object actual;
+        if (expected == null) {
+            actual = ExchangeHelper.getMandatoryOutBody(exchange);
+            assertEquals("output body of: " + exchange, expected, actual);
+        }
+        else {
+            actual = ExchangeHelper.getMandatoryOutBody(exchange, expected.getClass());
+        }
+        assertEquals("output body of: " + exchange, expected, actual);
+
+        log.debug("Received response: " + exchange + " with out: " + exchange.getOut());
+    }
     protected Object assertMessageHeader(Message message, String name, Object expected) {
         Object value = message.getHeader(name);
         assertEquals("Header: " + name + " on Message: " + message, expected, value);
@@ -274,4 +295,5 @@
         assertNotNull("Text should not be null!", text);
         assertTrue("Text: " + text + " does not contain: " + containedText, text.contains(containedText));
     }
+
 }

Modified: activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java?rev=575882&r1=575881&r2=575882&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
(original)
+++ activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
Fri Sep 14 23:50:56 2007
@@ -17,29 +17,19 @@
  */
 package org.apache.camel.component.velocity;
 
-import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.StringWriter;
 import java.util.Map;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.PollingConsumer;
-import org.apache.camel.Processor;
-import org.apache.camel.Producer;
-import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
 import org.apache.camel.component.ResourceBasedEndpoint;
-import org.apache.camel.impl.DefaultProducer;
-import org.apache.camel.impl.PollingConsumerSupport;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
 import org.apache.velocity.context.Context;
-import org.apache.velocity.exception.MethodInvocationException;
-import org.apache.velocity.exception.ParseErrorException;
-import org.apache.velocity.exception.ResourceNotFoundException;
 
 /**
  * @version $Revision: 1.1 $
@@ -62,9 +52,10 @@
         return ExchangePattern.InOut;
     }
 
-    public VelocityEngine getVelocityEngine() {
+    public VelocityEngine getVelocityEngine() throws Exception {
         if (velocityEngine == null) {
             velocityEngine = component.getVelocityEngine();
+            velocityEngine.init();
         }
         return velocityEngine;
     }
@@ -75,11 +66,14 @@
 
     @Override
     protected void onExchange(Exchange exchange) throws Exception {
-        Reader   reader = new InputStreamReader(getResource().getInputStream());
+        // TODO we might wanna add some kinda resource caching of the template
+        Reader reader = new InputStreamReader(getResource().getInputStream());
         StringWriter buffer = new StringWriter();
         String logTag = getClass().getName();
-        Context velocityContext = new VelocityContext(ExchangeHelper.createVariableMap(exchange));
-        getVelocityEngine().evaluate(velocityContext, buffer, logTag, reader);
+        Map variableMap = ExchangeHelper.createVariableMap(exchange);
+        Context velocityContext = new VelocityContext(variableMap);
+        VelocityEngine engine = getVelocityEngine();
+        engine.evaluate(velocityContext, buffer, logTag, reader);
 
         // now lets output the results to the exchange
         Message out = exchange.getOut(true);

Modified: activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java?rev=575882&r1=575881&r2=575882&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java
(original)
+++ activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java
Fri Sep 14 23:50:56 2007
@@ -22,14 +22,11 @@
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import static org.apache.camel.language.simple.SimpleLanguage.simple;
-import org.apache.camel.util.ExchangeHelper;
 
 /**
  * @version $Revision: 1.1 $
  */
 public class VelocityTest extends ContextTestSupport {
-
     public void testReceivesFooResponse() throws Exception {
         assertRespondsWith("foo", "<hello>foo</hello>");
     }
@@ -38,7 +35,7 @@
         assertRespondsWith("bar", "<hello>bar</hello>");
     }
 
-    protected void assertRespondsWith(final String value, String containedText) throws InvalidPayloadException
{
+    protected void assertRespondsWith(final String value, String expectedBody) throws InvalidPayloadException
{
         Exchange response = template.request("direct:a", new Processor() {
             public void process(Exchange exchange) throws Exception {
                 Message in = exchange.getIn();
@@ -46,14 +43,7 @@
                 in.setHeader("cheese", value);
             }
         });
-
-        assertNotNull("Should receive a response!", response);
-
-        System.out.println("Received response: " + response + " with out: " + response.getOut());
-        
-        String text = ExchangeHelper.getMandatoryOutBody(response, String.class);
-        log.info("Received: " + text);
-        assertStringContains(text, containedText);
+        assertOutMessageBodyEquals(response, expectedBody);
     }
 
     protected RouteBuilder createRouteBuilder() {



Mime
View raw message