Search in sources :

Example 11 with ResourceKeys

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);
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) ApplicationKey(com.enonic.xp.app.ApplicationKey) ResourceKeys(com.enonic.xp.resource.ResourceKeys) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 12 with ResourceKeys

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);
}
Also used : Locale(java.util.Locale) ResourceKeys(com.enonic.xp.resource.ResourceKeys) Test(org.junit.jupiter.api.Test)

Example 13 with ResourceKeys

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")));
}
Also used : Locale(java.util.Locale) ResourceKeys(com.enonic.xp.resource.ResourceKeys) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceKeys (com.enonic.xp.resource.ResourceKeys)13 Test (org.junit.jupiter.api.Test)12 Locale (java.util.Locale)11 Application (com.enonic.xp.app.Application)1 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 MessageBundle (com.enonic.xp.i18n.MessageBundle)1 ResourceKey (com.enonic.xp.resource.ResourceKey)1 LinkedHashSet (java.util.LinkedHashSet)1