use of org.apache.tapestry5.services.AssetSource in project tapestry-5 by apache.
the class AssetObjectProviderTest method no_path_annotation.
@Test
public void no_path_annotation() {
AssetSource source = mockAssetSource();
ObjectLocator locator = mockObjectLocator();
AnnotationProvider annotationProvider = mockAnnotationProvider();
TypeCoercer typeCoercer = mockTypeCoercer();
SymbolSource symbolSource = mockSymbolSource();
train_getAnnotation(annotationProvider, Path.class, null);
replay();
ObjectProvider provider = new AssetObjectProvider(source, typeCoercer, symbolSource);
assertNull(provider.provide(Asset.class, annotationProvider, locator));
verify();
}
use of org.apache.tapestry5.services.AssetSource in project tapestry-5 by apache.
the class AssetObjectProviderTest method normal_conversion.
@Test
public void normal_conversion() {
AssetSource source = mockAssetSource();
ObjectLocator locator = mockObjectLocator();
Asset asset = mockAsset();
String path = "${foo}";
String expanded = "foo/bar/baz.gif";
AnnotationProvider annotationProvider = mockAnnotationProvider();
TypeCoercer typeCoercer = mockTypeCoercer();
Path pathAnnotation = mockPath();
SymbolSource symbolSource = mockSymbolSource();
train_getAnnotation(annotationProvider, Path.class, pathAnnotation);
train_value(pathAnnotation, path);
train_expandSymbols(symbolSource, path, expanded);
train_getAsset(source, null, expanded, null, asset);
train_coerce(typeCoercer, asset, Asset.class, asset);
replay();
ObjectProvider provider = new AssetObjectProvider(source, typeCoercer, symbolSource);
Asset result = provider.provide(Asset.class, annotationProvider, locator);
assertSame(result, asset);
verify();
}
use of org.apache.tapestry5.services.AssetSource in project tapestry-5 by apache.
the class AssetSourceImplTest method absolute_asset_with_known_prefix.
@Test
public void absolute_asset_with_known_prefix() {
AssetFactory factory = mockAssetFactory();
ThreadLocale threadLocale = mockThreadLocale();
Asset asset = mockAsset();
Resource expectedResource = rootResource.forFile("org/apache/tapestry5/internal/services/SimpleComponent_en_GB.properties");
train_getRootResource(factory, rootResource);
train_createAsset(factory, expectedResource, asset);
Map<String, AssetFactory> configuration = Collections.singletonMap("classpath", factory);
replay();
AssetSource source = new AssetSourceImpl(threadLocale, configuration, null, null, tracker);
assertSame(source.getAsset(baseResource, "classpath:org/apache/tapestry5/internal/services/SimpleComponent.properties", Locale.UK), asset);
// Check that a leading slash is not a problem:
assertSame(source.getAsset(baseResource, "classpath:/org/apache/tapestry5/internal/services/SimpleComponent.properties", Locale.UK), asset);
verify();
}
use of org.apache.tapestry5.services.AssetSource in project tapestry-5 by apache.
the class AssetSourceImplTest method get_classpath_asset_for_unspecified_locale.
@Test
public void get_classpath_asset_for_unspecified_locale() {
AssetFactory factory = mockAssetFactory();
ThreadLocale threadLocale = mockThreadLocale();
Asset asset = mockAsset();
Locale locale = Locale.UK;
Resource expectedResource = baseResource.forFile("SimpleComponent_en_GB.properties");
train_getRootResource(factory, rootResource);
train_createAsset(factory, expectedResource, asset);
Map<String, AssetFactory> configuration = Collections.singletonMap("classpath", factory);
train_getLocale(threadLocale, locale);
replay();
AssetSource source = new AssetSourceImpl(threadLocale, configuration, null, null, tracker);
assertSame(source.getClasspathAsset("org/apache/tapestry5/internal/services/SimpleComponent.properties"), asset);
verify();
}
use of org.apache.tapestry5.services.AssetSource in project tapestry-5 by apache.
the class AssetSourceImplTest method relative_asset.
@Test
public void relative_asset() {
AssetFactory factory = mockAssetFactory();
ThreadLocale threadLocale = mockThreadLocale();
Asset asset = mockAsset();
Resource expectedResource = baseResource.forFile("SimpleComponent_en_GB.properties");
train_getRootResource(factory, rootResource);
train_createAsset(factory, expectedResource, asset);
Map<String, AssetFactory> configuration = Collections.singletonMap("classpath", factory);
replay();
AssetSource source = new AssetSourceImpl(threadLocale, configuration, null, null, tracker);
// First try creates it:
assertSame(source.getAsset(baseResource, "SimpleComponent.properties", Locale.UK), asset);
// Second try shows that it is cached
assertSame(source.getAsset(baseResource, "SimpleComponent.properties", Locale.UK), asset);
verify();
}
Aggregations