}
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 */
String[] languages = Locale.getISOLanguages();
String fakeLanguage = languages[random.nextInt(languages.length)];
String translatedContent =
String.format("This is the content in the '%s' language. (This will be version: %d)", fakeLanguage,
page.getVersion() + 1);
XWikiPage translatedPage = new XWikiPage();
translatedPage.setId(TestConstants.TEST_PAGE_WITH_TRANSLATIONS);
translatedPage.setSpace(TestConstants.TEST_SPACE);
translatedPage.setTitle("Translated page");
translatedPage.setContent(translatedContent);
translatedPage.setLanguage(fakeLanguage);
translatedPage = this.rpc.storePage(translatedPage);
/* 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());
}
}