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();
}
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();
}
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;
}
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();
}
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;
}
Aggregations