HttpRequestFactory { HttpGet getPageByTitleRequest(String spaceKey, String title) { assertMandatoryParameter(isNotBlank(spaceKey), "spaceKey"); assertMandatoryParameter(isNotBlank(title), "title"); String encodedTitle; try { encodedTitle = URLEncoder.encode(title, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Could not encode title", e); } String searchQuery = this.confluenceRestApiEndpoint + "/content?spaceKey=" + spaceKey + "&title=" + encodedTitle; return new HttpGet(searchQuery); } 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 getPageByTitleRequest_withValidParameters_returnsValidHttpGet() { String spaceKey = "~personalSpace"; String title = "Some page"; HttpGet getPageByTitleRequest = this.httpRequestFactory.getPageByTitleRequest(spaceKey, title); assertThat(getPageByTitleRequest.getMethod(), is("GET")); assertThat(getPageByTitleRequest.getURI().toString(), is(CONFLUENCE_REST_API_ENDPOINT + "/content?spaceKey=" + spaceKey + "&title=" + "Some+page")); }
@Test public void getPageByTitleRequest_withEmptySpaceKey_throwsIllegalArgumentException() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("spaceKey must be set"); this.httpRequestFactory.getPageByTitleRequest("", "Some page"); }
@Test public void getPageByTitleRequest_withEmptyTitle_throwsIllegalArgumentException() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("title must be set"); this.httpRequestFactory.getPageByTitleRequest("~personalSpace", ""); }