Search in sources :

Example 66 with PutMethod

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());
}
Also used : PutMethod(org.apache.commons.httpclient.methods.PutMethod) Page(org.xwiki.rest.model.jaxb.Page) Link(org.xwiki.rest.model.jaxb.Link) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 67 with PutMethod

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);
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Tag(org.xwiki.rest.model.jaxb.Tag) PageTagsResource(org.xwiki.rest.resources.pages.PageTagsResource) Tags(org.xwiki.rest.model.jaxb.Tags) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 68 with PutMethod

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);
}
Also used : PageResource(org.xwiki.rest.resources.pages.PageResource) PagesForTagsResource(org.xwiki.rest.resources.tags.PagesForTagsResource) PageTagsResource(org.xwiki.rest.resources.pages.PageTagsResource) TagsResource(org.xwiki.rest.resources.tags.TagsResource) PagesForTagsResource(org.xwiki.rest.resources.tags.PagesForTagsResource) Page(org.xwiki.rest.model.jaxb.Page) Pages(org.xwiki.rest.model.jaxb.Pages) GetMethod(org.apache.commons.httpclient.methods.GetMethod) PutMethod(org.apache.commons.httpclient.methods.PutMethod) Tag(org.xwiki.rest.model.jaxb.Tag) PageSummary(org.xwiki.rest.model.jaxb.PageSummary) Tags(org.xwiki.rest.model.jaxb.Tags) PageTagsResource(org.xwiki.rest.resources.pages.PageTagsResource) Link(org.xwiki.rest.model.jaxb.Link) AbstractHttpTest(org.xwiki.test.rest.framework.AbstractHttpTest) Test(org.junit.Test)

Example 69 with PutMethod

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;
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) HttpClient(org.apache.commons.httpclient.HttpClient) PutMethod(org.apache.commons.httpclient.methods.PutMethod) RequestEntity(org.apache.commons.httpclient.methods.RequestEntity) InputStreamRequestEntity(org.apache.commons.httpclient.methods.InputStreamRequestEntity) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity)

Example 70 with 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;
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) StringWriter(java.io.StringWriter) HttpClient(org.apache.commons.httpclient.HttpClient) PutMethod(org.apache.commons.httpclient.methods.PutMethod) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) RequestEntity(org.apache.commons.httpclient.methods.RequestEntity) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Aggregations

PutMethod (org.apache.commons.httpclient.methods.PutMethod)94 Test (org.junit.Test)49 GetMethod (org.apache.commons.httpclient.methods.GetMethod)29 AbstractHttpTest (org.xwiki.test.rest.framework.AbstractHttpTest)21 StringRequestEntity (org.apache.commons.httpclient.methods.StringRequestEntity)19 Page (org.xwiki.rest.model.jaxb.Page)15 HttpClient (org.apache.commons.httpclient.HttpClient)14 IOException (java.io.IOException)13 RequestEntity (org.apache.commons.httpclient.methods.RequestEntity)13 DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)12 PostMethod (org.apache.commons.httpclient.methods.PostMethod)10 InputStreamRequestEntity (org.apache.commons.httpclient.methods.InputStreamRequestEntity)7 DeleteMethod (org.apache.jackrabbit.webdav.client.methods.DeleteMethod)7 Link (org.xwiki.rest.model.jaxb.Link)7 Header (org.apache.commons.httpclient.Header)6 HttpMethod (org.apache.commons.httpclient.HttpMethod)6 FileRequestEntity (org.apache.commons.httpclient.methods.FileRequestEntity)6 File (java.io.File)5 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)5 Object (org.xwiki.rest.model.jaxb.Object)5