Author: hlship
Date: Mon Apr 19 14:06:32 2010
New Revision: 935581
URL: http://svn.apache.org/viewvc?rev=935581&view=rev
Log:
Get all unit tests working again. Many integration tests are still broken,
waiting for stack assets to be implemented.
Removed:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClientInfrastructureImplTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/PartialDocumentLinkerImplTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_in_development_mode.txt
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/duplicate_script_links_ignored.txt
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/duplicate_scripts_ignored_first_media_wins.txt
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java?rev=935581&r1=935580&r2=935581&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.java
Mon Apr 19 14:06:32 2010
@@ -216,26 +216,6 @@ public class DocumentLinkerImplTest exte
}
@Test
- public void duplicate_scripts_ignored_first_media_wins() throws Exception
- {
- Document document = new Document(new XMLMarkupModel());
-
-
document.newRootElement("html").element("body").element("p").text("Ready to be
updated with styles.");
-
- DocumentLinkerImpl linker = new DocumentLinkerImpl(true, "1.2.3");
-
- 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");
-
- linker.updateDocument(document);
-
- check(document, "duplicate_scripts_ignored_first_media_wins.txt");
- }
-
- @Test
public void existing_head_used_if_present() throws Exception
{
Document document = new Document(new XMLMarkupModel());
@@ -253,27 +233,6 @@ public class DocumentLinkerImplTest exte
}
@Test
- public void duplicate_script_links_ignored() throws Exception
- {
- Document document = new Document();
-
-
document.newRootElement("html").element("body").element("p").text("Ready to be
updated with scripts.");
-
- DocumentLinkerImpl linker = new DocumentLinkerImpl(true, "1.2.3");
-
- for (int i = 0; i < 3; i++)
- {
- linker.addScriptLink("foo.js");
- linker.addScriptLink("bar/baz.js");
- linker.addScriptLink("biff.js");
- }
-
- linker.updateDocument(document);
-
- check(document, "duplicate_script_links_ignored.txt");
- }
-
- @Test
public void add_script() throws Exception
{
Document document = new Document();
@@ -290,22 +249,6 @@ public class DocumentLinkerImplTest exte
assertEquals(document.toString(), readFile("add_script.txt").trim());
}
- @Test
- public void add_script_in_development_mode() throws Exception
- {
- Document document = new Document();
-
-
document.newRootElement("html").element("body").element("p").text("Ready to be
updated with scripts.");
-
- DocumentLinkerImpl linker = new DocumentLinkerImpl(true, "1.2.3");
-
- linker.addScriptLink("foo.js");
-
- linker.updateDocument(document);
-
- assertEquals(document.toString(),
readFile("add_script_in_development_mode.txt").trim());
- }
-
/**
* Perhaps the linker should create the <body> element in this case?
In the meantime,
*/
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java?rev=935581&r1=935580&r2=935581&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java
Mon Apr 19 14:06:32 2010
@@ -108,15 +108,14 @@ public class RenderSupportImplTest exten
public void add_stylesheet_link_by_asset()
{
String media = "print";
- DocumentLinker linker = mockDocumentLinker();
+ JavascriptSupport javascriptSupport = mockJavascriptSupport();
Asset asset = mockAsset();
- train_toClientURL(asset, ASSET_URL);
- linker.addStylesheetLink(ASSET_URL, media);
+ javascriptSupport.importStylesheet(asset, media);
replay();
- RenderSupport support = new RenderSupportImpl(null, null, null);
+ RenderSupport support = new RenderSupportImpl(null, null,
javascriptSupport);
support.addStylesheetLink(asset, media);
@@ -127,13 +126,13 @@ public class RenderSupportImplTest exten
public void add_stylesheet_link_by_url()
{
String media = "print";
- DocumentLinker linker = mockDocumentLinker();
+ JavascriptSupport javascriptSupport = mockJavascriptSupport();
- linker.addStylesheetLink(ASSET_URL, media);
+ javascriptSupport.importStylesheet(ASSET_URL, media);
replay();
- RenderSupport support = new RenderSupportImpl(null, null, null);
+ RenderSupport support = new RenderSupportImpl(null, null,
javascriptSupport);
support.addStylesheetLink(ASSET_URL, media);
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java?rev=935581&r1=935580&r2=935581&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
Mon Apr 19 14:06:32 2010
@@ -14,22 +14,27 @@
package org.apache.tapestry5.internal.services.ajax;
+import java.util.Collections;
import java.util.List;
import org.apache.tapestry5.Asset;
import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.internal.InternalConstants;
import org.apache.tapestry5.internal.services.DocumentLinker;
import org.apache.tapestry5.internal.services.ajax.JavascriptSupportImpl;
+import
org.apache.tapestry5.internal.services.javascript.JavascriptStackPathConstructor;
import org.apache.tapestry5.internal.test.InternalBaseTestCase;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.IdAllocator;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.ClientInfrastructure;
import org.apache.tapestry5.services.javascript.InitializationPriority;
+import org.apache.tapestry5.services.javascript.JavascriptStack;
+import org.apache.tapestry5.services.javascript.JavascriptStackSource;
import org.apache.tapestry5.services.javascript.JavascriptSupport;
import org.testng.annotations.Test;
-public class JavaScriptSupportImplTest extends InternalBaseTestCase
+public class JavascriptSupportImplTest extends InternalBaseTestCase
{
@Test
public void allocate_id_from_resources()
@@ -52,23 +57,15 @@ public class JavaScriptSupportImplTest e
@Test
public void commit_with_no_javascript()
{
- DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
-
- replay();
-
- JavascriptSupportImpl jss = new JavascriptSupportImpl(linker, null,
null);
+ JavascriptSupportImpl jss = new JavascriptSupportImpl(null, null,
null);
jss.commit();
-
- verify();
}
@Test
public void no_stack_or_dom_loading_callback_in_partial_mode()
{
DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
linker.addScript("doSomething();\n");
@@ -87,15 +84,15 @@ public class JavaScriptSupportImplTest e
public void adding_script_will_add_stack()
{
DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
+ JavascriptStackSource stackSource = mockJavascriptStackSource();
+ JavascriptStackPathConstructor pathConstructor =
mockJavascriptStackPathConstructor();
+ trainForCoreStack(linker, stackSource, pathConstructor);
- train_for_stack(infra, linker);
-
- linker.addScript("Tapestry.onDOMLoaded(function()
{\ndoSomething();\n});");
+ linker.addScript("stackInit();\nTapestry.onDOMLoaded(function()
{\ndoSomething();\n});");
replay();
- JavascriptSupportImpl jss = new JavascriptSupportImpl(linker, null,
null);
+ JavascriptSupportImpl jss = new JavascriptSupportImpl(linker,
stackSource, pathConstructor);
jss.addScript("doSomething();");
@@ -104,19 +101,69 @@ public class JavaScriptSupportImplTest e
verify();
}
+ private void trainForEmptyCoreStack(DocumentLinker linker,
JavascriptStackSource stackSource,
+ JavascriptStackPathConstructor pathConstructor)
+ {
+ JavascriptStack stack = mockJavascriptStack();
+
+ List<String> libraryPaths = Collections.emptyList();
+ List<Asset> stylesheets = Collections.emptyList();
+
+
expect(stackSource.getStack(InternalConstants.CORE_STACK_NAME)).andReturn(stack);
+
expect(pathConstructor.constructPathsForJavascriptStack(InternalConstants.CORE_STACK_NAME)).andReturn(
+ libraryPaths);
+ expect(stack.getStylesheets()).andReturn(stylesheets);
+
+ expect(stack.getInitialization()).andReturn(null);
+ }
+
+ private void trainForCoreStack(DocumentLinker linker,
JavascriptStackSource stackSource,
+ JavascriptStackPathConstructor pathConstructor)
+ {
+ JavascriptStack stack = mockJavascriptStack();
+
+ Asset stylesheet = mockAsset("style.css");
+
+
expect(stackSource.getStack(InternalConstants.CORE_STACK_NAME)).andReturn(stack);
+
expect(pathConstructor.constructPathsForJavascriptStack(InternalConstants.CORE_STACK_NAME)).andReturn(
+ CollectionFactory.newList("stack1.js", "stack2.js"));
+
expect(stack.getStylesheets()).andReturn(CollectionFactory.newList(stylesheet));
+
+ expect(stack.getInitialization()).andReturn("stackInit();");
+
+ linker.addScriptLink("stack1.js");
+ linker.addScriptLink("stack2.js");
+ linker.addStylesheetLink("style.css", null);
+ }
+
+ private JavascriptStack mockJavascriptStack()
+ {
+ return newMock(JavascriptStack.class);
+ }
+
+ private JavascriptStackPathConstructor mockJavascriptStackPathConstructor()
+ {
+ return newMock(JavascriptStackPathConstructor.class);
+ }
+
+ protected JavascriptStackSource mockJavascriptStackSource()
+ {
+ return newMock(JavascriptStackSource.class);
+ }
+
@Test
public void only_immediate_script_added()
{
DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
-
- train_for_stack(infra, linker);
+ JavascriptStackSource stackSource = mockJavascriptStackSource();
+ JavascriptStackPathConstructor pathConstructor =
mockJavascriptStackPathConstructor();
+ trainForEmptyCoreStack(linker, stackSource, pathConstructor);
linker.addScript("doSomething();\n");
replay();
- JavascriptSupportImpl jss = new JavascriptSupportImpl(linker, null,
null);
+ JavascriptSupportImpl jss = new JavascriptSupportImpl(linker,
stackSource, pathConstructor);
jss.addScript(InitializationPriority.IMMEDIATE, "doSomething();");
@@ -129,16 +176,16 @@ public class JavaScriptSupportImplTest e
public void script_within_priority_accumulates()
{
DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
-
- train_for_stack(infra, linker);
+ JavascriptStackSource stackSource = mockJavascriptStackSource();
+ JavascriptStackPathConstructor pathConstructor =
mockJavascriptStackPathConstructor();
+ trainForEmptyCoreStack(linker, stackSource, pathConstructor);
linker
.addScript("immediate1();\nimmediate2();\nTapestry.onDOMLoaded(function()
{\nnormal1();\nnormal2();\n});");
replay();
- JavascriptSupportImpl jss = new JavascriptSupportImpl(linker, null,
null);
+ JavascriptSupportImpl jss = new JavascriptSupportImpl(linker,
stackSource, pathConstructor);
jss.addScript(InitializationPriority.IMMEDIATE, "immediate1();");
jss.addScript("normal1();");
@@ -154,15 +201,15 @@ public class JavaScriptSupportImplTest e
public void priority_order()
{
DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
-
- train_for_stack(infra, linker);
+ JavascriptStackSource stackSource = mockJavascriptStackSource();
+ JavascriptStackPathConstructor pathConstructor =
mockJavascriptStackPathConstructor();
+ trainForCoreStack(linker, stackSource, pathConstructor);
- linker.addScript("Tapestry.onDOMLoaded(function()
{\nearly();\nnormal();\nlate();\n});");
+ linker.addScript("stackInit();\nTapestry.onDOMLoaded(function()
{\nearly();\nnormal();\nlate();\n});");
replay();
- JavascriptSupportImpl jss = new JavascriptSupportImpl(linker, null,
null);
+ JavascriptSupportImpl jss = new JavascriptSupportImpl(linker,
stackSource, pathConstructor);
jss.addScript(InitializationPriority.EARLY, "early();");
jss.addScript(InitializationPriority.NORMAL, "normal();");
@@ -177,16 +224,17 @@ public class JavaScriptSupportImplTest e
public void import_library()
{
DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
- Asset library = mockAsset("mylib.js");
+ JavascriptStackSource stackSource = mockJavascriptStackSource();
+ JavascriptStackPathConstructor pathConstructor =
mockJavascriptStackPathConstructor();
+ trainForEmptyCoreStack(linker, stackSource, pathConstructor);
- train_for_stack(infra, linker);
+ Asset library = mockAsset("mylib.js");
linker.addScriptLink("mylib.js");
replay();
- JavascriptSupportImpl jss = new JavascriptSupportImpl(linker, null,
null);
+ JavascriptSupportImpl jss = new JavascriptSupportImpl(linker,
stackSource, pathConstructor);
jss.importJavascriptLibrary(library);
@@ -198,18 +246,18 @@ public class JavaScriptSupportImplTest e
@Test
public void init_once()
{
- JSONObject spec = new JSONObject("clientId", "chuck");
-
DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
+ JavascriptStackSource stackSource = mockJavascriptStackSource();
+ JavascriptStackPathConstructor pathConstructor =
mockJavascriptStackPathConstructor();
+ trainForEmptyCoreStack(linker, stackSource, pathConstructor);
- train_for_stack(infra, linker);
+ JSONObject spec = new JSONObject("clientId", "chuck");
linker.addScript("Tapestry.init({\"setup\":[{\"clientId\":\"chuck\"}]});\n");
replay();
- JavascriptSupportImpl jss = new JavascriptSupportImpl(linker, null,
null);
+ JavascriptSupportImpl jss = new JavascriptSupportImpl(linker,
stackSource, pathConstructor);
jss.addInitializerCall(InitializationPriority.IMMEDIATE, "setup",
spec);
@@ -221,16 +269,17 @@ public class JavaScriptSupportImplTest e
@Test
public void init_with_string()
{
- DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
- train_for_stack(infra, linker);
+ DocumentLinker linker = mockDocumentLinker();
+ JavascriptStackSource stackSource = mockJavascriptStackSource();
+ JavascriptStackPathConstructor pathConstructor =
mockJavascriptStackPathConstructor();
+ trainForEmptyCoreStack(linker, stackSource, pathConstructor);
linker.addScript("Tapestry.init({\"setup\":[\"chuck\"]});\n");
replay();
- JavascriptSupportImpl jss = new JavascriptSupportImpl(linker, null,
null);
+ JavascriptSupportImpl jss = new JavascriptSupportImpl(linker,
stackSource, pathConstructor);
jss.addInitializerCall(InitializationPriority.IMMEDIATE, "setup",
"chuck");
@@ -242,17 +291,16 @@ public class JavaScriptSupportImplTest e
@Test
public void init_with_string_multiple()
{
-
DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
-
- train_for_stack(infra, linker);
+ JavascriptStackSource stackSource = mockJavascriptStackSource();
+ JavascriptStackPathConstructor pathConstructor =
mockJavascriptStackPathConstructor();
+ trainForEmptyCoreStack(linker, stackSource, pathConstructor);
linker.addScript("Tapestry.init({\"setup\":[\"chuck\",\"pat\"]});\n");
replay();
- JavascriptSupportImpl jss = new JavascriptSupportImpl(linker, null,
null);
+ JavascriptSupportImpl jss = new JavascriptSupportImpl(linker,
stackSource, pathConstructor);
jss.addInitializerCall(InitializationPriority.IMMEDIATE, "setup",
"chuck");
jss.addInitializerCall(InitializationPriority.IMMEDIATE, "setup",
"pat");
@@ -266,15 +314,15 @@ public class JavaScriptSupportImplTest e
public void default_for_init_string_is_normal_priority()
{
DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
-
- train_for_stack(infra, linker);
+ JavascriptStackSource stackSource = mockJavascriptStackSource();
+ JavascriptStackPathConstructor pathConstructor =
mockJavascriptStackPathConstructor();
+ trainForEmptyCoreStack(linker, stackSource, pathConstructor);
linker.addScript("Tapestry.onDOMLoaded(function()
{\nTapestry.init({\"setup\":[\"chuck\"]});\n});");
replay();
- JavascriptSupportImpl jss = new JavascriptSupportImpl(linker, null,
null);
+ JavascriptSupportImpl jss = new JavascriptSupportImpl(linker,
stackSource, pathConstructor);
jss.addInitializerCall("setup", "chuck");
@@ -286,19 +334,19 @@ public class JavaScriptSupportImplTest e
@Test
public void init_multiple()
{
- JSONObject spec1 = new JSONObject("clientId", "chuck");
- JSONObject spec2 = new JSONObject("clientId", "tony");
-
DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
+ JavascriptStackSource stackSource = mockJavascriptStackSource();
+ JavascriptStackPathConstructor pathConstructor =
mockJavascriptStackPathConstructor();
+ trainForEmptyCoreStack(linker, stackSource, pathConstructor);
- train_for_stack(infra, linker);
+ JSONObject spec1 = new JSONObject("clientId", "chuck");
+ JSONObject spec2 = new JSONObject("clientId", "tony");
linker.addScript("Tapestry.init({\"setup\":[{\"clientId\":\"chuck\"},{\"clientId\":\"tony\"}]});\n");
replay();
- JavascriptSupportImpl jss = new JavascriptSupportImpl(linker, null,
null);
+ JavascriptSupportImpl jss = new JavascriptSupportImpl(linker,
stackSource, pathConstructor);
jss.addInitializerCall(InitializationPriority.IMMEDIATE, "setup",
spec1);
jss.addInitializerCall(InitializationPriority.IMMEDIATE, "setup",
spec2);
@@ -313,9 +361,9 @@ public class JavaScriptSupportImplTest e
{
DocumentLinker linker = mockDocumentLinker();
- ClientInfrastructure infra = mockClientInfrastucture();
-
- train_for_stack(infra, linker);
+ JavascriptStackSource stackSource = mockJavascriptStackSource();
+ JavascriptStackPathConstructor pathConstructor =
mockJavascriptStackPathConstructor();
+ trainForEmptyCoreStack(linker, stackSource, pathConstructor);
linker.addScript("Tapestry.onDOMLoaded(function()
{\nTapestry.init({\"early\":[{\"id\":\"foo\"}]});\n"
+ "Tapestry.init({\"normal\":[{\"id\":\"bar\"}]});\n"
@@ -323,7 +371,7 @@ public class JavaScriptSupportImplTest e
replay();
- JavascriptSupportImpl jss = new JavascriptSupportImpl(linker, null,
null);
+ JavascriptSupportImpl jss = new JavascriptSupportImpl(linker,
stackSource, pathConstructor);
jss.addInitializerCall(InitializationPriority.EARLY, "early", new
JSONObject("id", "foo"));
jss.addInitializerCall("normal", new JSONObject("id", "bar"));