Package com.taskadapter.redmineapi.bean

Examples of com.taskadapter.redmineapi.bean.Attachment


        assertThat(specificPage.getCreatedOn()).isNotNull();
        assertThat(specificPage.getUpdatedOn()).isNotNull();
        assertThat(specificPage.getAttachments()).isNotNull();
        assertThat(specificPage.getAttachments().size()).isEqualTo(1);

        Attachment attachment = specificPage.getAttachments().get(0);

        assertThat(attachment.getFileName()).isEqualTo("happy_penguin.jpg");
        assertThat(attachment.getId()).isEqualTo(8);
        assertThat(attachment.getFileSize()).isEqualTo(72158);
        assertThat(attachment.getAuthor().getFullName()).isEqualTo("Redmine Admin");
        assertThat(attachment.getContentURL()).isEqualTo("http://76.126.10.142/redmine/attachments/download/8/happy_penguin.jpg");
    }
View Full Code Here


    return result;
  }

  public static Attachment parseAttachments(JSONObject content)
      throws JSONException {
    final Attachment result = AttachmentFactory.create(JsonInput.getIntOrNull(content, "id"));
    result.setFileName(JsonInput.getStringOrNull(content, "filename"));
    result.setFileSize(JsonInput.getLong(content, "filesize"));
    result.setContentType(JsonInput
        .getStringOrNull(content, "content_type"));
    result.setContentURL(JsonInput.getStringOrNull(content, "content_url"));
    result.setDescription(JsonInput.getStringOrNull(content, "description"));
    result.setCreatedOn(getDateOrNull(content, "created_on"));
    result.setAuthor(JsonInput.getObjectOrNull(content, "author",
        USER_PARSER));
    return result;
  }
View Full Code Here

     *                    text or image or binary. see http://en.wikipedia.org/wiki/Internet_media_type for possible MIME types.
     *                    sample value: ContentType.TEXT_PLAIN.getMimeType()
     * @return the created attachment object.
     */
    public Attachment addAttachmentToIssue(Integer issueId, File attachmentFile, String contentType) throws RedmineException, IOException {
        final Attachment attach = uploadAttachment(contentType, attachmentFile);
        final Issue issue = IssueFactory.create(issueId);
        issue.addAttachment(attach);
        transport.updateObject(issue);
        return attach;
    }
View Full Code Here

        final InputStream wrapper = new MarkedInputStream(content,
                "uploadStream");
        final String token;
        try {
            token = transport.upload(wrapper);
            final Attachment result = AttachmentFactory.create();
            result.setToken(token);
            result.setContentType(contentType);
            result.setFileName(fileName);
            return result;
        } catch (RedmineException e) {
            unwrapException(e, "uploadStream");
            throw e;
        }
View Full Code Here

    }

    @Test
    public void uploadAttachment() throws RedmineException, IOException {
        final byte[] content = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        final Attachment attach1 = attachmentManager.uploadAttachment("test.bin",
                "application/ternary", content);
        final Issue testIssue = IssueFactory.createWithSubject("This is upload ticket!");
        testIssue.addAttachment(attach1);
        final Issue createdIssue = issueManager.createIssue(projectKey, testIssue);
        try {
            final Collection<Attachment> attachments = createdIssue.getAttachments();
            assertThat(attachments.size()).isEqualTo(1);
            final Attachment added = attachments.iterator().next();
            assertThat(added.getFileName()).isEqualTo("test.bin");
            assertThat(added.getContentType()).isEqualTo("application/ternary");
            final byte[] receivedContent = attachmentManager.downloadAttachmentContent(added);
            assertArrayEquals(content, receivedContent);

            Issue issueById = issueManager.getIssueById(createdIssue.getId(), Include.attachments);
            assertThat(issueById.getAttachments().size()).isEqualTo(1);
View Full Code Here

        final Issue createdIssue = issueManager.createIssue(projectKey, issue);
        attachmentManager.addAttachmentToIssue(createdIssue.getId(), tempFile, ContentType.TEXT_PLAIN.getMimeType());
        try {
            Issue loadedIssue = issueManager.getIssueById(createdIssue.getId(), Include.attachments);
            final Collection<Attachment> attachments = loadedIssue.getAttachments();
            Attachment next = attachments.iterator().next();
            assertThat(next.getFileName()).isEqualTo(tempFile.getName());
            final byte[] receivedContent = attachmentManager.downloadAttachmentContent(next);
            String contentAsString = new String(receivedContent);
            assertThat(contentAsString).isEqualTo(attachmentContent);
        } finally {
            issueManager.deleteIssue(createdIssue.getId());
View Full Code Here

    public void testGetAttachmentById() throws RedmineException {
        // TODO where do we get a valid attachment number from? We can't create
        // an attachment by our own for the test as the Redmine REST API does
        // not support that.
        int attachmentID = 1;
        Attachment attachment = attachmentManager.getAttachmentById(attachmentID);
        assertNotNull("Attachment retrieved by ID " + attachmentID
                + " should not be null", attachment);
        assertNotNull("Content URL of attachment retrieved by ID "
                + attachmentID + " should not be null",
                attachment.getContentURL());
        // TODO more asserts on the attachment once this delivers an attachment
    }
View Full Code Here

        // TODO where do we get a valid attachment number from? We can't create
        // an attachment by our own for the test as the Redmine REST API does
        // not support that.
        int attachmentID = 1;
        // retrieve issue attachment
        Attachment attachment = attachmentManager.getAttachmentById(attachmentID);
        // download attachment content
        byte[] attachmentContent = attachmentManager.downloadAttachmentContent(attachment);
        assertNotNull("Download of content of attachment with content URL " + attachment.getContentURL()
                + " should not be null", attachmentContent);
    }
View Full Code Here

    @SuppressWarnings("unused")
  private static void tryUpload(RedmineManager mgr, IssueManager issueManager, AttachmentManager attachmentManager) throws RedmineException,
      IOException {
    final byte[] content = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    final Attachment attach1 = attachmentManager.uploadAttachment("test.bin",
        "application/ternary", content);
    final Issue testIssue = new Issue();
    testIssue.setSubject("This is upload ticket!");
    testIssue.addAttachment(attach1);
    final Project tmpProject = ProjectFactory.create("Upload project", "uploadtmpproject");
View Full Code Here

TOP

Related Classes of com.taskadapter.redmineapi.bean.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.