Search in sources :

Example 1 with ResourceKeys

use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.

the class LocaleServiceImplTest method getSupportedLocale_noPreferredFound.

@Test
public void getSupportedLocale_noPreferredFound() {
    final ResourceKeys resourceKeys = ResourceKeys.from("myapplication:/site/i18n/myphrases.properties", "myapplication:/site/i18n/myphrases_en.properties", "myapplication:/site/i18n/myphrases_en_US.properties", "myapplication:/site/i18n/myphrases_en_US_1.properties", "myapplication:/site/i18n/myphrases_fr.properties", "myapplication:/site/i18n/myphrases_ca.properties");
    when(resourceService.findFiles(any(), anyString())).thenReturn(resourceKeys);
    List<Locale> preferredLocales = localeList("no");
    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 2 with ResourceKeys

use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.

the class LocaleServiceImplTest method getSupportedLocale_LanguagePreferredFound.

@Test
public void getSupportedLocale_LanguagePreferredFound() {
    final ResourceKeys resourceKeys = ResourceKeys.from("myapplication:/site/i18n/myphrases.properties", "myapplication:/site/i18n/myphrases_en.properties", "myapplication:/site/i18n/myphrases_en_US.properties", "myapplication:/site/i18n/myphrases_en_US_1.properties", "myapplication:/site/i18n/myphrases_fr.properties", "myapplication:/site/i18n/myphrases_ca.properties");
    when(resourceService.findFiles(any(), anyString())).thenReturn(resourceKeys);
    List<Locale> preferredLocales = localeList("en-UK");
    Locale supportedLocale = localeService.getSupportedLocale(preferredLocales, ApplicationKey.from("myapplication"), "/myphrases");
    assertNotNull(supportedLocale);
    assertEquals("en", supportedLocale.toLanguageTag());
}
Also used : Locale(java.util.Locale) ResourceKeys(com.enonic.xp.resource.ResourceKeys) Test(org.junit.jupiter.api.Test)

Example 3 with ResourceKeys

use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.

the class LocaleServiceImplTest method getSupportedLocale_nn_file_supports_no_locale.

@Test
public void getSupportedLocale_nn_file_supports_no_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("no");
    Locale supportedLocale = localeService.getSupportedLocale(preferredLocales, ApplicationKey.from("myapplication"), "/myphrases");
    assertNotNull(supportedLocale);
    assertEquals("no", supportedLocale.toLanguageTag());
}
Also used : Locale(java.util.Locale) ResourceKeys(com.enonic.xp.resource.ResourceKeys) Test(org.junit.jupiter.api.Test)

Example 4 with ResourceKeys

use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.

the class LocaleServiceImplTest method getSupportedLocale_onePreferredFound.

@Test
public void getSupportedLocale_onePreferredFound() {
    final ResourceKeys resourceKeys = ResourceKeys.from("myapplication:/site/i18n/myphrases.properties", "myapplication:/site/i18n/myphrases_en.properties", "myapplication:/site/i18n/myphrases_en_US.properties", "myapplication:/site/i18n/myphrases_en_US_1.properties", "myapplication:/site/i18n/myphrases_fr.properties", "myapplication:/site/i18n/myphrases_ca.properties");
    when(resourceService.findFiles(any(), anyString())).thenReturn(resourceKeys);
    List<Locale> preferredLocales = localeList("en-US");
    Locale supportedLocale = localeService.getSupportedLocale(preferredLocales, ApplicationKey.from("myapplication"), "/myphrases");
    assertNotNull(supportedLocale);
    assertEquals("en-US", supportedLocale.toLanguageTag());
}
Also used : Locale(java.util.Locale) ResourceKeys(com.enonic.xp.resource.ResourceKeys) Test(org.junit.jupiter.api.Test)

Example 5 with ResourceKeys

use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.

the class ResourceServiceImplTest method testFindFiles.

@Test
void testFindFiles() throws Exception {
    newFile("a.txt");
    newFile("b/c.txt");
    newFile("c/d/e.png");
    final ResourceKeys keys1 = this.resourceService.findFiles(this.appKey, ".+");
    assertEquals(3, keys1.getSize());
    assertEquals("[myapp:/b/c.txt, myapp:/a.txt, myapp:/c/d/e.png]", keys1.toString());
    final ResourceKeys keys2 = this.resourceService.findFiles(this.appKey, "b/c\\.txt");
    assertEquals(1, keys2.getSize());
    assertEquals("[myapp:/b/c.txt]", keys2.toString());
    final ResourceKeys keys3 = this.resourceService.findFiles(this.appKey, ".+\\.txt");
    assertEquals(2, keys3.getSize());
    assertEquals("[myapp:/b/c.txt, myapp:/a.txt]", keys3.toString());
}
Also used : 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