use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.
the class LocaleServiceImplTest method bundleInvalidateCaching.
@Test
public void bundleInvalidateCaching() {
final ResourceKeys resourceKeys = ResourceKeys.empty();
when(resourceService.findFiles(any(), anyString())).thenReturn(resourceKeys);
final ApplicationKey myApp = ApplicationKey.from("myapplication");
final ApplicationKey otherApp = ApplicationKey.from("otherapp");
MessageBundle bundleCached = localeService.getBundle(myApp, Locale.ENGLISH, "/phrases", "/override");
MessageBundle bundle = localeService.getBundle(myApp, Locale.ENGLISH, "/phrases", "/override");
MessageBundle otherBundleCached = localeService.getBundle(otherApp, Locale.ENGLISH, "/texts");
MessageBundle otherBundle = localeService.getBundle(otherApp, Locale.ENGLISH, "/texts");
assertSame(bundle, bundleCached);
assertSame(otherBundle, otherBundleCached);
Application application = Mockito.mock(Application.class);
when(application.getKey()).thenReturn(myApp);
localeService.activated(application);
bundle = localeService.getBundle(myApp, Locale.ENGLISH, "/phrases", "/override");
otherBundle = localeService.getBundle(otherApp, Locale.ENGLISH, "/texts");
assertNotSame(bundle, bundleCached);
assertSame(otherBundle, otherBundleCached);
}
use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.
the class LocaleServiceImplTest method getSupportedLocale_nb_file_does_not_support_nn_locale.
@Test
public void getSupportedLocale_nb_file_does_not_support_nn_locale() {
final ResourceKeys resourceKeys = ResourceKeys.from("myapplication:/site/i18n/myphrases.properties", "myapplication:/site/i18n/myphrases_nn.properties");
when(resourceService.findFiles(any(), anyString())).thenReturn(resourceKeys);
List<Locale> preferredLocales = localeList("nb");
Locale supportedLocale = localeService.getSupportedLocale(preferredLocales, ApplicationKey.from("myapplication"), "/myphrases");
assertNull(supportedLocale);
}
use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.
the class LocaleServiceImplTest method getLocales.
@Test
public void getLocales() {
final ResourceKeys resourceKeys = ResourceKeys.from("myapplication:/i18n/myphrases.properties", "myapplication:/i18n/myphrases_en.properties", "myapplication:/i18n/myphrases_en_US.properties", "myapplication:/i18n/myphrases_en_US_1.properties", "myapplication:/i18n/myphrases_fr.properties", "myapplication:/i18n/myphrases_ca.properties");
when(resourceService.findFiles(any(), Mockito.eq("^\\Q/i18n/myphrases\\E.*\\.properties$"))).thenReturn(resourceKeys);
final Set<Locale> locales = localeService.getLocales(ApplicationKey.from("myapplication"), "i18n/myphrases");
assertNotNull(locales);
assertEquals(5, locales.size());
assertTrue(locales.contains(new Locale("en")));
assertTrue(locales.contains(new Locale("en", "US")));
assertTrue(locales.contains(new Locale("en", "US", "1")));
assertTrue(locales.contains(new Locale("fr")));
assertTrue(locales.contains(new Locale("ca")));
}
Aggregations