Search in sources :

Example 1 with AssetFactory

use of org.apache.tapestry5.services.AssetFactory 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 AssetFactory

use of org.apache.tapestry5.services.AssetFactory 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 AssetFactory

use of org.apache.tapestry5.services.AssetFactory 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 AssetFactory

use of org.apache.tapestry5.services.AssetFactory 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 AssetFactory

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

the class TapestryModule method contributeComponentTemplateLocator.

/**
 * Contributes two template locators:
 * <dl>
 * <dt>Default</dt>
 * <dd>Searches for the template on the classpath ({@link DefaultTemplateLocator}</dd>
 * <dt>Page</dt>
 * <dd>Searches for <em>page</em> templates in the context ({@link PageTemplateLocator})</dd>
 * </dl>
 *
 * @since 5.2.0
 */
public static void contributeComponentTemplateLocator(OrderedConfiguration<ComponentTemplateLocator> configuration, @ContextProvider AssetFactory contextAssetFactory, @Symbol(SymbolConstants.APPLICATION_FOLDER) String applicationFolder, ComponentClassResolver componentClassResolver) {
    configuration.add("Default", new DefaultTemplateLocator());
    configuration.add("Page", new PageTemplateLocator(contextAssetFactory.getRootResource(), componentClassResolver, applicationFolder));
}
Also used : PageTemplateLocator(org.apache.tapestry5.internal.services.templates.PageTemplateLocator) DefaultTemplateLocator(org.apache.tapestry5.internal.services.templates.DefaultTemplateLocator)

Aggregations

AssetFactory (org.apache.tapestry5.services.AssetFactory)8 AssetSource (org.apache.tapestry5.services.AssetSource)7 Test (org.testng.annotations.Test)7 Asset (org.apache.tapestry5.Asset)6 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)6 Resource (org.apache.tapestry5.commons.Resource)5 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)5 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)2 Locale (java.util.Locale)1 ExternalUrlAssetFactory (org.apache.tapestry5.internal.services.ExternalUrlAssetFactory)1 ClasspathAssetRequestHandler (org.apache.tapestry5.internal.services.assets.ClasspathAssetRequestHandler)1 ContextAssetRequestHandler (org.apache.tapestry5.internal.services.assets.ContextAssetRequestHandler)1 DefaultTemplateLocator (org.apache.tapestry5.internal.services.templates.DefaultTemplateLocator)1 PageTemplateLocator (org.apache.tapestry5.internal.services.templates.PageTemplateLocator)1 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)1 AssetRequestDispatcher (org.apache.tapestry5.services.AssetRequestDispatcher)1