Search in sources :

Example 1 with AssetSource

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

the class AssetSourceImplTest method missing_resource.

@Test
public void missing_resource() {
    ThreadLocale threadLocale = mockThreadLocale();
    Map<String, AssetFactory> configuration = Collections.emptyMap();
    replay();
    AssetSource source = new AssetSourceImpl(threadLocale, configuration, null, null, tracker);
    try {
        source.getAsset(baseResource, "DoesNotExist.properties", Locale.UK);
        unreachable();
    } catch (RuntimeException ex) {
        assertEquals(ex.getMessage(), "Unable to locate asset 'classpath:org/apache/tapestry5/internal/services/DoesNotExist.properties' (the file does not exist).");
    }
    verify();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) AssetFactory(org.apache.tapestry5.services.AssetFactory) Test(org.testng.annotations.Test)

Example 2 with AssetSource

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

the class AssetSourceImplTest method get_classpath_asset.

@Test
public void get_classpath_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.getClasspathAsset("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 3 with AssetSource

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

the class AssetSourceImplTest method get_expanded_asset.

@Test
public void get_expanded_asset() {
    AssetFactory factory = mockAssetFactory();
    Asset asset = mockAsset();
    SymbolSource symbolSource = mockSymbolSource();
    Resource expectedResource = baseResource.forFile("SimpleComponent.properties");
    train_getRootResource(factory, rootResource);
    train_createAsset(factory, expectedResource, asset);
    train_expandSymbols(symbolSource, "${path}/SimpleComponent.properties", "org/apache/tapestry5/internal/services/SimpleComponent.properties");
    Map<String, AssetFactory> configuration = Collections.singletonMap("classpath", factory);
    replay();
    AssetSource source = new AssetSourceImpl(null, configuration, symbolSource, null, tracker);
    // First try creates it:
    assertSame(source.getExpandedAsset("${path}/SimpleComponent.properties"), asset);
    verify();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) 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 4 with AssetSource

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

the class AssetSourceImplTest method unknown_asset_prefix.

@Test
public void unknown_asset_prefix() {
    ThreadLocale threadLocale = mockThreadLocale();
    Map<String, AssetFactory> configuration = Collections.emptyMap();
    replay();
    AssetSource source = new AssetSourceImpl(threadLocale, configuration, null, null, tracker);
    try {
        source.getAsset(baseResource, "classpath:org/apache/tapestry5/internal/services/SimpleComponent.properties", Locale.UK);
        unreachable();
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "Unknown prefix for asset path 'classpath:org/apache/tapestry5/internal/services/SimpleComponent.properties'.");
    }
    verify();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) AssetFactory(org.apache.tapestry5.services.AssetFactory) Test(org.testng.annotations.Test)

Example 5 with AssetSource

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

the class AssetsModule method setupGlobalMessageCatalog.

/**
 * Contributes:
 * <dl>
 * <dt>ClientLocalization</dt>
 * <dd>A virtual resource of formatting symbols for decimal numbers</dd>
 * <dt>Core</dt>
 * <dd>Built in messages used by Tapestry's default validators and components</dd>
 * <dt>AppCatalog</dt>
 * <dd>The Resource defined by {@link SymbolConstants#APPLICATION_CATALOG}</dd>
 * <dt>
 *     </dl>
 *
 * @since 5.2.0
 */
@Contribute(ComponentMessagesSource.class)
public static void setupGlobalMessageCatalog(AssetSource assetSource, @Symbol(SymbolConstants.APPLICATION_CATALOG) Resource applicationCatalog, OrderedConfiguration<Resource> configuration) {
    configuration.add("ClientLocalization", new ClientLocalizationMessageResource());
    configuration.add("Core", assetSource.resourceForPath("org/apache/tapestry5/core.properties"));
    configuration.add("AppCatalog", applicationCatalog);
}
Also used : ClientLocalizationMessageResource(org.apache.tapestry5.internal.services.messages.ClientLocalizationMessageResource) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Aggregations

AssetSource (org.apache.tapestry5.services.AssetSource)9 Test (org.testng.annotations.Test)9 Asset (org.apache.tapestry5.Asset)8 AssetFactory (org.apache.tapestry5.services.AssetFactory)7 Resource (org.apache.tapestry5.commons.Resource)6 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)6 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)5 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)3 AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)2 ObjectLocator (org.apache.tapestry5.commons.ObjectLocator)2 ObjectProvider (org.apache.tapestry5.commons.ObjectProvider)2 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)2 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 Locale (java.util.Locale)1