ComponentMessagesSourceImpl implements ComponentMessagesSource, UpdateListener { public Messages getMessages(ComponentModel componentModel, Locale locale) { return getMessages(componentModel, new ComponentResourceSelector(locale)); } ComponentMessagesSourceImpl(@Symbol(SymbolConstants.PRODUCTION_MODE)
                                       boolean productionMode, List<Resource> appCatalogResources, PropertiesFileParser parser,
                                       ComponentResourceLocator resourceLocator, ClasspathURLConverter classpathURLConverter);   ComponentMessagesSourceImpl(boolean productionMode, Resource appCatalogResource,
                                ComponentResourceLocator resourceLocator, PropertiesFileParser parser, URLChangeTracker tracker);   ComponentMessagesSourceImpl(boolean productionMode, List<Resource> appCatalogResources,
                                ComponentResourceLocator resourceLocator, PropertiesFileParser parser, URLChangeTracker tracker); @PostInjection void setupReload(ReloadHelper reloadHelper); void checkForUpdates(); Messages getMessages(ComponentModel componentModel, Locale locale); Messages getMessages(ComponentModel componentModel, ComponentResourceSelector selector); Messages getApplicationCatalog(Locale locale); InvalidationEventHub getInvalidationEventHub();  }
@Test public void simple_component() { ComponentModel model = mockComponentModel(); train_getComponentClassName(model, SIMPLE_COMPONENT_CLASS_NAME); train_getBaseResource(model, simpleComponentResource); train_getParentModel(model, null); replay(); forceCacheClear(); Messages messages = source.getMessages(model, Locale.ENGLISH); assertEquals(messages.get("color"), "color"); assertEquals(messages.get("framework"), "Tapestry"); assertSame(source.getMessages(model, Locale.ENGLISH), messages); forceCacheClear(); Messages messages2 = source.getMessages(model, Locale.ENGLISH); assertNotSame(messages2, messages); assertEquals(messages2.get("color"), "color"); assertEquals(messages2.get("framework"), "Tapestry"); verify(); }
@Test public void per_language_messages_override() { ComponentModel model = mockComponentModel(); train_getComponentClassName(model, SIMPLE_COMPONENT_CLASS_NAME); train_getBaseResource(model, simpleComponentResource); train_getParentModel(model, null); replay(); forceCacheClear(); Messages messages = source.getMessages(model, Locale.UK); assertEquals(messages.get("color"), "colour"); assertEquals(messages.get("framework"), "Tapestry"); verify(); }
@Test public void messages_keys_are_case_insensitive() { ComponentModel model = mockComponentModel(); train_getComponentClassName(model, SIMPLE_COMPONENT_CLASS_NAME); train_getBaseResource(model, simpleComponentResource); train_getParentModel(model, null); replay(); forceCacheClear(); Messages messages = source.getMessages(model, Locale.UK); assertEquals(messages.get("COlor"), "colour"); assertEquals(messages.get("Framework"), "Tapestry"); verify(); }
@Test public void subclass_inherits_base_class_messages() { ComponentModel model = mockComponentModel(); ComponentModel parent = mockComponentModel(); train_getComponentClassName(model, "org.apache.tapestry5.internal.services.SubclassComponent"); train_getBaseResource(model, new ClasspathResource( "org/apache/tapestry5/internal/services/SubclassComponent.class")); train_getParentModel(model, parent); train_getComponentClassName(parent, SIMPLE_COMPONENT_CLASS_NAME); train_getBaseResource(parent, simpleComponentResource); train_getParentModel(parent, null); replay(); forceCacheClear(); Messages messages = source.getMessages(model, Locale.ENGLISH); assertEquals(messages.get("color"), "color"); assertEquals(messages.get("framework"), "Tapestry"); assertEquals(messages.get("source"), "SubclassComponent"); assertEquals(messages.get("metal"), "steel"); assertEquals(messages.get("app-catalog-source"), "AppCatalog"); assertEquals(messages.get("app-catalog-overridden"), "Overridden by Component"); messages = source.getMessages(model, Locale.UK); assertEquals(messages.get("color"), "colour"); assertEquals(messages.get("framework"), "Tapestry"); assertEquals(messages.get("source"), "SubclassComponent"); assertEquals(messages.get("metal"), "aluminium"); verify(); }
@Test public void no_app_catalog() { ComponentModel model = mockComponentModel(); ComponentModel parent = mockComponentModel(); train_getComponentClassName(model, "org.apache.tapestry5.internal.services.SubclassComponent"); train_getBaseResource(model, new ClasspathResource( "org/apache/tapestry5/internal/services/SubclassComponent.class")); train_getParentModel(model, parent); train_getComponentClassName(parent, SIMPLE_COMPONENT_CLASS_NAME); train_getBaseResource(parent, simpleComponentResource); train_getParentModel(parent, null); replay(); forceCacheClear(); Resource resource = simpleComponentResource.forFile("NoSuchAppCatalog.properties"); List<Resource> resources = Arrays.asList(resource); ComponentMessagesSource source = new ComponentMessagesSourceImpl(true, resources, new PropertiesFileParserImpl(), resourceLocator, converter); Messages messages = source.getMessages(model, Locale.ENGLISH); assertEquals(messages.get("color"), "color"); assertEquals(messages.get("app-catalog-source"), "[[missing key: app-catalog-source]]"); assertEquals(messages.get("app-catalog-overridden"), "Overridden by Component"); verify(); }