HttpRequestFactory { public HttpGet getAttachmentsRequest(String contentId, Integer limit, Integer start, String expandOptions) { assertMandatoryParameter(isNotBlank(contentId), "contentId"); URIBuilder uriBuilder = createUriBuilder(this.confluenceRestApiEndpoint + "/content/" + contentId + "/child/attachment"); if (limit != null) { uriBuilder.addParameter("limit", limit.toString()); } if (start != null) { uriBuilder.addParameter("start", start.toString()); } if (isNotBlank(expandOptions)) { uriBuilder.addParameter("expand", expandOptions); } HttpGet getAttachmentsRequest; try { getAttachmentsRequest = new HttpGet(uriBuilder.build().toString()); } catch (URISyntaxException e) { throw new RuntimeException("Invalid URL", e); } return getAttachmentsRequest; } 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 getAttachmentsRequest_withMinimalParameters_returnsValidHttpGetRequest() { String contentId = "1234"; HttpGet getAttachmentsRequest = this.httpRequestFactory.getAttachmentsRequest(contentId, null, null, null); assertThat(getAttachmentsRequest.getURI().toString(), is(CONFLUENCE_REST_API_ENDPOINT + "/content/" + contentId + "/child/attachment")); }
@Test public void getAttachmentsRequest_withLimit_returnsHttpGetWithLimit() { String contentId = "1234"; int limit = 5; HttpGet getAttachmentsRequest = this.httpRequestFactory.getAttachmentsRequest(contentId, limit, null, null); assertThat(getAttachmentsRequest.getURI().toString(), is(CONFLUENCE_REST_API_ENDPOINT + "/content/" + contentId + "/child/attachment?limit=" + limit)); }
@Test public void getAttachmentsRequest_withPageNumber_returnsHttpGetWithPage() { String contentId = "1234"; int start = 1; HttpGet getAttachmentsRequest = this.httpRequestFactory.getAttachmentsRequest(contentId, null, start, null); assertThat(getAttachmentsRequest.getURI().toString(), is(CONFLUENCE_REST_API_ENDPOINT + "/content/" + contentId + "/child/attachment?start=" + start)); }
@Test public void getAttachmentsRequest_withLimitAndPageNumberAndExpandOptions_returnsHttpGetWithLimitAndPage() { String contentId = "1234"; int limit = 5; int start = 1; String expandOptions = "version"; HttpGet getAttachmentsRequest = this.httpRequestFactory.getAttachmentsRequest(contentId, limit, start, expandOptions); assertThat(getAttachmentsRequest.getURI().toString(), containsString("limit=" + limit)); assertThat(getAttachmentsRequest.getURI().toString(), containsString("start=" + start)); assertThat(getAttachmentsRequest.getURI().toString(), containsString("expand=" + expandOptions)); }