List of usage examples for org.springframework.restdocs.headers HeaderDocumentation responseHeaders
public static ResponseHeadersSnippet responseHeaders(List<HeaderDescriptor> descriptors)
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java
private void checkJobOutput(final int documentationId, final String id) throws Exception { // Check getting a directory as json final RestDocumentationFilter jsonResultFilter = RestAssuredRestDocumentation.document( "{class-name}/" + documentationId + "/getJobOutput/json/", Snippets.ID_PATH_PARAM.and(RequestDocumentation.parameterWithName("filePath") .description("The path to the directory to get").optional()), // Path parameters HeaderDocumentation.requestHeaders(HeaderDocumentation.headerWithName(HttpHeaders.ACCEPT) .description(MediaType.APPLICATION_JSON_VALUE).optional()), // Request header HeaderDocumentation.responseHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description(MediaType.APPLICATION_JSON_VALUE)), // Response Headers Snippets.OUTPUT_DIRECTORY_FIELDS); RestAssured.given(this.getRequestSpecification()).filter(jsonResultFilter) .accept(MediaType.APPLICATION_JSON_VALUE).when().port(this.port) .get(JOBS_API + "/{id}/output/{filePath}", id, "").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.equalToIgnoringCase(MediaType.APPLICATION_JSON_UTF8_VALUE)) .body("parent", Matchers.isEmptyOrNullString()).body("directories[0].name", Matchers.is("genie/")) .body("files[0].name", Matchers.is("config1")).body("files[1].name", Matchers.is("dep1")) .body("files[2].name", Matchers.is("jobsetupfile")).body("files[3].name", Matchers.is("run")) .body("files[4].name", Matchers.is("stderr")).body("files[5].name", Matchers.is("stdout")); // Check getting a directory as HTML final RestDocumentationFilter htmlResultFilter = RestAssuredRestDocumentation.document( "{class-name}/" + documentationId + "/getJobOutput/html/", Snippets.ID_PATH_PARAM.and(RequestDocumentation.parameterWithName("filePath") .description("The path to the directory to get").optional()), // Path parameters HeaderDocumentation.requestHeaders( HeaderDocumentation.headerWithName(HttpHeaders.ACCEPT).description(MediaType.TEXT_HTML)), // Request header HeaderDocumentation.responseHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description(MediaType.TEXT_HTML)) // Response Headers );/* ww w . j a v a 2 s . com*/ RestAssured.given(this.getRequestSpecification()).filter(htmlResultFilter).accept(MediaType.TEXT_HTML_VALUE) .when().port(this.port).get(JOBS_API + "/{id}/output/{filePath}", id, "").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_HTML_VALUE)); // Check getting a file final RestDocumentationFilter fileResultFilter = RestAssuredRestDocumentation.document( "{class-name}/" + documentationId + "/getJobOutput/file/", Snippets.ID_PATH_PARAM.and(RequestDocumentation.parameterWithName("filePath") .description("The path to the file to get").optional()), // Path parameters HeaderDocumentation.requestHeaders(HeaderDocumentation.headerWithName(HttpHeaders.ACCEPT) .description(MediaType.ALL_VALUE).optional()), // Request header HeaderDocumentation.responseHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description("The content type of the file being returned").optional()) // Response Headers ); // check that the generated run file is correct final String runShFileName = SystemUtils.IS_OS_LINUX ? "linux-runsh.txt" : "non-linux-runsh.txt"; final String runShFile = this.resourceLoader.getResource(BASE_DIR + runShFileName).getFile() .getAbsolutePath(); final String runFileContents = new String(Files.readAllBytes(Paths.get(runShFile)), StandardCharsets.UTF_8); final String jobWorkingDir = this.jobDirResource.getFile().getCanonicalPath() + FILE_DELIMITER + id; final String expectedRunScriptContent = this.getExpectedRunContents(runFileContents, jobWorkingDir, id); RestAssured.given(this.getRequestSpecification()).filter(fileResultFilter).when().port(this.port) .get(JOBS_API + "/{id}/output/{filePath}", id, "run").then() .statusCode(Matchers.is(HttpStatus.OK.value())).body(Matchers.is(expectedRunScriptContent)); }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTests.java
private void checkJobOutput(final int documentationId, final String id) throws Exception { // Check getting a directory as json final RestDocumentationResultHandler jsonResultHandler = MockMvcRestDocumentation.document( "{class-name}/" + documentationId + "/getJobOutput/json/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM.and(RequestDocumentation.parameterWithName("filePath") .description("The path to the directory to get").optional()), // Path parameters HeaderDocumentation.requestHeaders(HeaderDocumentation.headerWithName(HttpHeaders.ACCEPT) .description(MediaType.APPLICATION_JSON_VALUE).optional()), // Request header HeaderDocumentation.responseHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description(MediaType.APPLICATION_JSON_VALUE)), // Response Headers Snippets.OUTPUT_DIRECTORY_FIELDS); this.mvc.perform(RestDocumentationRequestBuilders.get(JOBS_API + "/{id}/output/{filePath}", id, "")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("parent", Matchers.isEmptyOrNullString())) .andExpect(MockMvcResultMatchers.jsonPath("$.directories[0].name", Matchers.is("genie/"))) .andExpect(MockMvcResultMatchers.jsonPath("$.files[0].name", Matchers.is("dep1"))) .andExpect(MockMvcResultMatchers.jsonPath("$.files[1].name", Matchers.is("jobsetupfile"))) .andExpect(MockMvcResultMatchers.jsonPath("$.files[2].name", Matchers.is("run"))) .andExpect(MockMvcResultMatchers.jsonPath("$.files[3].name", Matchers.is("stderr"))) .andExpect(MockMvcResultMatchers.jsonPath("$.files[4].name", Matchers.is("stdout"))) .andDo(jsonResultHandler);/* ww w. jav a2 s. c om*/ // Check getting a directory as HTML final RestDocumentationResultHandler htmlResultHandler = MockMvcRestDocumentation.document( "{class-name}/" + documentationId + "/getJobOutput/html/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM.and(RequestDocumentation.parameterWithName("filePath") .description("The path to the directory to get").optional()), // Path parameters HeaderDocumentation.requestHeaders( HeaderDocumentation.headerWithName(HttpHeaders.ACCEPT).description(MediaType.TEXT_HTML)), // Request header HeaderDocumentation.responseHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description(MediaType.TEXT_HTML)) // Response Headers ); this.mvc.perform(RestDocumentationRequestBuilders.get(JOBS_API + "/{id}/output/{filePath}", id, "") .accept(MediaType.TEXT_HTML)).andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaType.TEXT_HTML)) .andDo(htmlResultHandler); // Check getting a file // Check getting a directory as HTML final RestDocumentationResultHandler fileResultHandler = MockMvcRestDocumentation.document( "{class-name}/" + documentationId + "/getJobOutput/file/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM.and(RequestDocumentation.parameterWithName("filePath") .description("The path to the file to get").optional()), // Path parameters HeaderDocumentation.requestHeaders(HeaderDocumentation.headerWithName(HttpHeaders.ACCEPT) .description(MediaType.ALL_VALUE).optional()), // Request header HeaderDocumentation.responseHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description("The content type of the file being returned").optional()) // Response Headers ); // check that the generated run file is correct final String runShFileName = SystemUtils.IS_OS_LINUX ? "linux-runsh.txt" : "non-linux-runsh.txt"; final String runShFile = this.resourceLoader.getResource(BASE_DIR + runShFileName).getFile() .getAbsolutePath(); final String runFileContents = new String(Files.readAllBytes(Paths.get(runShFile)), "UTF-8"); final String jobWorkingDir = this.jobDirResource.getFile().getCanonicalPath() + FILE_DELIMITER + id; final String expectedRunScriptContent = this.getExpectedRunContents(runFileContents, jobWorkingDir, id); this.mvc.perform(RestDocumentationRequestBuilders.get(JOBS_API + "/{id}/output/{filePath}", id, "run")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string(expectedRunScriptContent)) .andDo(fileResultHandler); }