doPostAsAdmin(spaceName, pageName, null, "delete", "confirm=1", null);
// Create a document. v1.1
doPostAsAdmin(spaceName, pageName, null, "save", null, null);
HttpMethod ret = null;
// Upload the attachment v2.1
ret = doUploadAsAdmin(spaceName, pageName,
new HashMap<String, byte[]>() {{
put(FILENAME, ATTACHMENT_CONTENT.getBytes());
}});
// Make sure it's there.
Assert.assertEquals(ATTACHMENT_CONTENT, TestUtils.getPageAsString(attachURL));
// Delete it v3.1
doPostAsAdmin(spaceName, pageName, FILENAME, "delattachment", null, null);
// Upload again v4.1
ret = doUploadAsAdmin(spaceName, pageName,
new HashMap<String, byte[]>() {{
put(FILENAME, versionTwo.getBytes());
}});
// Make sure it's there.
Assert.assertEquals(versionTwo, TestUtils.getPageAsString(attachURL));
// Do a rollback. v5.1
doPostAsAdmin(spaceName, pageName, null, "rollback", "rev=2.1&confirm=1", null);
// Make sure the latest current version is actually v5.1
ret = doPostAsAdmin(spaceName, pageName, null, "preview", "xpage=plain",
new HashMap<String, String>() {{
put("content", "{{velocity}}$doc.getVersion(){{/velocity}}");
}});
Assert.assertEquals("<p>5.1</p>", new String(ret.getResponseBody(), "UTF-8"));
// Make sure it is version1
Assert.assertEquals(ATTACHMENT_CONTENT, TestUtils.getPageAsString(attachURL));
// Do rollback to version2. v6.1
doPostAsAdmin(spaceName, pageName, null, "rollback", "rev=4.1&confirm=1", null);
// Make sure it is version2
Assert.assertEquals(versionTwo, TestUtils.getPageAsString(attachURL));
// Make sure the latest current version is actually v6.1
ret = doPostAsAdmin(spaceName, pageName, null, "preview", "xpage=plain",
new HashMap<String, String>() {{
put("content", "{{velocity}}$doc.getVersion(){{/velocity}}");
}});
Assert.assertEquals("<p>6.1</p>", new String(ret.getResponseBody(), "UTF-8"));
}