Search in sources :

Example 1 with ThreadLocale

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

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

use of org.apache.tapestry5.ioc.services.ThreadLocale 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 4 with ThreadLocale

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

the class ComponentTemplateSourceImplTest method child_component_inherits_parent_template.

@Test
public void child_component_inherits_parent_template() {
    TemplateParser parser = mockTemplateParser();
    ComponentTemplate template = mockComponentTemplate();
    ComponentModel model = mockComponentModel();
    ComponentModel parentModel = mockComponentModel();
    Resource resource = mockResource();
    ComponentResourceLocator locator = mockLocator(model, english, null);
    train_getComponentClassName(model, "foo.Bar");
    train_getParentModel(model, parentModel);
    expect(locator.locateTemplate(parentModel, english)).andReturn(resource).once();
    expect(resource.exists()).andReturn(true);
    expect(resource.toURL()).andReturn(null);
    train_parseTemplate(parser, resource, template);
    replay();
    ComponentTemplateSource source = new ComponentTemplateSourceImpl(true, parser, locator, converter, componentRequestSelectorAnalyzer, threadLocale);
    assertSame(source.getTemplate(model, english), template);
    verify();
}
Also used : ComponentModel(org.apache.tapestry5.model.ComponentModel) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) ComponentResourceLocator(org.apache.tapestry5.services.pageload.ComponentResourceLocator) ComponentTemplate(org.apache.tapestry5.internal.parser.ComponentTemplate) Test(org.testng.annotations.Test)

Example 5 with ThreadLocale

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

the class LocalizationSetterImplTest method set_nonpersistent_locale.

@Test
public void set_nonpersistent_locale() {
    PersistentLocale pl = mockPersistentLocale();
    ThreadLocale tl = mockThreadLocale();
    Request request = mockRequest();
    tl.setLocale(Locale.FRENCH);
    replay();
    LocalizationSetterImpl setter = new LocalizationSetterImpl(request, pl, tl, "en,fr");
    setter.setNonPersistentLocaleFromLocaleName("fr_BE");
    verify();
}
Also used : PersistentLocale(org.apache.tapestry5.services.PersistentLocale) ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) Request(org.apache.tapestry5.http.services.Request) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)17 Resource (org.apache.tapestry5.commons.Resource)11 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)11 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)10 ComponentModel (org.apache.tapestry5.model.ComponentModel)6 AssetFactory (org.apache.tapestry5.services.AssetFactory)6 AssetSource (org.apache.tapestry5.services.AssetSource)6 Asset (org.apache.tapestry5.Asset)5 Request (org.apache.tapestry5.http.services.Request)5 ComponentTemplate (org.apache.tapestry5.internal.parser.ComponentTemplate)5 PersistentLocale (org.apache.tapestry5.services.PersistentLocale)5 ComponentResourceLocator (org.apache.tapestry5.services.pageload.ComponentResourceLocator)5 File (java.io.File)1 URLClassLoader (java.net.URLClassLoader)1 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