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.annotations.Path;
19: import org.apache.tapestry.internal.test.InternalBaseTestCase;
20: import org.apache.tapestry.ioc.AnnotationProvider;
21: import org.apache.tapestry.ioc.ObjectProvider;
22: import org.apache.tapestry.ioc.ObjectLocator;
23: import org.apache.tapestry.ioc.services.SymbolSource;
24: import org.apache.tapestry.ioc.services.TypeCoercer;
25: import org.apache.tapestry.services.AssetSource;
26: import org.testng.annotations.Test;
27:
28: public class AssetObjectProviderTest extends InternalBaseTestCase {
29:
30: @Test
31: public void no_path_annotation() {
32: AssetSource source = mockAssetSource();
33: ObjectLocator locator = mockObjectLocator();
34: AnnotationProvider annotationProvider = mockAnnotationProvider();
35: TypeCoercer typeCoercer = mockTypeCoercer();
36: SymbolSource symbolSource = mockSymbolSource();
37:
38: train_getAnnotation(annotationProvider, Path.class, null);
39:
40: replay();
41:
42: ObjectProvider provider = new AssetObjectProvider(source,
43: typeCoercer, symbolSource);
44:
45: assertNull(provider.provide(Asset.class, annotationProvider,
46: locator));
47:
48: verify();
49: }
50:
51: @Test
52: public void normal_conversion() {
53: AssetSource source = mockAssetSource();
54: ObjectLocator locator = mockObjectLocator();
55: Asset asset = mockAsset();
56: String path = "${foo}";
57: String expanded = "foo/bar/baz.gif";
58: AnnotationProvider annotationProvider = mockAnnotationProvider();
59: TypeCoercer typeCoercer = mockTypeCoercer();
60: Path pathAnnotation = mockPath();
61: SymbolSource symbolSource = mockSymbolSource();
62:
63: train_getAnnotation(annotationProvider, Path.class,
64: pathAnnotation);
65: train_value(pathAnnotation, path);
66: train_expandSymbols(symbolSource, path, expanded);
67: train_findAsset(source, null, expanded, null, asset);
68: train_coerce(typeCoercer, asset, Asset.class, asset);
69:
70: replay();
71:
72: ObjectProvider provider = new AssetObjectProvider(source,
73: typeCoercer, symbolSource);
74:
75: Asset result = provider.provide(Asset.class,
76: annotationProvider, locator);
77:
78: assertSame(result, asset);
79:
80: verify();
81: }
82: }
|