- Revision
- 682
- Author
- mauro
- Date
- 2008-05-19 11:39:54 -0500 (Mon, 19 May 2008)
Log Message
WAFFLE-81: Added export methods to ViewHarness.
Modified Paths
Diff
Modified: trunk/waffle-testing/src/main/java/org/codehaus/waffle/testing/view/ViewHarness.java (681 => 682)
--- trunk/waffle-testing/src/main/java/org/codehaus/waffle/testing/view/ViewHarness.java 2008-05-16 13:20:59 UTC (rev 681) +++ trunk/waffle-testing/src/main/java/org/codehaus/waffle/testing/view/ViewHarness.java 2008-05-19 16:39:54 UTC (rev 682) @@ -1,5 +1,10 @@ package org.codehaus.waffle.testing.view; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + import org.codehaus.waffle.testing.view.freemarker.FreemarkerProcessor; /** @@ -42,11 +47,11 @@ } /** - * Static entry point to ViewHarness + * Processes a view * * @param resource the template resource path * @param controller the controller instance - * @param debug the debug boolean flag + * @param debug the debug boolean flag * @return The processed resource */ public static String processView(String resource, Object controller, boolean debug) { @@ -56,4 +61,31 @@ } return processed; } + + /** + * Exports a view to a file + * + * @param resource the template resource path + * @param controller the controller instance + * @param output the File to export view to + * @throws IOException + */ + public static void exportView(String resource, Object controller, File output) throws IOException { + File parent = new File(output.getParent()); + parent.mkdirs(); + exportView(resource, controller, new FileOutputStream(output)); + } + + /** + * Exports a view to an output stream + * + * @param resource the template resource path + * @param controller the controller instance + * @param output the OutputStream to export view to + * @throws IOException + */ + public static void exportView(String resource, Object controller, OutputStream output) throws IOException { + String processed = new ViewHarness().process(resource, controller); + output.write(processed.getBytes()); + } }
Modified: trunk/waffle-testing/src/test/java/org/codehaus/waffle/testing/view/ViewHarnessTest.java (681 => 682)
--- trunk/waffle-testing/src/test/java/org/codehaus/waffle/testing/view/ViewHarnessTest.java 2008-05-16 13:20:59 UTC (rev 681) +++ trunk/waffle-testing/src/test/java/org/codehaus/waffle/testing/view/ViewHarnessTest.java 2008-05-19 16:39:54 UTC (rev 682) @@ -1,7 +1,12 @@ package org.codehaus.waffle.testing.view; +import static org.codehaus.waffle.testing.view.ViewHarness.exportView; import static org.codehaus.waffle.testing.view.ViewHarness.processView; +import static org.junit.Assert.assertTrue; +import java.io.File; +import java.io.IOException; + import org.codehaus.waffle.testing.ListController; import org.junit.Test; @@ -11,11 +16,20 @@ public class ViewHarnessTest { @Test - public void canProcessFreemarkerTemplate() { + public void canProcessFreemarkerView() { ListController controller = new ListController(); controller.list(); processView("freemarker/list.ftl", controller, false); } + @Test + public void canExportView() throws IOException { + ListController controller = new ListController(); + controller.list(); + File output = new File("target/export/list.html"); + exportView("freemarker/list.ftl", controller, output); + assertTrue(output.exists()); + } + }
To unsubscribe from this list please visit:
