HttpRequestFactory { HttpPost updateAttachmentContentRequest(String contentId, String attachmentId, InputStream attachmentContent) { assertMandatoryParameter(isNotBlank(contentId), "contentId"); assertMandatoryParameter(isNotBlank(attachmentId), "attachmentId"); assertMandatoryParameter(attachmentContent != null, "attachmentContent"); HttpPost attachmentPostRequest = new HttpPost(this.confluenceRestApiEndpoint + "/content/" + contentId + "/child/attachment/" + attachmentId + "/data"); attachmentPostRequest.addHeader(new BasicHeader("X-Atlassian-Token", "no-check")); HttpEntity multipartEntity = multipartEntity(null, attachmentContent); attachmentPostRequest.setEntity(multipartEntity); return attachmentPostRequest; } HttpRequestFactory(String rootConfluenceUrl); HttpGet getAttachmentsRequest(String contentId, Integer limit, Integer start, String expandOptions); HttpGet getAttachmentContentRequest(String relativeDownloadLink); HttpGet getPropertyByKeyRequest(String contentId, String key); HttpDelete deletePropertyByKeyRequest(String contentId, String key); HttpPost setPropertyByKeyRequest(String contentId, String key, String value);  }
@Test public void updateAttachmentContentRequest_withValidParameters_returnsHttpPutRequestWithMultipartEntity() throws Exception { String contentId = "1234"; String attachmentId = "45"; InputStream attachmentContent = new ByteArrayInputStream("hello".getBytes()); HttpPost updateAttachmentContentRequest = this.httpRequestFactory.updateAttachmentContentRequest(contentId, attachmentId, attachmentContent); assertThat(updateAttachmentContentRequest.getMethod(), is("POST")); assertThat(updateAttachmentContentRequest.getURI().toString(), is(CONFLUENCE_REST_API_ENDPOINT + "/content/" + contentId + "/child/attachment/" + attachmentId + "/data")); assertThat(updateAttachmentContentRequest.getFirstHeader("X-Atlassian-Token").getValue(), is("no-check")); ByteArrayOutputStream entityContent = new ByteArrayOutputStream(); updateAttachmentContentRequest.getEntity().writeTo(entityContent); String multiPartPayload = entityContent.toString("UTF-8"); assertThat(multiPartPayload, containsString("hello")); }
@Test public void updateAttachmentContentRequest_withEmptyContentId_throwsIllegalArgumentException() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("contentId must be set"); this.httpRequestFactory.updateAttachmentContentRequest("", "45", new ByteArrayInputStream("hello".getBytes())); }
@Test public void updateAttachmentContentRequest_withEmptyAttachmentId_throwsIllegalArgumentException() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("attachmentId must be set"); this.httpRequestFactory.updateAttachmentContentRequest("1234", "", new ByteArrayInputStream("hello".getBytes())); }
@Test public void updateAttachmentContentRequest_withNullAttachmentContent_throwsIllegalArgumentException() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("attachmentContent"); this.httpRequestFactory.updateAttachmentContentRequest("1234", "45", null); }