String newContent = "New Content";
DeleteMethod deleteMethod = new DeleteMethod();
deleteMethod.setDoAuthentication(true);
MkcolMethod mkColMethod = new MkcolMethod();
mkColMethod.setDoAuthentication(true);
PutMethod putMethod = new PutMethod();
putMethod.setDoAuthentication(true);
GetMethod getMethod = new GetMethod();
getMethod.setDoAuthentication(true);
try {
deleteMethod.setPath(spaceUrl);
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
mkColMethod.setPath(spaceUrl);
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
mkColMethod.setPath(pageUrl);
assertEquals(DavServletResponse.SC_CREATED, getHttpClient().executeMethod(mkColMethod));
putMethod.setPath(wikiTextFileUrl);
putMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(newContent.getBytes())));
// Already existing resource, in which case SC_NO_CONTENT will be the return status.
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(putMethod));
getMethod.setPath(wikiTextFileUrl);
assertEquals(DavServletResponse.SC_OK, getHttpClient().executeMethod(getMethod));
assertEquals(newContent, getMethod.getResponseBodyAsString());
putMethod.setPath(wikiXMLFileUrl);
putMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(newContent.getBytes())));
// XML saving was disabled recently. See http://jira.xwiki.org/jira/browse/XWIKI-2910
assertEquals(DavServletResponse.SC_METHOD_NOT_ALLOWED, getHttpClient().executeMethod(putMethod));
deleteMethod.setPath(pageUrl);
assertEquals(DavServletResponse.SC_NO_CONTENT, getHttpClient().executeMethod(deleteMethod));
deleteMethod.setPath(spaceUrl);