HttpRequestFactory { HttpPost addPageUnderAncestorRequest(String spaceKey, String ancestorId, String title, String content, String versionMessage) { assertMandatoryParameter(isNotBlank(spaceKey), "spaceKey"); assertMandatoryParameter(isNotBlank(ancestorId), "ancestorId"); assertMandatoryParameter(isNotBlank(title), "title"); PagePayload pagePayload = pagePayloadBuilder() .spaceKey(spaceKey) .ancestorId(ancestorId) .title(title) .content(content) .version(INITAL_VERSION) .versionMessage(versionMessage) .build(); return addPageHttpPost(this.confluenceRestApiEndpoint, pagePayload); } 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 addPageUnderAncestorRequest_withAncestorId_returnsValidHttpPostWithAncestorIdWithoutSpaceKey() throws Exception { String spaceKey = "~personalSpace"; String ancestorId = "1234"; String title = "title"; String content = "content"; String versionMessage = "version message"; HttpPost addPageUnderAncestorRequest = this.httpRequestFactory.addPageUnderAncestorRequest(spaceKey, ancestorId, title, content, versionMessage); assertThat(addPageUnderAncestorRequest.getMethod(), is("POST")); assertThat(addPageUnderAncestorRequest.getURI().toString(), is(CONFLUENCE_REST_API_ENDPOINT + "/content")); assertThat(addPageUnderAncestorRequest.getFirstHeader("Content-Type").getValue(), is(APPLICATION_JSON_UTF8)); String jsonPayload = inputStreamAsString(addPageUnderAncestorRequest.getEntity().getContent(), UTF_8); String expectedJsonPayload = fileContent(Paths.get(CLASS_LOCATION, "add-page-request-ancestor-id.json").toString(), UTF_8); assertThat(jsonPayload, isSameJsonAs(expectedJsonPayload)); }
@Test public void addPageUnderAncestorRequest_withoutVersionMessage_returnsValidHttpPost() throws Exception { String spaceKey = "~personalSpace"; String ancestorId = "1234"; String title = "title"; String content = "content"; String versionMessage = null; HttpPost addPageUnderAncestorRequest = this.httpRequestFactory.addPageUnderAncestorRequest(spaceKey, ancestorId, title, content, versionMessage); assertThat(addPageUnderAncestorRequest.getMethod(), is("POST")); assertThat(addPageUnderAncestorRequest.getURI().toString(), is(CONFLUENCE_REST_API_ENDPOINT + "/content")); assertThat(addPageUnderAncestorRequest.getFirstHeader("Content-Type").getValue(), is(APPLICATION_JSON_UTF8)); String jsonPayload = inputStreamAsString(addPageUnderAncestorRequest.getEntity().getContent(), UTF_8); String expectedJsonPayload = fileContent(Paths.get(CLASS_LOCATION, "add-page-request-without-version-message.json").toString(), UTF_8); assertThat(jsonPayload, isSameJsonAs(expectedJsonPayload)); }
@Test public void addPageUnderAncestorRequest_withBlankTitle_throwsIllegalArgumentException() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("title must be set"); this.httpRequestFactory.addPageUnderAncestorRequest("~personalSpace", "1234", "", "content", "version message"); }
@Test public void addPageUnderAncestorRequest_withoutAncestorId_throwsIllegalArgumentException() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("ancestorId must be set"); this.httpRequestFactory.addPageUnderAncestorRequest("~personalSpace", "", "title", "content", "version message"); }