01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import org.apache.tapestry.Asset;
18: import org.apache.tapestry.PageRenderSupport;
19: import org.apache.tapestry.internal.test.InternalBaseTestCase;
20: import org.apache.tapestry.ioc.services.SymbolSource;
21: import org.apache.tapestry.services.AssetSource;
22: import org.testng.annotations.Test;
23:
24: public class PageRenderSupportImplTest extends InternalBaseTestCase {
25: private static final String ASSET_URL = "/assets/foo/bar.pdf";
26:
27: @Test
28: public void add_script_link_by_asset() {
29: DocumentScriptBuilder builder = mockDocumentScriptBuilder();
30: Asset asset = mockAsset();
31:
32: train_toClientURL(asset, ASSET_URL);
33: builder.addScriptLink(ASSET_URL);
34:
35: replay();
36:
37: PageRenderSupport support = new PageRenderSupportImpl(builder,
38: null, null);
39:
40: support.addScriptLink(asset);
41:
42: verify();
43: }
44:
45: @Test
46: public void add_script() {
47: DocumentScriptBuilder builder = mockDocumentScriptBuilder();
48:
49: builder.addScript("Tapestry.Foo(\"bar\");");
50:
51: replay();
52:
53: PageRenderSupport support = new PageRenderSupportImpl(builder,
54: null, null);
55:
56: support.addScript("Tapestry.Foo(\"%s\");", "bar");
57:
58: verify();
59: }
60:
61: @Test
62: public void add_classpath_script_link() {
63: String path = "${root}/foo/bar.pdf";
64: String expanded = "org/apache/tapestry/foo/bar.pdf";
65:
66: DocumentScriptBuilder builder = mockDocumentScriptBuilder();
67: Asset asset = mockAsset();
68: SymbolSource source = mockSymbolSource();
69: AssetSource assetSource = mockAssetSource();
70:
71: train_expandSymbols(source, path, expanded);
72:
73: train_findAsset(assetSource, null, expanded, null, asset);
74:
75: train_toClientURL(asset, ASSET_URL);
76: builder.addScriptLink(ASSET_URL);
77:
78: replay();
79:
80: PageRenderSupport support = new PageRenderSupportImpl(builder,
81: source, assetSource);
82:
83: support.addClasspathScriptLink(path);
84:
85: verify();
86: }
87: }
|