Search in sources :

Example 61 with Resource

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

the class ComponentTemplateSourceImplTest method caching.

@Test
public void caching() {
    TemplateParser parser = mockTemplateParser();
    ComponentTemplate template = mockComponentTemplate();
    ComponentModel model = mockComponentModel();
    Resource resource = mockResource();
    ComponentResourceLocator locator = mockLocator(model, english, resource);
    train_getComponentClassName(model, PACKAGE + ".Fred");
    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);
    // A second pass will test the caching (the
    // parser is not invoked).
    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 62 with Resource

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

the class ComponentTemplateSourceImplTest method no_template_found.

@Test
public void no_template_found() {
    TemplateParser parser = mockTemplateParser();
    ComponentModel model = mockComponentModel();
    Resource baseResource = mockResource();
    Resource missingResource = mockResource();
    train_getComponentClassName(model, PACKAGE + ".Barney");
    ComponentResourceLocator locator = mockLocator(model, english, null);
    train_getParentModel(model, null);
    train_getBaseResource(model, baseResource);
    expect(baseResource.withExtension(TapestryConstants.TEMPLATE_EXTENSION)).andReturn(missingResource);
    expect(missingResource.exists()).andReturn(false);
    replay();
    ComponentTemplateSourceImpl source = new ComponentTemplateSourceImpl(true, parser, locator, converter, componentRequestSelectorAnalyzer, threadLocale);
    ComponentTemplate template = source.getTemplate(model, Locale.ENGLISH);
    assertTrue(template.isMissing());
    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 63 with Resource

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

the class ComponentTemplateSourceImplTest method mockLocator.

private ComponentResourceLocator mockLocator(ComponentModel model, ComponentResourceSelector selector, Resource templateResource) {
    ComponentResourceLocator locator = newMock(ComponentResourceLocator.class);
    expect(locator.locateTemplate(model, selector)).andReturn(templateResource).once();
    return locator;
}
Also used : ComponentResourceLocator(org.apache.tapestry5.services.pageload.ComponentResourceLocator)

Example 64 with Resource

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

the class ContextResourceTest method to_string.

@Test
public void to_string() {
    Context context = mockContext();
    replay();
    Resource r = new ContextResource(context, "foo/Bar.txt");
    assertEquals(r.toString(), "context:foo/Bar.txt");
    verify();
}
Also used : Context(org.apache.tapestry5.http.services.Context) Resource(org.apache.tapestry5.commons.Resource) Test(org.testng.annotations.Test)

Example 65 with Resource

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

the class DynamicTemplateParserImpl method parseTemplate.

public DynamicTemplate parseTemplate(Resource resource) {
    DynamicTemplate result = cache.get(resource);
    if (result == null) {
        result = doParse(resource);
        cache.put(resource, result);
        tracker.add(resource.toURL());
    }
    return result;
}
Also used : DynamicTemplate(org.apache.tapestry5.services.dynamic.DynamicTemplate)

Aggregations

Resource (org.apache.tapestry5.commons.Resource)78 Test (org.testng.annotations.Test)62 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)38 Logger (org.slf4j.Logger)38 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)16 Asset (org.apache.tapestry5.Asset)14 ComponentModel (org.apache.tapestry5.model.ComponentModel)10 MutableEmbeddedComponentModel (org.apache.tapestry5.model.MutableEmbeddedComponentModel)10 ComponentTemplate (org.apache.tapestry5.internal.parser.ComponentTemplate)6 AssetFactory (org.apache.tapestry5.services.AssetFactory)6 IOException (java.io.IOException)5 AssetSource (org.apache.tapestry5.services.AssetSource)5 ComponentResourceLocator (org.apache.tapestry5.services.pageload.ComponentResourceLocator)5 Context (org.apache.tapestry5.http.services.Context)4 BeginRender (org.apache.tapestry5.annotations.BeginRender)3 Location (org.apache.tapestry5.commons.Location)3 AbstractResource (org.apache.tapestry5.ioc.internal.util.AbstractResource)3 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)3 ClasspathAssetAliasManager (org.apache.tapestry5.services.ClasspathAssetAliasManager)3 StreamableResource (org.apache.tapestry5.services.assets.StreamableResource)3