}
public void testAttachments() throws Exception
{
// Add attachment
Attachment attach0 = new Attachment();
String fileName = "test.txt";
String contentType = "text/plain";
attach0.setFileName(fileName);
attach0.setPageId(pageId);
attach0.setContentType(contentType);
byte[] data0 = new byte[4];
data0[0] = 't';
data0[1] = 'e';
data0[2] = 's';
data0[3] = 't';
Attachment attach00 = rpc.addAttachment(0, attach0, data0);
assertEquals(pageId, attach00.getPageId());
assertEquals(fileName, attach00.getFileName());
assertEquals(fileName, attach00.getTitle());
assertEquals("" + data0.length, attach00.getFileSize());
assertEquals(contentType, attach00.getContentType());
/*The Confluence API is broken for attachment versions. There is no way for knowing what versions of an attachment are available.
Since we are using the Confluence client here, this test cannot be done. */
// // Get attachment versions
// List versions = rpc.getAttachmentVersions(pageId, fileName);
//
// // Get attachment
// Attachment attach000 = rpc.getAttachment(pageId, fileName, (String)versions.get(0));
// assertEquals(attach00.getId(), attach000.getId());
// assertEquals(attach00.getPageId(), attach000.getPageId());
// assertEquals(attach00.getTitle(), attach000.getTitle());
// assertEquals(attach00.getFileName(), attach000.getFileName());
// assertEquals(attach00.getFileSize(), attach000.getFileSize());
// assertEquals(attach00.getContentType(), attach000.getContentType());
// assertEquals(attach00.getCreated(), attach000.getCreated());
// assertEquals(attach00.getCreator(), attach000.getCreator());
// assertEquals(attach00.getUrl(), attach000.getUrl());
// assertEquals(attach00.getComment(), attach000.getComment());
// Get attachment data
byte[] data00 = rpc.getAttachmentData(pageId, fileName, ""/*(String)versions.get(0)*/);
assertEquals(data0.length, data00.length);
for (int i = 0; i < data0.length; i++) {
assertEquals(data0[i], data00[i]);
}
// Remove attachment
rpc.removeAttachment(pageId, fileName);
// Get attachments
List list = rpc.getAttachments(pageId);
assertTrue(list.isEmpty());
// Add two attachments
Attachment attach1 = new Attachment();
String fileName1 = "file1";
attach1.setFileName(fileName1);
attach1.setPageId(pageId);
attach1.setContentType("");
byte[] data1 = new byte[0];
rpc.addAttachment(0, attach1, data1);
Attachment attach2 = new Attachment();
String fileName2 = "file2";
attach2.setFileName(fileName2);
attach2.setPageId(pageId);
attach2.setContentType("");
byte[] data2 = new byte[0];
rpc.addAttachment(0, attach2, data2);
// Get attachments
list = rpc.getAttachments(pageId);