Package org.codehaus.swizzle.confluence

Examples of org.codehaus.swizzle.confluence.Attachment


    public void testAddAttachment() throws Exception
    {
        String attachmentName = String.format("test_attachment_%d.png", random.nextInt());
        byte[] data = ("Data for " + attachmentName).getBytes();

        Attachment attachment = new Attachment();
        attachment.setPageId(TestConstants.TEST_PAGE_WITH_ATTACHMENTS);
        attachment.setFileName(attachmentName);

        attachment = rpc.addAttachment(0, attachment, data);

        TestUtils.banner("TEST: addAttachment()");
        System.out.format("%s\n", attachment);

        // We can't assert the file name because it can be transformed (e.g. some characters could be removed).
        assertEquals(data.length, Integer.parseInt(attachment.getFileSize()));

        // Let's see if the attachment was properly added.
        assertEquals(new String(data), new String(rpc.getAttachmentData(attachment.getPageId(), attachment
            .getFileName(), "1.1")));
    }
View Full Code Here


    }

    public void testGetAttachmentData() throws Exception
    {
        List<Attachment> attachments = rpc.getAttachments(TestConstants.TEST_PAGE_WITH_ATTACHMENTS);
        Attachment attachment = attachments.get(0);

        byte[] content = rpc.getAttachmentData(attachment.getPageId(), attachment.getFileName(), "1.1");

        TestUtils.banner("getAttachmentData()");
        System.out.format("%s\n", attachment);
        System.out.format("Content = %s\n", Utils.truncateToFirstLine(new String(content, 0, content.length > 32 ? 32
            : content.length)));

        int contentLength = new Integer(attachment.getFileSize());
        assertTrue(content.length == contentLength);
    }
View Full Code Here

    }

    public void testRemoveAttachment() throws Exception
    {
        List<Attachment> attachments = rpc.getAttachments(TestConstants.TEST_PAGE_WITH_ATTACHMENTS);
        Attachment attachmentToBeRemoved = attachments.get(random.nextInt(attachments.size()));

        TestUtils.banner("TEST: testRemoveAttachment()");
        System.out.format("Before: %s\n", attachments);
        Boolean result = rpc.removeAttachment(attachmentToBeRemoved.getPageId(), attachmentToBeRemoved.getFileName());

        System.out.format("Result: %b\n", result);

        attachments = rpc.getAttachments(TestConstants.TEST_PAGE_WITH_ATTACHMENTS);
        System.out.format("After: %s\n", attachments);
        boolean found = false;
        for (Attachment attachment : attachments) {
            if (attachment.getFileName().equals(attachmentToBeRemoved.getFileName())) {
                found = true;
                break;
            }
        }
View Full Code Here

        addAttachment("first.txt", "Content of first attachment.");
    }

    private Attachment addAttachment(String fileName, String content) throws Exception
    {
        Attachment attachment = new Attachment();
        attachment.setPageId(TestConstants.TEST_PAGE_WITH_ATTACHMENTS);
        attachment.setFileName(fileName);
        return rpc.addAttachment(0, attachment, content.getBytes());
    }
View Full Code Here

    public void testAddAttachment() throws Exception
    {
        String attachmentName = String.format("test_attachment_%d.png", random.nextInt());
        String attachmentData = "Data for " + attachmentName;
        Attachment attachment = addAttachment(attachmentName, "Data for " + attachmentName);

        TestUtils.banner("TEST: addAttachment()");
        System.out.format("%s\n", attachment);

        // We can't assert the file name because it can be transformed (e.g. some characters could be removed).
        assertEquals(attachmentData.getBytes().length, Integer.parseInt(attachment.getFileSize()));

        // Let's see if the attachment was properly added.
        assertEquals(attachmentData,
            new String(rpc.getAttachmentData(attachment.getPageId(), attachment.getFileName(), "1.1")));
    }
View Full Code Here

    }

    public void testGetAttachmentData() throws Exception
    {
        List<Attachment> attachments = rpc.getAttachments(TestConstants.TEST_PAGE_WITH_ATTACHMENTS);
        Attachment attachment = attachments.get(0);

        byte[] content = rpc.getAttachmentData(attachment.getPageId(), attachment.getFileName(), "1.1");

        TestUtils.banner("getAttachmentData()");
        System.out.format("%s\n", attachment);
        System.out.format("Content = %s\n",
            Utils.truncateToFirstLine(new String(content, 0, content.length > 32 ? 32 : content.length)));

        int contentLength = new Integer(attachment.getFileSize());
        assertTrue(content.length == contentLength);
    }
View Full Code Here

    }

    public void testRemoveAttachment() throws Exception
    {
        List<Attachment> attachments = rpc.getAttachments(TestConstants.TEST_PAGE_WITH_ATTACHMENTS);
        Attachment attachmentToBeRemoved = attachments.get(random.nextInt(attachments.size()));

        TestUtils.banner("TEST: testRemoveAttachment()");
        System.out.format("Before: %s\n", attachments);
        Boolean result = rpc.removeAttachment(attachmentToBeRemoved.getPageId(), attachmentToBeRemoved.getFileName());

        System.out.format("Result: %b\n", result);

        attachments = rpc.getAttachments(TestConstants.TEST_PAGE_WITH_ATTACHMENTS);
        System.out.format("After: %s\n", attachments);
        boolean found = false;
        for (Attachment attachment : attachments) {
            if (attachment.getFileName().equals(attachmentToBeRemoved.getFileName())) {
                found = true;
                break;
            }
        }
View Full Code Here

    }

    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);
View Full Code Here

TOP

Related Classes of org.codehaus.swizzle.confluence.Attachment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.