in genie-web/src/integTest/java/com/netflix/genie/web/apis/rest/v3/controllers/JobRestControllerIntegrationTest.java [485:646]
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
);
final ValidatableResponse outputDirJsonResponse = 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.startsWith(MediaType.APPLICATION_JSON_VALUE));
outputDirJsonResponse
.body("parent", Matchers.blankOrNullString())
.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("genie_setup.sh"))
.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
);
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
);
final String setupFile = this.getResourceURI(BASE_DIR + "job" + FILE_DELIMITER + "jobsetupfile");
final String setupFileContents = Files.readString(Paths.get(new URI(setupFile)));
RestAssured
.given(this.getRequestSpecification())
.filter(fileResultFilter)
.when()
.port(this.port)
.get(
JOBS_API + "/{id}/output/{filePath}",
id,
"genie_setup.sh"
)
.then()
.statusCode(Matchers.is(HttpStatus.OK.value()))
.body(Matchers.is(setupFileContents));
// Validate content of 'run' file
final String expectedFilename = "runsh-agent.txt";
final String runFile = this.getResourceURI(BASE_DIR + expectedFilename);
final String runFileContent = Files.readString(Paths.get(new URI(runFile)));
final String testJobsDir = this.jobsLocationsProperties.getJobs().getPath();
final String expectedRunFileContent = this.getExpectedRunContents(
runFileContent,
testJobsDir + id,
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.equalTo(expectedRunFileContent));
// Check stderr content and size
RestAssured
.given(this.getRequestSpecification())
.when()
.port(this.port)
.get(JOBS_API + "/{id}/output/{filePath}", id, "stderr")
.then()
.header(HttpHeaders.CONTENT_LENGTH, String.valueOf(0))
.body(Matchers.emptyString());
// Check stdout content and size
RestAssured
.given(this.getRequestSpecification())
.when()
.port(this.port)
.get(JOBS_API + "/{id}/output/{filePath}", id, "stdout")
.then()
.statusCode(Matchers.is(HttpStatus.OK.value()))
.header(HttpHeaders.CONTENT_LENGTH, Integer.toString(EXPECTED_STDOUT_LENGTH))
.body(Matchers.equalTo(EXPECTED_STDOUT_CONTENT));
checkGetFileRanges(id);
}