Search in sources :

Example 1 with ComponentResourceLocator

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();
}
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 2 with ComponentResourceLocator

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();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentResourceLocator(org.apache.tapestry5.services.pageload.ComponentResourceLocator) ComponentTemplate(org.apache.tapestry5.internal.parser.ComponentTemplate) Test(org.testng.annotations.Test)

Example 3 with ComponentResourceLocator

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();
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) URLClassLoader(java.net.URLClassLoader) 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) InvalidationListener(org.apache.tapestry5.commons.services.InvalidationListener) File(java.io.File) Test(org.testng.annotations.Test)

Example 4 with ComponentResourceLocator

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

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

Aggregations

ComponentResourceLocator (org.apache.tapestry5.services.pageload.ComponentResourceLocator)6 Resource (org.apache.tapestry5.commons.Resource)5 ComponentTemplate (org.apache.tapestry5.internal.parser.ComponentTemplate)5 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)5 ComponentModel (org.apache.tapestry5.model.ComponentModel)5 Test (org.testng.annotations.Test)5 File (java.io.File)1 URLClassLoader (java.net.URLClassLoader)1 InvalidationListener (org.apache.tapestry5.commons.services.InvalidationListener)1