Copied: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/DocumentLinkerImplTest.java (from r648325, tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/DocumentHeadBuilderImplTest.java) URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/DocumentLinkerImplTest.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/DocumentLinkerImplTest.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/DocumentHeadBuilderImplTest.java&r1=648325&r2=649837&rev=649837&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/DocumentHeadBuilderImplTest.java (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/DocumentLinkerImplTest.java Sat Apr 19 11:33:09 2008 @@ -19,7 +19,7 @@ import org.apache.tapestry.internal.test.InternalBaseTestCase; import org.testng.annotations.Test; -public class DocumentHeadBuilderImplTest extends InternalBaseTestCase +public class DocumentLinkerImplTest extends InternalBaseTestCase { private void check(Document document, String file) throws Exception { @@ -33,12 +33,12 @@ document.newRootElement("not-html").text("not an HTML document"); - DocumentHeadBuilderImpl builder = new DocumentHeadBuilderImpl(); + DocumentLinkerImpl linker = new DocumentLinkerImpl(); - builder.addScript("foo.js"); - builder.addScript("doSomething();"); + linker.addScript("foo.js"); + linker.addScript("doSomething();"); - builder.updateDocument(document); + linker.updateDocument(document); assertEquals(document.toString(), "<not-html>not an HTML document</not-html>"); } @@ -50,12 +50,12 @@ document.newRootElement("html").element("body").element("p").text("Ready to be updated with scripts."); - DocumentHeadBuilderImpl builder = new DocumentHeadBuilderImpl(); + DocumentLinkerImpl linker = new DocumentLinkerImpl(); - builder.addScriptLink("foo.js"); - builder.addScriptLink("bar/baz.js"); + linker.addScriptLink("foo.js"); + linker.addScriptLink("bar/baz.js"); - builder.updateDocument(document); + linker.updateDocument(document); check(document, "add_script_links.txt"); } @@ -67,12 +67,12 @@ document.newRootElement("html").element("body").element("p").text("Ready to be updated with styles."); - DocumentHeadBuilderImpl builder = new DocumentHeadBuilderImpl(); + DocumentLinkerImpl linker = new DocumentLinkerImpl(); - builder.addStylesheetLink("foo.css", null); - builder.addStylesheetLink("bar/baz.css", "print"); + linker.addStylesheetLink("foo.css", null); + linker.addStylesheetLink("bar/baz.css", "print"); - builder.updateDocument(document); + linker.updateDocument(document); check(document, "add_style_links.txt"); } @@ -84,15 +84,15 @@ document.newRootElement("html").element("body").element("p").text("Ready to be updated with styles."); - DocumentHeadBuilderImpl builder = new DocumentHeadBuilderImpl(); + DocumentLinkerImpl linker = new DocumentLinkerImpl(); - builder.addStylesheetLink("foo.css", null); - builder.addStylesheetLink("bar/baz.css", "print"); - builder.addStylesheetLink("foo.css", "implant"); - builder.addStylesheetLink("bar/baz.css", null); - builder.addStylesheetLink("bar/baz.css", "duplicate"); + linker.addStylesheetLink("foo.css", null); + linker.addStylesheetLink("bar/baz.css", "print"); + linker.addStylesheetLink("foo.css", "implant"); + linker.addStylesheetLink("bar/baz.css", null); + linker.addStylesheetLink("bar/baz.css", "duplicate"); - builder.updateDocument(document); + linker.updateDocument(document); check(document, "duplicate_scripts_ignored_first_media_wins.txt"); } @@ -105,11 +105,11 @@ document.newRootElement("html").element("head").comment("existing head").getParent() .element("body").text("body content"); - DocumentHeadBuilderImpl builder = new DocumentHeadBuilderImpl(); + DocumentLinkerImpl linker = new DocumentLinkerImpl(); - builder.addStylesheetLink("foo.css", null); + linker.addStylesheetLink("foo.css", null); - builder.updateDocument(document); + linker.updateDocument(document); check(document, "existing_head_used_if_present.txt"); } @@ -121,16 +121,16 @@ document.newRootElement("html").element("body").element("p").text("Ready to be updated with scripts."); - DocumentHeadBuilderImpl builder = new DocumentHeadBuilderImpl(); + DocumentLinkerImpl linker = new DocumentLinkerImpl(); for (int i = 0; i < 3; i++) { - builder.addScriptLink("foo.js"); - builder.addScriptLink("bar/baz.js"); - builder.addScriptLink("biff.js"); + linker.addScriptLink("foo.js"); + linker.addScriptLink("bar/baz.js"); + linker.addScriptLink("biff.js"); } - builder.updateDocument(document); + linker.updateDocument(document); check(document, "duplicate_script_links_ignored.txt"); } @@ -142,18 +142,18 @@ document.newRootElement("html").element("body").element("p").text("Ready to be updated with scripts."); - DocumentHeadBuilderImpl builder = new DocumentHeadBuilderImpl(); + DocumentLinkerImpl linker = new DocumentLinkerImpl(); - builder.addScript("doSomething();"); - builder.addScript("doSomethingElse();"); + linker.addScript("doSomething();"); + linker.addScript("doSomethingElse();"); - builder.updateDocument(document); + linker.updateDocument(document); assertEquals(document.toString(), readFile("add_script.txt").trim()); } /** - * Perhaps the builder should create the <body> element in this case? In the meantime, + * Perhaps the linker should create the <body> element in this case? In the meantime, */ @Test public void no_body_element() throws Exception @@ -162,11 +162,11 @@ document.newRootElement("html").element("notbody").element("p").text("Ready to be updated with scripts."); - DocumentHeadBuilderImpl builder = new DocumentHeadBuilderImpl(); + DocumentLinkerImpl linker = new DocumentLinkerImpl(); - builder.addScriptLink("foo.js"); + linker.addScriptLink("foo.js"); - builder.updateDocument(document); + linker.updateDocument(document); check(document, "no_body_element.txt"); }
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageRenderSupportImplTest.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageRenderSupportImplTest.java?rev=649837&r1=649836&r2=649837&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageRenderSupportImplTest.java (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageRenderSupportImplTest.java Sat Apr 19 11:33:09 2008 @@ -34,15 +34,15 @@ @Test public void add_script_link_by_asset() { - DocumentHeadBuilder builder = mockDocumentScriptBuilder(); + DocumentLinker linker = mockDocumentLinker(); Asset asset = mockAsset(); train_toClientURL(asset, ASSET_URL); - builder.addScriptLink(ASSET_URL); + linker.addScriptLink(ASSET_URL); replay(); - PageRenderSupport support = new PageRenderSupportImpl(builder, null, null); + PageRenderSupport support = new PageRenderSupportImpl(linker, null, null); support.addScriptLink(asset); @@ -55,7 +55,7 @@ getMocksControl().checkOrder(true); Asset coreAsset = mockAsset(); - DocumentHeadBuilder builder = mockDocumentScriptBuilder(); + DocumentLinker linker = mockDocumentLinker(); Asset asset = mockAsset(); AssetSource assetSource = mockAssetSource(); SymbolSource symbolSource = mockSymbolSource(); @@ -64,14 +64,14 @@ train_getAsset(assetSource, null, CORE_ASSET_PATH, null, coreAsset); train_toClientURL(coreAsset, CORE_ASSET_URL); - builder.addScriptLink(CORE_ASSET_URL); + linker.addScriptLink(CORE_ASSET_URL); train_toClientURL(asset, ASSET_URL); - builder.addScriptLink(ASSET_URL); + linker.addScriptLink(ASSET_URL); replay(); - PageRenderSupport support = new PageRenderSupportImpl(builder, symbolSource, assetSource, + PageRenderSupport support = new PageRenderSupportImpl(linker, symbolSource, assetSource, CORE_ASSET_PATH_UNEXPANDED); support.addScriptLink(asset); @@ -82,13 +82,13 @@ @Test public void add_script() { - DocumentHeadBuilder builder = mockDocumentScriptBuilder(); + DocumentLinker linker = mockDocumentLinker(); - builder.addScript("Tapestry.Foo(\"bar\");"); + linker.addScript("Tapestry.Foo(\"bar\");"); replay(); - PageRenderSupport support = new PageRenderSupportImpl(builder, null, null); + PageRenderSupport support = new PageRenderSupportImpl(linker, null, null); support.addScript("Tapestry.Foo(\"%s\");", "bar"); @@ -101,7 +101,7 @@ String path = "${root}/foo/bar.pdf"; String expanded = "org/apache/tapestry/foo/bar.pdf"; - DocumentHeadBuilder builder = mockDocumentScriptBuilder(); + DocumentLinker linker = mockDocumentLinker(); Asset asset = mockAsset(); SymbolSource source = mockSymbolSource(); AssetSource assetSource = mockAssetSource(); @@ -111,11 +111,11 @@ train_getAsset(assetSource, null, expanded, null, asset); train_toClientURL(asset, ASSET_URL); - builder.addScriptLink(ASSET_URL); + linker.addScriptLink(ASSET_URL); replay(); - PageRenderSupport support = new PageRenderSupportImpl(builder, source, assetSource); + PageRenderSupport support = new PageRenderSupportImpl(linker, source, assetSource); support.addClasspathScriptLink(path); @@ -126,17 +126,54 @@ public void add_stylesheet_link() { String media = "print"; - DocumentHeadBuilder builder = mockDocumentScriptBuilder(); + DocumentLinker linker = mockDocumentLinker(); Asset asset = mockAsset(); train_toClientURL(asset, ASSET_URL); - builder.addStylesheetLink(ASSET_URL, media); + linker.addStylesheetLink(ASSET_URL, media); replay(); - PageRenderSupport support = new PageRenderSupportImpl(builder, null, null); + PageRenderSupport support = new PageRenderSupportImpl(linker, null, null); support.addStylesheetLink(asset, media); + + verify(); + } + + @Test + public void add_init_with_single_string_parameter() + { + DocumentLinker linker = mockDocumentLinker(); + + linker.addScript("Tapestry.init({\"foo\":[\"fred\",\"barney\"]});"); + + replay(); + + PageRenderSupportImpl support = new PageRenderSupportImpl(linker, null, null); + + support.addInit("foo", "fred"); + support.addInit("foo", "barney"); + + support.commit(); + + verify(); + } + + @Test + public void add_multiple_string_init_parameters() + { + DocumentLinker linker = mockDocumentLinker(); + + linker.addScript("Tapestry.init({\"foo\":[[\"fred\",\"barney\"]]});"); + + replay(); + + PageRenderSupportImpl support = new PageRenderSupportImpl(linker, null, null); + + support.addInit("foo", "fred", "barney"); + + support.commit(); verify(); } Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java?rev=649837&r1=649836&r2=649837&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/test/InternalBaseTestCase.java Sat Apr 19 11:33:09 2008 @@ -497,9 +497,9 @@ return buffer.toString().trim(); } - protected final DocumentHeadBuilder mockDocumentScriptBuilder() + protected final DocumentLinker mockDocumentLinker() { - return newMock(DocumentHeadBuilder.class); + return newMock(DocumentLinker.class); } protected final void train_canonicalizePageName(ComponentClassResolver resolver, String pageName, Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/add_script_links.txt URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/add_script_links.txt?rev=649837&r1=649836&r2=649837&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/add_script_links.txt (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/add_script_links.txt Sat Apr 19 11:33:09 2008 @@ -1,2 +1,2 @@ <?xml version="1.0"?> -<html><body><script src="foo.js" type="text/javascript"/><script src="bar/baz.js" type="text/javascript"/><p>Ready to be updated with scripts.</p></body></html> \ No newline at end of file +<html><body><p>Ready to be updated with scripts.</p><script src="foo.js" type="text/javascript"/><script src="bar/baz.js" type="text/javascript"/></body></html> \ No newline at end of file Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/duplicate_script_links_ignored.txt URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/duplicate_script_links_ignored.txt?rev=649837&r1=649836&r2=649837&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/duplicate_script_links_ignored.txt (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/duplicate_script_links_ignored.txt Sat Apr 19 11:33:09 2008 @@ -1 +1 @@ -<html><body><script src="foo.js" type="text/javascript"></script><script src="bar/baz.js" type="text/javascript"></script><script src="biff.js" type="text/javascript"></script><p>Ready to be updated with scripts.</p></body></html> \ No newline at end of file +<html><body><p>Ready to be updated with scripts.</p><script src="foo.js" type="text/javascript"></script><script src="bar/baz.js" type="text/javascript"></script><script src="biff.js" type="text/javascript"></script></body></html> \ No newline at end of file
