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 2011/08/22 16:18:26 UTC

svn commit: r1160274 - in /camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi: freemarker/FreemarkerFileTest.java velocity/VelocityFileTest.java

Author: davsclaus
Date: Mon Aug 22 14:18:26 2011
New Revision: 1160274

URL: http://svn.apache.org/viewvc?rev=1160274&view=rev
Log:
Added osgi unit tests for velocity and freemarker to load templates from file system.

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerFileTest.java
      - copied, changed from r1160262, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/velocity/VelocityFileTest.java
      - copied, changed from r1160262, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/velocity/VelocityTest.java

Copied: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerFileTest.java (from r1160262, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerFileTest.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerFileTest.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java&r1=1160262&r2=1160274&rev=1160274&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerFileTest.java Mon Aug 22 14:18:26 2011
@@ -16,58 +16,39 @@
  */
 package org.apache.camel.itest.osgi.freemarker;
 
-import org.apache.camel.Exchange;
-import org.apache.camel.InvalidPayloadException;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
-import org.junit.Test;
+import org.apache.camel.util.IOHelper;
 import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 
-import static org.ops4j.pax.exam.OptionUtils.combine;
-import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
-
 @RunWith(JUnit4TestRunner.class)
-public class FreemarkerTest extends OSGiIntegrationTestSupport {
+public class FreemarkerFileTest extends FreemarkerTest {
     
-    @Test
-    public void testReceivesResponse() throws Exception {        
-        assertRespondsWith("foo", "<hello>foo</hello>");
-        assertRespondsWith("bar", "<hello>bar</hello>");
-    }
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("mydir");
+        createDirectory("mydir");
 
-    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();
-                in.setBody("answer");
-                in.setHeader("cheese", value);
-            }
-        });
-        assertOutMessageBodyEquals(response, expectedBody);
+        File src = new File("../../src/test/resources/org/apache/camel/itest/osgi/freemarker/example.ftl");
+        File dest = new File("mydir/example.ftl");
+        FileInputStream fis = new FileInputStream(src);
+        FileOutputStream fos = new FileOutputStream(dest, false);
+        IOHelper.copyAndCloseInput(fis, fos);
+        fos.close();
+
+        super.setUp();
     }
 
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
-                from("direct:a").to("freemarker:org/apache/camel/itest/osgi/freemarker/example.ftl");
+                from("direct:a").to("freemarker:file:mydir/example.ftl");
             }
         };
     }
-    
-    @Configuration
-    public static Option[] configure() {
-        Option[] options = combine(
-            getDefaultCamelKarafOptions(),
-            // using the features to install the other camel components             
-            scanFeatures(getCamelKarafFeatureUrl(), "camel-freemarker"));
-        
-        return options;
-    }
-    
-   
+
 }
\ No newline at end of file

Copied: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/velocity/VelocityFileTest.java (from r1160262, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/velocity/VelocityTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/velocity/VelocityFileTest.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/velocity/VelocityFileTest.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/velocity/VelocityTest.java&r1=1160262&r2=1160274&rev=1160274&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/velocity/VelocityTest.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/velocity/VelocityFileTest.java Mon Aug 22 14:18:26 2011
@@ -16,59 +16,40 @@
  */
 package org.apache.camel.itest.osgi.velocity;
 
-import org.apache.camel.Exchange;
-import org.apache.camel.InvalidPayloadException;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
-import org.junit.Test;
+import org.apache.camel.util.IOHelper;
 import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 
-import static org.ops4j.pax.exam.OptionUtils.combine;
-import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
-
 @RunWith(JUnit4TestRunner.class)
-public class VelocityTest extends OSGiIntegrationTestSupport {
-    
-    @Test
-    public void testReceivesResponse() throws Exception {        
-        assertRespondsWith("foo", "<header>foo</header><hello>foo</hello>");
-        assertRespondsWith("bar", "<header>bar</header><hello>bar</hello>");
-    }
+public class VelocityFileTest extends VelocityTest {
 
-    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();
-                in.setBody("answer");
-                in.setHeader("cheese", value);
-            }
-        });
-        assertOutMessageBodyEquals(response, expectedBody);
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("mydir");
+        createDirectory("mydir");
+
+        File src = new File("../../src/test/resources/org/apache/camel/itest/osgi/velocity/example.vm");
+        File dest = new File("mydir/example.vm");
+        FileInputStream fis = new FileInputStream(src);
+        FileOutputStream fos = new FileOutputStream(dest, false);
+        IOHelper.copyAndCloseInput(fis, fos);
+        fos.close();
+
+        super.setUp();
     }
 
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
                 from("direct:a").
-                        to("velocity:org/apache/camel/itest/osgi/velocity/example.vm");
+                        to("velocity:file:mydir/example.vm");
             }
         };
     }
-    
-    @Configuration
-    public static Option[] configure() {
-        Option[] options = combine(
-            getDefaultCamelKarafOptions(),
-            // using the features to install the other camel components             
-            scanFeatures(getCamelKarafFeatureUrl(), "camel-velocity"));
-        
-        return options;
-    }
-    
-   
+
 }
\ No newline at end of file