Search in sources :

Example 21 with Asset

use of org.apache.tapestry5.Asset 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();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) Path(org.apache.tapestry5.annotations.Path) SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) ObjectLocator(org.apache.tapestry5.commons.ObjectLocator) Asset(org.apache.tapestry5.Asset) ObjectProvider(org.apache.tapestry5.commons.ObjectProvider) Test(org.testng.annotations.Test)

Example 22 with Asset

use of org.apache.tapestry5.Asset 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();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Asset(org.apache.tapestry5.Asset) AssetFactory(org.apache.tapestry5.services.AssetFactory) Test(org.testng.annotations.Test)

Example 23 with Asset

use of org.apache.tapestry5.Asset 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();
}
Also used : ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) Locale(java.util.Locale) AssetSource(org.apache.tapestry5.services.AssetSource) ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Asset(org.apache.tapestry5.Asset) AssetFactory(org.apache.tapestry5.services.AssetFactory) Test(org.testng.annotations.Test)

Example 24 with Asset

use of org.apache.tapestry5.Asset 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();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Asset(org.apache.tapestry5.Asset) AssetFactory(org.apache.tapestry5.services.AssetFactory) Test(org.testng.annotations.Test)

Example 25 with Asset

use of org.apache.tapestry5.Asset in project tapestry-5 by apache.

the class TapestryModule method contributeBindingSource.

// ========================================================================
// 
// Service Builder Methods (static)
// 
// ========================================================================
// ========================================================================
// 
// Service Contribution Methods (static)
// 
// ========================================================================
/**
 * Contributes the factory for several built-in binding prefixes ("asset",
 * "block", "component", "literal", prop",
 * "nullfieldstrategy", "message", "validate", "translate", "var").
 */
public static void contributeBindingSource(MappedConfiguration<String, BindingFactory> configuration, @InjectService("PropBindingFactory") BindingFactory propBindingFactory, @InjectService("MessageBindingFactory") BindingFactory messageBindingFactory, @InjectService("ValidateBindingFactory") BindingFactory validateBindingFactory, @InjectService("TranslateBindingFactory") BindingFactory translateBindingFactory, @InjectService("AssetBindingFactory") BindingFactory assetBindingFactory, @InjectService("NullFieldStrategyBindingFactory") BindingFactory nullFieldStrategyBindingFactory, @InjectService("ContextBindingFactory") BindingFactory contextBindingFactory, @InjectService("SymbolBindingFactory") BindingFactory symbolBindingFactory) {
    configuration.add(BindingConstants.LITERAL, new LiteralBindingFactory());
    configuration.add(BindingConstants.COMPONENT, new ComponentBindingFactory());
    configuration.add(BindingConstants.VAR, new RenderVariableBindingFactory());
    configuration.add(BindingConstants.BLOCK, new BlockBindingFactory());
    configuration.add(BindingConstants.PROP, propBindingFactory);
    configuration.add(BindingConstants.MESSAGE, messageBindingFactory);
    configuration.add(BindingConstants.VALIDATE, validateBindingFactory);
    configuration.add(BindingConstants.TRANSLATE, translateBindingFactory);
    configuration.add(BindingConstants.ASSET, assetBindingFactory);
    configuration.add(BindingConstants.NULLFIELDSTRATEGY, nullFieldStrategyBindingFactory);
    configuration.add(BindingConstants.CONTEXT, contextBindingFactory);
    configuration.add(BindingConstants.SYMBOL, symbolBindingFactory);
}
Also used : LiteralBindingFactory(org.apache.tapestry5.internal.bindings.LiteralBindingFactory) BlockBindingFactory(org.apache.tapestry5.internal.bindings.BlockBindingFactory) RenderVariableBindingFactory(org.apache.tapestry5.internal.bindings.RenderVariableBindingFactory) ComponentBindingFactory(org.apache.tapestry5.internal.bindings.ComponentBindingFactory)

Aggregations

Asset (org.apache.tapestry5.Asset)19 Resource (org.apache.tapestry5.commons.Resource)10 Test (org.testng.annotations.Test)9 AssetFactory (org.apache.tapestry5.services.AssetFactory)8 AssetSource (org.apache.tapestry5.services.AssetSource)8 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)6 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)5 ComponentResources (org.apache.tapestry5.ComponentResources)3 Path (org.apache.tapestry5.annotations.Path)3 Asset (com.google.cloud.asset.v1.Asset)2 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)2 ListAssetsRequest (com.google.cloud.asset.v1.ListAssetsRequest)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 ListAssetsResponse (com.google.cloud.asset.v1.ListAssetsResponse)1 OutputStream (java.io.OutputStream)1 SoftReference (java.lang.ref.SoftReference)1 URL (java.net.URL)1 DateFormat (java.text.DateFormat)1