use of org.apache.tapestry5.services.pageload.ComponentResourceLocator 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();
}
use of org.apache.tapestry5.services.pageload.ComponentResourceLocator in project tapestry-5 by apache.
the class ComponentTemplateSourceImplTest method localization_to_same.
/**
* Checks that localization to the same resource works (w/ caching).
*/
@Test
public void localization_to_same() {
Resource resource = mockResource();
TemplateParser parser = mockTemplateParser();
ComponentTemplate template = mockComponentTemplate();
ComponentModel model = mockComponentModel();
ComponentResourceLocator locator = newMock(ComponentResourceLocator.class);
train_getComponentClassName(model, PACKAGE + ".Fred");
expect(locator.locateTemplate(model, english)).andReturn(resource).once();
expect(resource.exists()).andReturn(true).anyTimes();
expect(resource.toURL()).andReturn(null).anyTimes();
expect(locator.locateTemplate(model, french)).andReturn(resource).once();
train_parseTemplate(parser, resource, template);
replay();
ComponentTemplateSourceImpl source = new ComponentTemplateSourceImpl(true, parser, locator, converter, componentRequestSelectorAnalyzer, threadLocale);
assertSame(source.getTemplate(model, Locale.ENGLISH), template);
// A second pass finds the same resource, but using a different
// path/locale combination.
assertSame(source.getTemplate(model, Locale.FRENCH), template);
// A third pass should further demonstrate the caching.
assertSame(source.getTemplate(model, Locale.FRENCH), template);
verify();
}
use of org.apache.tapestry5.services.pageload.ComponentResourceLocator in project tapestry-5 by apache.
the class ComponentTemplateSourceImplTest method invalidation.
/**
* Tests resource invalidation.
*/
@Test
public void invalidation() throws Exception {
File rootDir = createClasspathRoot();
URLClassLoader loader = newLoaderWithClasspathRoot(rootDir);
ComponentModel model = mockComponentModel();
File packageDir = new File(rootDir, "baz");
packageDir.mkdirs();
File f = new File(packageDir, "Biff.tml");
f.createNewFile();
Resource baseResource = new ClasspathResource(loader, "baz/Biff.class");
Resource localized = baseResource.withExtension(TapestryConstants.TEMPLATE_EXTENSION);
TemplateParser parser = mockTemplateParser();
ComponentTemplate template = mockComponentTemplate();
InvalidationListener listener = mockInvalidationListener();
train_getComponentClassName(model, "baz.Biff");
ComponentResourceLocator locator = mockLocator(model, english, localized);
train_parseTemplate(parser, localized, template);
replay();
ComponentTemplateSourceImpl source = new ComponentTemplateSourceImpl(false, parser, locator, converter, componentRequestSelectorAnalyzer, threadLocale);
source.addInvalidationListener(listener);
assertSame(source.getTemplate(model, Locale.ENGLISH), template);
// Check for updates (which won't be found).
source.checkForUpdates();
// A second pass will test the caching (the
// parser is not invoked).
assertSame(source.getTemplate(model, Locale.ENGLISH), template);
verify();
// Now, change the file and processInbound an UpdateEvent.
touch(f);
listener.objectWasInvalidated();
replay();
// Check for updates (which will be found).
source.checkForUpdates();
verify();
// Check that the cache really is cleared.
train_getComponentClassName(model, "baz.Biff");
expect(locator.locateTemplate(model, english)).andReturn(localized);
train_parseTemplate(parser, localized, template);
replay();
assertSame(source.getTemplate(model, Locale.ENGLISH), template);
verify();
}
use of org.apache.tapestry5.services.pageload.ComponentResourceLocator 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.services.pageload.ComponentResourceLocator 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();
}
Aggregations