@Test public void getPropertyWithNextLocaleAndFallback() throws RepositoryException { // GIVEN i18nContentSupport.setEnabled(true); Map<String, Locale> locales = new HashMap<String, Locale>(); locales.put("fr_CA", Locale.CANADA_FRENCH); i18nContentSupport.setLocales(locales); i18nContentSupport.setFallbackLocale(Locale.ENGLISH); Node page = session.getRootNode().addNode("test-project"); page.setProperty("title_fr_CA", "titre"); page.setProperty("abstract_en", "abstract"); // WHEN i18nContentSupport.setLocale(Locale.FRENCH); // THEN assertEquals("titre", i18nContentSupport.getProperty(page, "title").getString()); assertEquals("abstract", i18nContentSupport.getProperty(page, "abstract").getString()); }
@Test public void getPropertyWithBothDefaultAndSuffixed() throws RepositoryException { // GIVEN i18nContentSupport.setEnabled(true); i18nContentSupport.setDefaultLocale(Locale.ENGLISH); Node page = session.getRootNode().addNode("test-project"); page.setProperty("title", "globish"); page.setProperty("title_en", "english"); // WHEN i18nContentSupport.setLocale(Locale.ENGLISH); // THEN assertEquals("english", i18nContentSupport.getProperty(page, "title").getString()); }
/** * Test for MAGNOLIA-5931. */ @Test public void getPropertyWithDefaultLocale() throws RepositoryException { // GIVEN i18nContentSupport.setEnabled(true); i18nContentSupport.setDefaultLocale(Locale.GERMAN); i18nContentSupport.setFallbackLocale(Locale.FRENCH); Node page = session.getRootNode().addNode("test-project"); page.setProperty("title", "Titel"); page.setProperty("title_fr", "titre"); // WHEN i18nContentSupport.setLocale(Locale.GERMAN); // THEN assertEquals("Titel", i18nContentSupport.getProperty(page, "title").getString()); }
@Test public void getPropertyWithExplicitCurrentLocale() throws RepositoryException { // GIVEN i18nContentSupport.setEnabled(true); Node page = session.getRootNode().addNode("test-project"); // a property with the current locale suffix page.setProperty("title_fr", "titre"); // WHEN i18nContentSupport.setLocale(Locale.FRENCH); // THEN assertTrue(i18nContentSupport.hasProperty(page, "title")); assertFalse(i18nContentSupport.hasProperty(page, "NotExistingProperty")); assertEquals("titre", i18nContentSupport.getProperty(page, "title").getString()); }
@Test public void getDefaultLocaleIfNull() { // GIVEN i18nContentSupport.setLocale(Locale.JAPANESE); // keep default locale null i18nContentSupport.setFallbackLocale(Locale.ENGLISH); // WHEN Locale defaultLocale = i18nContentSupport.getDefaultLocale(); // THEN assertEquals(defaultLocale, Locale.ENGLISH); }
/** * Test for MAGNOLIA-5993. */ @Test public void getArraysPropertyWithLocale() throws RepositoryException { // GIVEN i18nContentSupport.setEnabled(true); String titles[] = new String[] { "Titel" }; Node page = session.getRootNode().addNode("test-project"); PropertyUtil.setProperty(page, "title_de", Arrays.asList(titles)); // WHEN i18nContentSupport.setLocale(Locale.GERMAN); // THEN assertTrue(i18nContentSupport.getProperty(page, "title").isMultiple()); assertEquals(titles[0], i18nContentSupport.getProperty(page, "title").getValues()[0].getString()); assertEquals(titles.length, i18nContentSupport.getProperty(page, "title").getValues().length); }