use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class WikiManagerRestTest method testMultiwikiSearch.
// FIXME: Test is disabled for the moment. It works if tested against MySQL but with HSQLDB it seems that the
// Lucene plugin is not triggered. Anyway this should be better to rewrite it, if possible, as a unit test.
@Ignore("This test doesn't seem to work correctly with HSQLDB but it actually works if run against MySQL.")
@Test
public void testMultiwikiSearch() throws Exception {
String WIKI1_ID = "w1";
String WIKI2_ID = "w2";
String PAGE_SPACE = "Main";
String PAGE_NAME = "Test";
String PAGE1_STRING = "foo";
String PAGE2_STRING = "bar";
Wiki wiki = objectFactory.createWiki();
wiki.setId(WIKI1_ID);
PostMethod postMethod = executePost(getFullUri(WikiManagerREST.class), "superadmin", "pass", wiki);
Assert.assertEquals(HttpStatus.SC_CREATED, postMethod.getStatusCode());
wiki = objectFactory.createWiki();
wiki.setId(WIKI2_ID);
postMethod = executePost(getFullUri(WikiManagerREST.class), "superadmin", "pass", wiki);
Assert.assertEquals(HttpStatus.SC_CREATED, postMethod.getStatusCode());
/* Store the page */
Page page1 = objectFactory.createPage();
page1.setTitle(PAGE1_STRING);
page1.setContent(PAGE1_STRING);
PutMethod putMethod = executePut(getUriBuilder(PageResource.class).build(WIKI1_ID, PAGE_SPACE, PAGE_NAME).toString(), "superadmin", "pass", page1);
Assert.assertEquals(HttpStatus.SC_CREATED, putMethod.getStatusCode());
page1 = (Page) unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
/* Retrieve the page to check that it exists */
GetMethod getMethod = executeGet(getUriBuilder(PageResource.class).build(WIKI1_ID, PAGE_SPACE, PAGE_NAME).toString());
Assert.assertEquals(HttpStatus.SC_OK, getMethod.getStatusCode());
Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(WIKI1_ID, page.getWiki());
Assert.assertEquals(PAGE_SPACE, page.getSpace());
Assert.assertEquals(PAGE_NAME, page.getName());
Assert.assertEquals(PAGE1_STRING, page.getTitle());
Assert.assertEquals(PAGE1_STRING, page.getContent());
Assert.assertEquals(page1.getCreated(), page.getCreated());
Assert.assertEquals(page1.getModified(), page.getModified());
/* Store the page */
Page page2 = objectFactory.createPage();
page2.setTitle(PAGE2_STRING);
page2.setContent(PAGE2_STRING);
putMethod = executePut(getUriBuilder(PageResource.class).build(WIKI2_ID, PAGE_SPACE, PAGE_NAME).toString(), "superadmin", "pass", page2);
Assert.assertEquals(HttpStatus.SC_CREATED, putMethod.getStatusCode());
page2 = (Page) unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
/* Retrieve the page to check that it exists */
getMethod = executeGet(getUriBuilder(PageResource.class).build(WIKI2_ID, PAGE_SPACE, PAGE_NAME).toString());
Assert.assertEquals(HttpStatus.SC_OK, getMethod.getStatusCode());
page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(WIKI2_ID, page.getWiki());
Assert.assertEquals(PAGE_SPACE, page.getSpace());
Assert.assertEquals(PAGE_NAME, page.getName());
Assert.assertEquals(PAGE2_STRING, page.getTitle());
Assert.assertEquals(PAGE2_STRING, page.getContent());
Assert.assertEquals(page2.getCreated(), page.getCreated());
Assert.assertEquals(page2.getModified(), page.getModified());
/* Wait a bit that the Lucene Indexer indexes the pages. */
Thread.sleep(5000);
getMethod = executeGet(URIUtil.encodeQuery(String.format("%s?q=\"%s\"&wikis=w1,w2", getFullUri(WikisSearchQueryResource.class), PAGE_NAME)));
Assert.assertEquals(HttpStatus.SC_OK, getMethod.getStatusCode());
SearchResults searchResults = (SearchResults) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertEquals(2, searchResults.getSearchResults().size());
for (SearchResult searchResult : searchResults.getSearchResults()) {
Page pageToBeCheckedAgainst = null;
if (searchResult.getWiki().equals(WIKI1_ID)) {
pageToBeCheckedAgainst = page1;
} else {
pageToBeCheckedAgainst = page2;
}
Assert.assertEquals(pageToBeCheckedAgainst.getWiki(), searchResult.getWiki());
Assert.assertEquals(pageToBeCheckedAgainst.getTitle(), searchResult.getTitle());
Assert.assertEquals(pageToBeCheckedAgainst.getAuthor(), searchResult.getAuthor());
Assert.assertEquals(pageToBeCheckedAgainst.getModified(), searchResult.getModified());
Assert.assertEquals(pageToBeCheckedAgainst.getVersion(), searchResult.getVersion());
}
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class AttachmentsResourceTest method testDELETEAttachment.
@Test
public void testDELETEAttachment() throws Exception {
String attachmentName = String.format("%d.txt", System.currentTimeMillis());
String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName);
String content = "ATTACHMENT CONTENT";
PutMethod putMethod = executePut(attachmentURI, content, MediaType.TEXT_PLAIN, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());
GetMethod getMethod = executeGet(attachmentURI);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
DeleteMethod deleteMethod = executeDelete(attachmentURI, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_NO_CONTENT, deleteMethod.getStatusCode());
getMethod = executeGet(attachmentURI);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class AttachmentsResourceTest method testDELETEAttachmentNoRights.
@Test
public void testDELETEAttachmentNoRights() throws Exception {
String attachmentName = String.format("%d.txt", System.currentTimeMillis());
String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName);
String content = "ATTACHMENT CONTENT";
PutMethod putMethod = executePut(attachmentURI, content, MediaType.TEXT_PLAIN, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());
DeleteMethod deleteMethod = executeDelete(attachmentURI);
Assert.assertEquals(getHttpMethodInfo(deleteMethod), HttpStatus.SC_UNAUTHORIZED, deleteMethod.getStatusCode());
GetMethod getMethod = executeGet(attachmentURI);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class AttachmentsResourceTest method putAttachmentFilename.
protected void putAttachmentFilename(String attachmentName, String type) throws Exception {
String content = "ATTACHMENT CONTENT";
String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName);
GetMethod getMethod = executeGet(attachmentURI);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
PutMethod putMethod = executePut(attachmentURI, content, MediaType.TEXT_PLAIN, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode());
getMethod = executeGet(attachmentURI);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Assert.assertEquals(content, getMethod.getResponseBodyAsString());
}
use of org.apache.commons.httpclient.methods.PutMethod in project xwiki-platform by xwiki.
the class AttachmentsResourceTest method testPUTAttachmentNoRights.
@Test
public void testPUTAttachmentNoRights() throws Exception {
String attachmentName = String.format("%s.txt", UUID.randomUUID());
String attachmentURI = buildURIForThisPage(AttachmentResource.class, attachmentName);
String content = "ATTACHMENT CONTENT";
GetMethod getMethod = executeGet(attachmentURI);
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_NOT_FOUND, getMethod.getStatusCode());
PutMethod putMethod = executePut(attachmentURI, content, MediaType.TEXT_PLAIN);
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_UNAUTHORIZED, putMethod.getStatusCode());
}
Aggregations