// PUT
String[] languages = Locale.getISOLanguages();
final String languageId = languages[random.nextInt(languages.length)];
Page page = objectFactory.createPage();
page.setContent(languageId);
PutMethod putMethod =
executePutXml(
getUriBuilder(PageTranslationResource.class).build(getWiki(), TestConstants.TEST_SPACE_NAME,
TestConstants.TRANSLATIONS_PAGE_NAME, languageId).toString(), page,
TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());
// GET
GetMethod getMethod =
executeGet(getUriBuilder(PageTranslationResource.class).build(getWiki(), TestConstants.TEST_SPACE_NAME,
TestConstants.TRANSLATIONS_PAGE_NAME, languageId).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Page modifiedPage = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
// Some of the language codes returned by Locale#getISOLanguages() are deprecated and Locale's constructors map
// the new codes to the old ones which means the language code we have submitted can be different than the
// actual language code used when the Locale object is created on the server side. Let's go through the Locale
// constructor to be safe.
String expectedLanguage = LocaleUtils.toLocale(languageId).getLanguage();
Assert.assertEquals(expectedLanguage, modifiedPage.getLanguage());
Assert.assertTrue(modifiedPage.getTranslations().getTranslations().size() > 0);
for (Translation translation : modifiedPage.getTranslations().getTranslations()) {
getMethod = executeGet(getFirstLinkByRelation(translation, Relations.PAGE).getHref());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
modifiedPage = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(modifiedPage.getLanguage(), translation.getLanguage());
checkLinks(translation);
}
}