HttpRequestFactory { HttpPut updatePageRequest(String contentId, String ancestorId, String title, String content, int newVersion, String versionMessage) { assertMandatoryParameter(isNotBlank(contentId), "contentId"); assertMandatoryParameter(isNotBlank(title), "title"); PagePayload pagePayload = pagePayloadBuilder() .ancestorId(ancestorId) .title(title) .content(content) .version(newVersion) .versionMessage(versionMessage) .build(); HttpPut updatePageRequest = new HttpPut(this.confluenceRestApiEndpoint + "/content/" + contentId); updatePageRequest.setEntity(httpEntityWithJsonPayload(pagePayload)); updatePageRequest.addHeader(APPLICATION_JSON_UTF8_HEADER); return updatePageRequest; } 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 updatePageRequest_withValidParametersWithAncestorId_returnsValidHttpPutRequest() throws Exception { String contentId = "1234"; String ancestorId = "1"; String title = "title"; String content = "content"; Integer version = 2; String versionMessage = "version message"; HttpPut updatePageRequest = this.httpRequestFactory.updatePageRequest(contentId, ancestorId, title, content, version, versionMessage); assertThat(updatePageRequest.getMethod(), is("PUT")); assertThat(updatePageRequest.getURI().toString(), is(CONFLUENCE_REST_API_ENDPOINT + "/content/" + contentId)); assertThat(updatePageRequest.getFirstHeader("Content-Type").getValue(), is(APPLICATION_JSON_UTF8)); String jsonPayload = inputStreamAsString(updatePageRequest.getEntity().getContent(), UTF_8); String expectedJsonPayload = fileContent(Paths.get(CLASS_LOCATION, "update-page-request-with-ancestor-id.json").toString(), UTF_8); assertThat(jsonPayload, isSameJsonAs(expectedJsonPayload)); }
@Test public void updatePageRequest_withValidParametersWithoutAncestorId_returnsValidHttpPutRequest() throws Exception { String contentId = "1234"; String ancestorId = null; String title = "title"; String content = "content"; Integer version = 2; String versionMessage = null; HttpPut updatePageRequest = this.httpRequestFactory.updatePageRequest(contentId, ancestorId, title, content, version, versionMessage); assertThat(updatePageRequest.getMethod(), is("PUT")); assertThat(updatePageRequest.getURI().toString(), is(CONFLUENCE_REST_API_ENDPOINT + "/content/" + contentId)); assertThat(updatePageRequest.getFirstHeader("Content-Type").getValue(), is(APPLICATION_JSON_UTF8)); String jsonPayload = inputStreamAsString(updatePageRequest.getEntity().getContent(), UTF_8); String expectedJsonPayload = fileContent(Paths.get(CLASS_LOCATION, "update-page-request-without-ancestor-id.json").toString(), UTF_8); assertThat(jsonPayload, isSameJsonAs(expectedJsonPayload)); }
@Test public void updatePageRequest_withEmptyContentId_throwsIllegalArgumentException() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("contentId must be set"); this.httpRequestFactory.updatePageRequest("", "1", "title", "content", 2, "test message"); }
@Test public void updatePageRequest_withEmptyTitle_throwsIllegalArgumentException() { this.expectedException.expect(IllegalArgumentException.class); this.expectedException.expectMessage("title must be set"); this.httpRequestFactory.updatePageRequest("1234", "1", "", "content", 2, "test message"); }