ComponentTemplateSourceImpl extends InvalidationEventHubImpl implements ComponentTemplateSource,
        UpdateListener { public ComponentTemplate getTemplate(ComponentModel componentModel, ComponentResourceSelector selector) { String componentName = componentModel.getComponentClassName(); MultiKey key = new MultiKey(componentName, selector); Resource resource = templateResources.get(key); if (resource == null) { resource = locateTemplateResource(componentModel, selector); templateResources.put(key, resource); } ComponentTemplate result = templates.get(resource); if (result == null) { result = parseTemplate(resource); templates.put(resource, result); } return result; } ComponentTemplateSourceImpl(@Inject
                                       @Symbol(SymbolConstants.PRODUCTION_MODE)
                                       boolean productionMode, TemplateParser parser, ComponentResourceLocator locator,
                                       ClasspathURLConverter classpathURLConverter);   ComponentTemplateSourceImpl(boolean productionMode, TemplateParser parser, ComponentResourceLocator locator,
                                URLChangeTracker tracker); @PostInjection void registerAsUpdateListener(UpdateListenerHub hub); @PostInjection void setupReload(ReloadHelper helper); ComponentTemplate getTemplate(ComponentModel componentModel, ComponentResourceSelector selector); ComponentTemplate getTemplate(ComponentModel componentModel, Locale locale); void checkForUpdates(); InvalidationEventHub getInvalidationEventHub();  }
@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); assertSame(source.getTemplate(model, english), template); assertSame(source.getTemplate(model, english), template); verify(); }
@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); assertSame(source.getTemplate(model, Locale.ENGLISH), template); assertSame(source.getTemplate(model, Locale.FRENCH), template); assertSame(source.getTemplate(model, Locale.FRENCH), template); verify(); }
@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); ComponentTemplate template = source.getTemplate(model, Locale.ENGLISH); assertTrue(template.isMissing()); verify(); }
@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); assertSame(source.getTemplate(model, english), template); verify(); }