use of org.apache.tapestry5.commons.services.InvalidationListener 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();
}
Aggregations