01: // Copyright 2006, 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 static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
18:
19: import java.util.Map;
20:
21: import org.apache.tapestry.TapestryConstants;
22: import org.apache.tapestry.internal.test.InternalBaseTestCase;
23: import org.apache.tapestry.services.ClasspathAssetAliasManager;
24: import org.apache.tapestry.services.Request;
25: import org.testng.annotations.DataProvider;
26: import org.testng.annotations.Test;
27:
28: public class ClasspathAssetAliasManagerImplTest extends
29: InternalBaseTestCase {
30:
31: public Map<String, String> configuration() {
32: Map<String, String> configuration = newMap();
33:
34: configuration.put("tapestry/", "org/apache/tapestry/");
35: configuration.put("tapestry-internal/",
36: "org/apache/tapestry/internal/");
37: configuration.put("mylib/", "com/example/mylib/");
38:
39: return configuration;
40: }
41:
42: @Test(dataProvider="to_client_url_data")
43: public void to_client_url(String resourcePath,
44: String expectedClientURL) {
45: Request request = mockRequest();
46:
47: train_getContextPath(request, "/ctx");
48:
49: replay();
50:
51: ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(
52: request, configuration());
53:
54: assertEquals(manager.toClientURL(resourcePath), "/ctx"
55: + TapestryConstants.ASSET_PATH_PREFIX
56: + expectedClientURL);
57:
58: verify();
59: }
60:
61: @DataProvider(name="to_client_url_data")
62: public Object[][] to_client_url_data() {
63: return new Object[][] {
64: { "foo/bar/Baz.txt", "foo/bar/Baz.txt" },
65: { "com/example/mylib/Foo.bar", "mylib/Foo.bar" },
66: { "com/example/mylib/nested/Foo.bar",
67: "mylib/nested/Foo.bar" },
68: { "org/apache/tapestry/internal/Foo.bar",
69: "tapestry-internal/Foo.bar" },
70: { "org/apache/tapestry/Foo.bar", "tapestry/Foo.bar" }, };
71: }
72:
73: @Test(dataProvider="to_resource_path_data")
74: public void to_resource_path(String clientURL,
75: String expectedResourcePath) {
76: ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(
77: null, configuration());
78:
79: assertEquals(manager.toResourcePath(clientURL),
80: expectedResourcePath);
81: }
82:
83: @DataProvider(name="to_resource_path_data")
84: public Object[][] to_resource_path_data() {
85: Object[][] data = to_client_url_data();
86:
87: for (Object[] pair : data) {
88: Object buffer = pair[0];
89: pair[0] = TapestryConstants.ASSET_PATH_PREFIX + pair[1];
90: pair[1] = buffer;
91: }
92:
93: return data;
94: }
95: }
|