}
public void testStoreNewPageTranslation() throws Exception
{
/* Get the current page and all its available translations */
XWikiPage page = this.rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS);
Map<String, XWikiPage> before = new HashMap<String, XWikiPage>();
before.put(page.getLanguage(), page);
for (String l : page.getTranslations()) {
XWikiPage p = this.rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS, l);
before.put(l, p);
}
/* Add a translation in a fake language */
// Get the list of ISO 639 language codes. Unfortunately this list contains some deprecated codes.
String[] languages = Locale.getISOLanguages();
// We need to use the deprecated language codes because the Locale class rewrites the language codes even if you
// construct your own Locale object, not just for instances returned by the various lookup methods.
Map<String, String> deprecatedCodes = new HashMap<String, String>();
deprecatedCodes.put("he", "iw");
deprecatedCodes.put("id", "in");
deprecatedCodes.put("yi", "ji");
String fakeLanguage = languages[random.nextInt(languages.length)];
if (deprecatedCodes.containsKey(fakeLanguage)) {
// Use the deprecated language code instead.
fakeLanguage = deprecatedCodes.get(fakeLanguage);
}
String translatedContent =
String.format("This is the content in the '%s' language. (This will be version: %d)", fakeLanguage,
page.getVersion() + 1);
addTranslation(fakeLanguage, "Translated page", translatedContent);
/* Re-get the page and all its translations */
page = this.rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS);
Map<String, XWikiPage> after = new HashMap<String, XWikiPage>();
after.put(page.getLanguage(), page);
for (String l : page.getTranslations()) {
XWikiPage p = this.rpc.getPage(TestConstants.TEST_PAGE_WITH_TRANSLATIONS, l);
after.put(l, p);
}
TestUtils.banner("TEST: storeNewPageTranslation()");
System.out.format("Adding the '%s' translation...\n", fakeLanguage);
System.out.format("*********************************\n");
System.out.format("Before: %s\n", before);
System.out.format("*********************************\n");
System.out.format("After: %s\n", after);
/* Check for correctenss */
assertFalse(before.containsKey(fakeLanguage));
assertTrue(after.containsKey(fakeLanguage));
assertEquals(translatedContent, after.get(fakeLanguage).getContent());
for (String l : before.keySet()) {
assertTrue(after.containsKey(l));
XWikiPage b = before.get(l);
XWikiPage a = after.get(l);
assertEquals(b.getVersion(), a.getVersion());
assertEquals(b.getContent(), a.getContent());
}
}