use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testGETObjectAtPageVersion.
@Test
public void testGETObjectAtPageVersion() throws Exception {
Object objectToBePut = createObjectIfDoesNotExists("XWiki.TagClass", this.spaces, this.pageName);
Map<String, String> versionToValueMap = new HashMap<String, String>();
for (int i = 0; i < 5; i++) {
String value = String.format("Value%d", i);
Property property = getProperty(objectToBePut, "tags");
property.setValue(value);
PutMethod putMethod = executePutXml(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBePut.getClassName(), objectToBePut.getNumber()).toString(), objectToBePut, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode());
GetMethod getMethod = executeGet(buildURI(PageResource.class, getWiki(), this.spaces, this.pageName).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
versionToValueMap.put(page.getVersion(), value);
}
for (String version : versionToValueMap.keySet()) {
GetMethod getMethod = executeGet(buildURI(ObjectAtPageVersionResource.class, getWiki(), this.spaces, this.pageName, version, objectToBePut.getClassName(), objectToBePut.getNumber()).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Object currentObject = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Property property = getProperty(currentObject, "tags");
Assert.assertEquals(versionToValueMap.get(version), property.getValue());
checkLinks(currentObject);
for (Property p : currentObject.getProperties()) {
checkLinks(p);
}
}
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testPUTObject.
@Test
public void testPUTObject() throws Exception {
final String TAG_VALUE = UUID.randomUUID().toString();
Object objectToBePut = createObjectIfDoesNotExists("XWiki.TagClass", this.spaces, this.pageName);
GetMethod getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBePut.getClassName(), objectToBePut.getNumber()).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Object objectSummary = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
getProperty(objectSummary, "tags").setValue(TAG_VALUE);
PutMethod putMethod = executePutXml(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, objectToBePut.getClassName(), objectToBePut.getNumber()).toString(), objectSummary, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode());
Object updatedObjectSummary = (Object) unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
Assert.assertEquals(TAG_VALUE, getProperty(updatedObjectSummary, "tags").getValue());
Assert.assertEquals(objectSummary.getClassName(), updatedObjectSummary.getClassName());
Assert.assertEquals(objectSummary.getNumber(), updatedObjectSummary.getNumber());
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testPUTPropertyWithTextPlain.
@Test
public void testPUTPropertyWithTextPlain() throws Exception {
final String TAG_VALUE = UUID.randomUUID().toString();
/* Make sure that an Object with the TagClass exists. */
createObjectIfDoesNotExists("XWiki.TagClass", this.spaces, this.pageName);
GetMethod getMethod = executeGet(buildURI(PageResource.class, getWiki(), this.spaces, this.pageName).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Link link = getFirstLinkByRelation(page, Relations.OBJECTS);
Assert.assertNotNull(link);
getMethod = executeGet(link.getHref());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Objects objects = (Objects) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertFalse(objects.getObjectSummaries().isEmpty());
Object currentObject = null;
for (ObjectSummary objectSummary : objects.getObjectSummaries()) {
if (objectSummary.getClassName().equals("XWiki.TagClass")) {
link = getFirstLinkByRelation(objectSummary, Relations.OBJECT);
Assert.assertNotNull(link);
getMethod = executeGet(link.getHref());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
currentObject = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
break;
}
}
Assert.assertNotNull(currentObject);
Property tagsProperty = getProperty(currentObject, "tags");
Assert.assertNotNull(tagsProperty);
Link tagsPropertyLink = getFirstLinkByRelation(tagsProperty, Relations.SELF);
Assert.assertNotNull(tagsPropertyLink);
PutMethod putMethod = executePut(tagsPropertyLink.getHref(), TAG_VALUE, MediaType.TEXT_PLAIN, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode());
getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, currentObject.getClassName(), currentObject.getNumber()).toString());
Assert.assertEquals(HttpStatus.SC_OK, getMethod.getStatusCode());
currentObject = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
tagsProperty = getProperty(currentObject, "tags");
Assert.assertEquals(TAG_VALUE, tagsProperty.getValue());
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class PageResourceTest method testPUTGETPage.
@Test
public void testPUTGETPage() throws Exception {
final String title = String.format("Title (%s)", UUID.randomUUID().toString());
final String content = String.format("This is a content (%d)", System.currentTimeMillis());
final String comment = String.format("Updated title and content (%d)", System.currentTimeMillis());
Page originalPage = getFirstPage();
Page newPage = this.objectFactory.createPage();
newPage.setTitle(title);
newPage.setContent(content);
newPage.setComment(comment);
Link link = getFirstLinkByRelation(originalPage, Relations.SELF);
Assert.assertNotNull(link);
// PUT
PutMethod putMethod = executePutXml(link.getHref(), newPage, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode());
Page modifiedPage = (Page) this.unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
Assert.assertEquals(title, modifiedPage.getTitle());
Assert.assertEquals(content, modifiedPage.getContent());
Assert.assertEquals(comment, modifiedPage.getComment());
// GET
GetMethod getMethod = executeGet(link.getHref());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
modifiedPage = (Page) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(title, modifiedPage.getTitle());
Assert.assertEquals(content, modifiedPage.getContent());
Assert.assertEquals(comment, modifiedPage.getComment());
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class PageResourceTest method testPUTGETTranslation.
@Test
public void testPUTGETTranslation() throws Exception {
createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, TestConstants.TRANSLATIONS_PAGE_NAME, "Translations");
// PUT
String[] languages = Locale.getISOLanguages();
final String languageId = languages[random.nextInt(languages.length)];
Page page = objectFactory.createPage();
page.setContent(languageId);
PutMethod putMethod = executePutXml(buildURI(PageTranslationResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TRANSLATIONS_PAGE_NAME, languageId).toString(), page, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());
// GET
GetMethod getMethod = executeGet(buildURI(PageTranslationResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TRANSLATIONS_PAGE_NAME, languageId).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Page modifiedPage = (Page) this.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) this.unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(modifiedPage.getLanguage(), translation.getLanguage());
checkLinks(translation);
}
}
Aggregations