You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2010/02/05 19:56:22 UTC
svn commit: r907052 [3/3] - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/ main/java/org/apache/tapestry5/corelib/
main/java/org/apache/tapestry5/internal/services/
main/java/org/apache/tapestry5/services/ main/java/org...
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=907052&r1=907051&r2=907052&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 Fri Feb 5 18:56:21 2010
@@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,8 +19,11 @@
import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.internal.test.InternalBaseTestCase;
import org.apache.tapestry5.ioc.services.SymbolSource;
+import org.apache.tapestry5.json.JSONArray;
+import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.AssetSource;
import org.apache.tapestry5.services.ClientInfrastructure;
+import org.apache.tapestry5.services.javascript.JavascriptSupport;
import org.testng.annotations.Test;
import java.util.Arrays;
@@ -29,20 +32,17 @@
{
private static final String ASSET_URL = "/assets/foo/bar.pdf";
- private static final EmptyClientInfrastructure EMPTY_CLIENT_INFRASTRUCTURE = new EmptyClientInfrastructure();
-
@Test
public void add_script_link_by_asset()
{
- DocumentLinker linker = mockDocumentLinker();
+ JavascriptSupport js = mockJavascriptSupport();
Asset asset = mockAsset();
- train_toClientURL(asset, ASSET_URL);
- linker.addScriptLink(ASSET_URL);
+ js.importJavascriptLibrary(asset);
replay();
- RenderSupport support = new RenderSupportImpl(linker, null, null, EMPTY_CLIENT_INFRASTRUCTURE);
+ RenderSupport support = new RenderSupportImpl(null, null, null, js);
support.addScriptLink(asset);
@@ -50,149 +50,57 @@
}
@Test
- public void add_script_link_by_url()
+ public void add_script_link_by_url_fails()
{
- DocumentLinker linker = mockDocumentLinker();
-
- linker.addScriptLink(ASSET_URL);
-
- replay();
-
- RenderSupport support = new RenderSupportImpl(linker, null, null, EMPTY_CLIENT_INFRASTRUCTURE);
-
- support.addScriptLink(ASSET_URL);
-
- verify();
- }
-
- @Test
- public void core_assets_added()
- {
- getMocksControl().checkOrder(true);
-
- String coreURL1 = "/foo/core1.js";
- String coreURL2 = "/foo/core2.js";
-
- Asset asset = mockAsset();
-
- DocumentLinker linker = mockDocumentLinker();
-
- Asset coreAsset1 = mockAsset();
- Asset coreAsset2 = mockAsset();
-
- AssetSource assetSource = mockAssetSource();
- SymbolSource symbolSource = mockSymbolSource();
+ RenderSupport support = new RenderSupportImpl(null, null, null, null);
- ClientInfrastructure infrastructure = mockJavascriptStack(coreAsset1, coreAsset2);
-
- train_toClientURL(coreAsset1, coreURL1);
- linker.addScriptLink(coreURL1);
-
- train_toClientURL(coreAsset2, coreURL2);
- linker.addScriptLink(coreURL2);
-
- train_toClientURL(asset, ASSET_URL);
- linker.addScriptLink(ASSET_URL);
-
- replay();
-
- RenderSupport support = new RenderSupportImpl(linker, symbolSource, assetSource, infrastructure);
-
- support.addScriptLink(asset);
-
- verify();
+ try
+ {
+ support.addScriptLink(ASSET_URL);
+ unreachable();
+ }
+ catch (RuntimeException ex)
+ {
+ assertMessageContains(ex, "no longer supported");
+ }
}
@Test
public void add_script()
{
- String coreScript = "corescript.js";
-
- DocumentLinker linker = mockDocumentLinker();
- SymbolSource symbolSource = mockSymbolSource();
- AssetSource assetSource = mockAssetSource();
- Asset coreAsset = mockAsset(coreScript);
- ClientInfrastructure infrastructure = mockJavascriptStack(coreAsset);
-
- linker.addScriptLink(coreScript);
- linker.addScript("Tapestry.Foo(\"bar\");");
-
- replay();
-
- RenderSupport support = new RenderSupportImpl(linker, symbolSource, assetSource, infrastructure);
-
- support.addScript("Tapestry.Foo(\"%s\");", "bar");
-
- verify();
- }
-
- // TAPESTRY-2483
-
- @Test
- public void add_script_no_formatting()
- {
- String coreScript = "corescript.js";
- DocumentLinker linker = mockDocumentLinker();
- SymbolSource symbolSource = mockSymbolSource();
- AssetSource assetSource = mockAssetSource();
- Asset coreAsset = mockAsset(coreScript);
-
- ClientInfrastructure infrastructure = mockJavascriptStack(coreAsset);
+ JavascriptSupport js = mockJavascriptSupport();
- linker.addScriptLink(coreScript);
-
- String script = "foo('%');";
-
- linker.addScript(script);
+ js.addScript("doSomething();");
replay();
- RenderSupport support = new RenderSupportImpl(linker, symbolSource, assetSource, infrastructure);
+ RenderSupport support = new RenderSupportImpl(null, null, null, js);
- support.addScript(script);
+ support.addScript("doSomething();");
verify();
}
- protected final ClientInfrastructure mockJavascriptStack(Asset... asset)
- {
- ClientInfrastructure infrastructure = newMock(ClientInfrastructure.class);
-
- expect(infrastructure.getJavascriptStack()).andReturn(Arrays.asList(asset)).atLeastOnce();
-
- return infrastructure;
- }
-
- protected final Asset mockAsset(String assetURL)
- {
- Asset asset = mockAsset();
-
- train_toClientURL(asset, assetURL);
-
- return asset;
- }
-
@Test
public void add_classpath_script_link()
{
String path = "${root}/foo/bar.pdf";
String expanded = "org/apache/tapestry5/foo/bar.pdf";
- DocumentLinker linker = mockDocumentLinker();
Asset asset = mockAsset();
SymbolSource source = mockSymbolSource();
AssetSource assetSource = mockAssetSource();
+ JavascriptSupport js = mockJavascriptSupport();
train_expandSymbols(source, path, expanded);
train_getAsset(assetSource, null, expanded, null, asset);
- train_toClientURL(asset, ASSET_URL);
- linker.addScriptLink(ASSET_URL);
+ js.importJavascriptLibrary(asset);
replay();
- RenderSupport support = new RenderSupportImpl(linker, source, assetSource, EMPTY_CLIENT_INFRASTRUCTURE);
+ RenderSupport support = new RenderSupportImpl(null, source, assetSource, js);
support.addClasspathScriptLink(path);
@@ -211,7 +119,7 @@
replay();
- RenderSupport support = new RenderSupportImpl(linker, null, null, EMPTY_CLIENT_INFRASTRUCTURE);
+ RenderSupport support = new RenderSupportImpl(linker, null, null, null);
support.addStylesheetLink(asset, media);
@@ -228,7 +136,7 @@
replay();
- RenderSupport support = new RenderSupportImpl(linker, null, null, EMPTY_CLIENT_INFRASTRUCTURE);
+ RenderSupport support = new RenderSupportImpl(linker, null, null, null);
support.addStylesheetLink(ASSET_URL, media);
@@ -236,18 +144,19 @@
}
@Test
- public void add_init_with_single_string_parameter()
+ public void add_multiple_string_init_parameters()
{
- DocumentLinker linker = mockDocumentLinker();
+ JavascriptSupport js = mockJavascriptSupport();
- linker.addScript("Tapestry.init({\"foo\":[\"fred\",\"barney\"]});");
+ JSONObject spec = new JSONObject().put("foo", new JSONArray().put(new JSONArray("fred", "barney")));
+
+ js.addScript("Tapestry.init(%s);", spec);
replay();
- RenderSupportImpl support = new RenderSupportImpl(linker, null, null, EMPTY_CLIENT_INFRASTRUCTURE);
+ RenderSupportImpl support = new RenderSupportImpl(null, null, null, js);
- support.addInit("foo", "fred");
- support.addInit("foo", "barney");
+ support.addInit("foo", "fred", "barney");
support.commit();
@@ -255,17 +164,17 @@
}
@Test
- public void add_multiple_string_init_parameters()
+ public void field_focus()
{
- DocumentLinker linker = mockDocumentLinker();
+ JavascriptSupport js = mockJavascriptSupport();
- linker.addScript("Tapestry.init({\"foo\":[[\"fred\",\"barney\"]]});");
+ js.addScript("$('%s').activate();", "foo");
replay();
- RenderSupportImpl support = new RenderSupportImpl(linker, null, null, EMPTY_CLIENT_INFRASTRUCTURE);
+ RenderSupportImpl support = new RenderSupportImpl(null, null, null, js);
- support.addInit("foo", "fred", "barney");
+ support.autofocus(FieldFocusPriority.OPTIONAL, "foo");
support.commit();
@@ -273,17 +182,18 @@
}
@Test
- public void field_focus()
+ public void first_focus_field_at_priority_wins()
{
- DocumentLinker linker = mockDocumentLinker();
+ JavascriptSupport js = mockJavascriptSupport();
- linker.addScript("$('foo').activate();");
+ js.addScript("$('%s').activate();", "foo");
replay();
- RenderSupportImpl support = new RenderSupportImpl(linker, null, null, EMPTY_CLIENT_INFRASTRUCTURE);
+ RenderSupportImpl support = new RenderSupportImpl(null, null, null, js);
support.autofocus(FieldFocusPriority.OPTIONAL, "foo");
+ support.autofocus(FieldFocusPriority.OPTIONAL, "bar");
support.commit();
@@ -291,18 +201,18 @@
}
@Test
- public void first_focus_field_at_priority_wins()
+ public void higher_priority_wins_focus()
{
- DocumentLinker linker = mockDocumentLinker();
+ JavascriptSupport js = mockJavascriptSupport();
- linker.addScript("$('foo').activate();");
+ js.addScript("$('%s').activate();", "bar");
replay();
- RenderSupportImpl support = new RenderSupportImpl(linker, null, null, EMPTY_CLIENT_INFRASTRUCTURE);
+ RenderSupportImpl support = new RenderSupportImpl(null, null, null, js);
support.autofocus(FieldFocusPriority.OPTIONAL, "foo");
- support.autofocus(FieldFocusPriority.OPTIONAL, "bar");
+ support.autofocus(FieldFocusPriority.REQUIRED, "bar");
support.commit();
@@ -310,20 +220,19 @@
}
@Test
- public void higher_priority_wins_focus()
+ public void addInit_passes_through_to_JavascriptSupport()
{
- DocumentLinker linker = mockDocumentLinker();
+ JSONObject parameter = new JSONObject("clientid", "fred");
- linker.addScript("$('bar').activate();");
+ JavascriptSupport js = mockJavascriptSupport();
+
+ js.addInitializerCall("setup", parameter);
replay();
- RenderSupportImpl support = new RenderSupportImpl(linker, null, null, EMPTY_CLIENT_INFRASTRUCTURE);
+ RenderSupportImpl support = new RenderSupportImpl(null, null, null, js);
- support.autofocus(FieldFocusPriority.OPTIONAL, "foo");
- support.autofocus(FieldFocusPriority.REQUIRED, "bar");
-
- support.commit();
+ support.addInit("setup", parameter);
verify();
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/javascript/JavaScriptSupportImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/javascript/JavaScriptSupportImplTest.java?rev=907052&r1=907051&r2=907052&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/javascript/JavaScriptSupportImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/javascript/JavaScriptSupportImplTest.java Fri Feb 5 18:56:21 2010
@@ -268,15 +268,6 @@
verify();
}
- private Asset mockAsset(String clientURL)
- {
- Asset asset = mockAsset();
-
- train_toClientURL(asset, clientURL);
-
- return asset;
- }
-
private void train_for_stack(ClientInfrastructure infra, DocumentLinker linker)
{
Asset asset1 = mockAsset("script1.js");
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/TriggerDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/TriggerDemo.tml?rev=907052&r1=907051&r2=907052&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/TriggerDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/TriggerDemo.tml Fri Feb 5 18:56:21 2010
@@ -1,8 +1,6 @@
<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<h1>Trigger Demo</h1>
-
- <t:trigger event="addAdditionalScriptLinks"/>
-
+
<t:trigger t:id="provideAdditionalMarkup"/>
</html>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script.txt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script.txt?rev=907052&r1=907051&r2=907052&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script.txt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script.txt Fri Feb 5 18:56:21 2010
@@ -1,5 +1 @@
-<html><head></head><body><p>Ready to be updated with scripts.</p><script type="text/javascript">Tapestry.onDOMLoaded(function() {
-doSomething();
-doSomethingElse();
-});
-</script></body></html>
\ No newline at end of file
+<html><head></head><body><p>Ready to be updated with scripts.</p><script type="text/javascript">doSomething();doSomethingElse();</script></body></html>
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_in_development_mode.txt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_in_development_mode.txt?rev=907052&r1=907051&r2=907052&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_in_development_mode.txt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_in_development_mode.txt Fri Feb 5 18:56:21 2010
@@ -1,4 +1,2 @@
<html><head><script src="foo.js" type="text/javascript"></script></head><body><p>Ready to be updated with scripts.</p><script type="text/javascript">Tapestry.DEBUG_ENABLED = true;
-Tapestry.onDOMLoaded(function() {
-});
</script></body></html>
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_links.txt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_links.txt?rev=907052&r1=907051&r2=907052&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_links.txt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_links.txt Fri Feb 5 18:56:21 2010
@@ -1,5 +1,2 @@
<?xml version="1.0"?>
-<html><head><script src="foo.js" type="text/javascript"/><script src="bar/baz.js" type="text/javascript"/></head><body><p>Ready to be updated with scripts.</p><script type="text/javascript">Tapestry.onDOMLoaded(function() {
-pageInitialization();
-});
-</script></body></html>
\ No newline at end of file
+<html><head><script src="foo.js" type="text/javascript"/><script src="bar/baz.js" type="text/javascript"/></head><body><p>Ready to be updated with scripts.</p><script type="text/javascript">pageInitialization();</script></body></html>
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_links_at_top.txt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_links_at_top.txt?rev=907052&r1=907051&r2=907052&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_links_at_top.txt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/add_script_links_at_top.txt Fri Feb 5 18:56:21 2010
@@ -1,5 +1,2 @@
<?xml version="1.0"?>
-<html><head><script src="foo.js" type="text/javascript"/><script src="bar/baz.js" type="text/javascript"/></head><body><p>Ready to be updated with scripts at top.</p><script type="text/javascript">Tapestry.onDOMLoaded(function() {
-pageInitialization();
-});
-</script></body></html>
\ No newline at end of file
+<html><head><script src="foo.js" type="text/javascript"/><script src="bar/baz.js" type="text/javascript"/></head><body><p>Ready to be updated with scripts at top.</p><script type="text/javascript">pageInitialization();</script></body></html>
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/empty_document_with_scripts_at_top.txt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/empty_document_with_scripts_at_top.txt?rev=907052&r1=907051&r2=907052&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/empty_document_with_scripts_at_top.txt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/empty_document_with_scripts_at_top.txt Fri Feb 5 18:56:21 2010
@@ -1,5 +1,2 @@
<?xml version="1.0"?>
-<html><head><link media="print" type="text/css" rel="stylesheet" href="style.css"/><script src="foo.js" type="text/javascript"/><script src="bar/baz.js" type="text/javascript"/></head><body><script type="text/javascript">Tapestry.onDOMLoaded(function() {
-pageInitialization();
-});
-</script></body></html>
\ No newline at end of file
+<html><head><link media="print" type="text/css" rel="stylesheet" href="style.css"/><script src="foo.js" type="text/javascript"/><script src="bar/baz.js" type="text/javascript"/></head><body><script type="text/javascript">pageInitialization();</script></body></html>
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/script_written_raw.txt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/script_written_raw.txt?rev=907052&r1=907051&r2=907052&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/script_written_raw.txt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/script_written_raw.txt Fri Feb 5 18:56:21 2010
@@ -1,4 +1 @@
-<html><head></head><body><p>Ready to be updated with scripts.</p><script type="text/javascript">Tapestry.onDOMLoaded(function() {
-for (var i = 0; i < 5; i++) { doIt(i); }
-});
-</script></body></html>
\ No newline at end of file
+<html><head></head><body><p>Ready to be updated with scripts.</p><script type="text/javascript">for (var i = 0; i < 5; i++) { doIt(i); }</script></body></html>
\ No newline at end of file