use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class PageResourceTest method testPUTPageSyntax.
@Test
public void testPUTPageSyntax() throws Exception {
Page originalPage = getFirstPage();
// Use the plain/1.0 syntax since we are sure that the test page does not already use it.
String newSyntax = "plain/1.0";
originalPage.setSyntax(newSyntax);
Link link = getFirstLinkByRelation(originalPage, Relations.SELF);
Assert.assertNotNull(link);
PutMethod putMethod = executePutXml(link.getHref(), originalPage, 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(newSyntax, modifiedPage.getSyntax());
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class TagsResourceTest method testPUTTagsWithTextPlain.
@Test
public void testPUTTagsWithTextPlain() throws Exception {
createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME, "Test");
String tagName = UUID.randomUUID().toString();
GetMethod getMethod = executeGet(buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
PutMethod putMethod = executePut(buildURI(PageTagsResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString(), tagName, 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(PageTagsResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Tags tags = (Tags) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
boolean found = false;
for (Tag t : tags.getTags()) {
if (tagName.equals(t.getName())) {
found = true;
break;
}
}
Assert.assertTrue(found);
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class TagsResourceTest method testRepresentation.
@Override
@Test
public void testRepresentation() throws Exception {
String tagName = UUID.randomUUID().toString();
createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME, "Test");
GetMethod getMethod = executeGet(buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Tags tags = objectFactory.createTags();
Tag tag = objectFactory.createTag();
tag.setName(tagName);
tags.getTags().add(tag);
PutMethod putMethod = executePutXml(buildURI(PageTagsResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString(), tags, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode());
getMethod = executeGet(buildURI(PageTagsResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
tags = (Tags) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
boolean found = false;
for (Tag t : tags.getTags()) {
if (tagName.equals(t.getName())) {
found = true;
break;
}
}
Assert.assertTrue(found);
getMethod = executeGet(buildURI(TagsResource.class, getWiki()).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
tags = (Tags) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
found = false;
for (Tag t : tags.getTags()) {
if (tagName.equals(t.getName())) {
found = true;
break;
}
}
Assert.assertTrue(found);
getMethod = executeGet(buildURI(PagesForTagsResource.class, getWiki(), tagName).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Pages pages = (Pages) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
found = false;
for (PageSummary pageSummary : pages.getPageSummaries()) {
if (pageSummary.getFullName().equals(String.format("%s.%s", TestConstants.TEST_SPACE_NAME.get(0), TestConstants.TEST_PAGE_NAME))) {
found = true;
}
}
Assert.assertTrue(found);
getMethod = executeGet(buildURI(PageResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TEST_PAGE_NAME).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Link tagsLink = getFirstLinkByRelation(page, Relations.TAGS);
Assert.assertNotNull(tagsLink);
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class AbstractHttpTest method executePut.
protected PutMethod executePut(String uri, String string, String mediaType) throws Exception {
HttpClient httpClient = new HttpClient();
PutMethod putMethod = new PutMethod(uri);
RequestEntity entity = new StringRequestEntity(string, mediaType, "UTF-8");
putMethod.setRequestEntity(entity);
httpClient.executeMethod(putMethod);
return putMethod;
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class WikiManagerRestTest method executePut.
protected PutMethod executePut(String uri, String userName, String password, Object object) throws Exception {
HttpClient httpClient = new HttpClient();
httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
httpClient.getParams().setAuthenticationPreemptive(true);
PutMethod putMethod = new PutMethod(uri);
putMethod.addRequestHeader("Accept", MediaType.APPLICATION_XML.toString());
StringWriter writer = new StringWriter();
marshaller.marshal(object, writer);
RequestEntity entity = new StringRequestEntity(writer.toString(), MediaType.APPLICATION_XML.toString(), "UTF-8");
putMethod.setRequestEntity(entity);
httpClient.executeMethod(putMethod);
return putMethod;
}
Aggregations