HttpRequestFactory { HttpGet getAttachmentByFileNameRequest(String contentId, String attachmentFileName, String expandOptions) { assertMandatoryParameter(isNotBlank(contentId), "contentId"); assertMandatoryParameter(isNotBlank(attachmentFileName), "attachmentFileName"); URIBuilder uriBuilder = createUriBuilder(this.confluenceRestApiEndpoint + "/content/" + contentId + "/child/attachment"); uriBuilder.addParameter("filename", attachmentFileName); if (isNotBlank(expandOptions)) { uriBuilder.addParameter("expand", expandOptions); } HttpGet getAttachmentByFileNameRequest; try { getAttachmentByFileNameRequest = new HttpGet(uriBuilder.build().toString()); } catch (URISyntaxException e) { throw new RuntimeException("Invalid URL", e); } return getAttachmentByFileNameRequest; } 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 getAttachmentByFileNameRequest_withMinimalParameters_returnsValidHttpGet() { String contentId = "1234"; String attachmentFileName = "file.txt"; HttpGet getAttachmentByFileNameRequest = this.httpRequestFactory.getAttachmentByFileNameRequest(contentId, attachmentFileName, null); assertThat(getAttachmentByFileNameRequest.getURI().toString(), is(CONFLUENCE_REST_API_ENDPOINT + "/content/" + contentId + "/child/attachment?filename=" + attachmentFileName)); }
@Test public void getAttachmentByFileNameRequest_withExpandOptions_returnsValidHttpGetWithExpandOptions() { String contentId = "1234"; String attachmentFileName = "file.txt"; String expandOptions = "version"; HttpGet getAttachmentByFileNameRequest = this.httpRequestFactory.getAttachmentByFileNameRequest(contentId, attachmentFileName, expandOptions); assertThat(getAttachmentByFileNameRequest.getURI().toString(), containsString("filename=" + attachmentFileName)); assertThat(getAttachmentByFileNameRequest.getURI().toString(), containsString("expand=" + expandOptions)); }
@Test public void getAttachmentByFileNameRequest_withEmptyContentId_throwsIllegalArgumentException() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("contentId must be set"); this.httpRequestFactory.getAttachmentByFileNameRequest("", "file.txt", null); }
@Test public void getAttachmentByFileNameRequest_withEmptyAttachmentFileName_throwsIllegalArgumentException() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("attachmentFileName must be set"); this.httpRequestFactory.getAttachmentByFileNameRequest("1234", "", null); }