camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1160275 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/util/ components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/ components/camel-velocity/src/test/java/org/apache/camel/component/velocity/
Date Mon, 22 Aug 2011 14:19:26 GMT
Author: davsclaus
Date: Mon Aug 22 14:19:26 2011
New Revision: 1160275

URL: http://svn.apache.org/viewvc?rev=1160275&view=rev
Log:
CAMEL-4365: Fixed freemarker loading templates from file system

Added:
    camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerFileLetterTest.java
      - copied, changed from r1160262, camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerLetterTest.java
    camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityFileLetterTest.java
      - copied, changed from r1160262, camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java?rev=1160275&r1=1160274&r2=1160275&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResourceHelper.java Mon Aug
22 14:19:26 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.util;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -87,8 +88,14 @@ public final class ResourceHelper {
      * @throws java.io.FileNotFoundException is thrown if the resource file could not be
found
      * @throws java.net.MalformedURLException if the uri is malformed
      */
-    public static URL resolveMandatoryResourceAsUrl(ClassResolver classResolver,  String
uri) throws FileNotFoundException, MalformedURLException {
+    public static URL resolveMandatoryResourceAsUrl(ClassResolver classResolver, String uri)
throws FileNotFoundException, MalformedURLException {
         if (uri.startsWith("file:")) {
+            // check if file exists first
+            String name = ObjectHelper.after(uri, "file:");
+            File file = new File(name);
+            if (!file.exists()) {
+                throw new FileNotFoundException("File " + file + " not found");
+            }
             return new URL(uri);
         } else if (uri.startsWith("http:")) {
             return new URL(uri);

Copied: camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerFileLetterTest.java
(from r1160262, camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerLetterTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerFileLetterTest.java?p2=camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerFileLetterTest.java&p1=camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerLetterTest.java&r1=1160262&r2=1160275&rev=1160275&view=diff
==============================================================================
--- camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerLetterTest.java
(original)
+++ camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerFileLetterTest.java
Mon Aug 22 14:19:26 2011
@@ -16,51 +16,17 @@
  */
 package org.apache.camel.component.freemarker;
 
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
 
-/**
- * Unit test for wiki documentation
- */
-public class FreemarkerLetterTest extends CamelTestSupport {
-
-    // START SNIPPET: e1
-    private Exchange createLetter() {
-        Exchange exchange = context.getEndpoint("direct:a").createExchange();
-
-        Message msg = exchange.getIn();
-        msg.setHeader("firstName", "Claus");
-        msg.setHeader("lastName", "Ibsen");
-        msg.setHeader("item", "Camel in Action");
-        msg.setBody("PS: Next beer is on me, James");
-
-        return exchange;
-    }
-
-    @Test
-    public void testFreemarkerLetter() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        mock.expectedBodiesReceived("Dear Ibsen, Claus\n\nThanks for the order of Camel in
Action."
-                + "\n\nRegards Camel Riders Bookstore\nPS: Next beer is on me, James");
-
-        template.send("direct:a", createLetter());
-
-        mock.assertIsSatisfied();
-    }
+public class FreemarkerFileLetterTest extends FreemarkerLetterTest {
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
                 from("direct:a")
-                    .to("freemarker:org/apache/camel/component/freemarker/letter.ftl")
+                    .to("freemarker:file:src/test/resources/org/apache/camel/component/freemarker/letter.ftl")
                     .to("mock:result");
             }
         };
     }
-    // END SNIPPET: e1
 }

Copied: camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityFileLetterTest.java
(from r1160262, camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityFileLetterTest.java?p2=camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityFileLetterTest.java&p1=camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterTest.java&r1=1160262&r2=1160275&rev=1160275&view=diff
==============================================================================
--- camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterTest.java
(original)
+++ camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityFileLetterTest.java
Mon Aug 22 14:19:26 2011
@@ -16,46 +16,15 @@
  */
 package org.apache.camel.component.velocity;
 
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
 
-/**
- * Unit test for wiki documentation
- */
-public class VelocityLetterTest extends CamelTestSupport {
-
-    // START SNIPPET: e1
-    private Exchange createLetter() {
-        Exchange exchange = context.getEndpoint("direct:a").createExchange();
-        Message msg = exchange.getIn();
-        msg.setHeader("firstName", "Claus");
-        msg.setHeader("lastName", "Ibsen");
-        msg.setHeader("item", "Camel in Action");
-        msg.setBody("PS: Next beer is on me, James");
-        return exchange;
-    }
-
-    @Test
-    public void testVelocityLetter() throws Exception {
-        MockEndpoint mock = getMockEndpoint("mock:result");
-        mock.expectedMessageCount(1);
-        mock.expectedBodiesReceived("Dear Ibsen, Claus\n\nThanks for the order of Camel in
Action.\n\nRegards Camel Riders Bookstore\nPS: Next beer is on me, James");
-
-        template.send("direct:a", createLetter());
-
-        mock.assertIsSatisfied();
-    }
+public class VelocityFileLetterTest extends VelocityLetterTest {
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("direct:a").to("velocity:org/apache/camel/component/velocity/letter.vm").to("mock:result");
+                from("direct:a").to("velocity:file:src/test/resources/org/apache/camel/component/velocity/letter.vm").to("mock:result");
             }
         };
     }
-    // END SNIPPET: e1
 }



Mime
View raw message