List of usage examples for org.springframework.restdocs.restassured3 RestAssuredRestDocumentation document
public static RestDocumentationFilter document(String identifier, Snippet... snippets)
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java
/** * Test the job submit method for when the job is killed by sending a DELETE HTTP call. * * @throws Exception If there is a problem. *//* w w w .ja v a 2s.c om*/ @Test public void testSubmitJobMethodKill() throws Exception { Assume.assumeTrue(SystemUtils.IS_OS_UNIX); final List<String> commandArgs = Lists.newArrayList("-c", "'sleep 60'"); final List<ClusterCriteria> clusterCriteriaList = new ArrayList<>(); final Set<String> clusterTags = Sets.newHashSet(LOCALHOST_CLUSTER_TAG); final ClusterCriteria clusterCriteria = new ClusterCriteria(clusterTags); clusterCriteriaList.add(clusterCriteria); final Set<String> commandCriteria = Sets.newHashSet(BASH_COMMAND_TAG); final JobRequest jobRequest = new JobRequest.Builder(JOB_NAME, JOB_USER, JOB_VERSION, clusterCriteriaList, commandCriteria).withCommandArgs(commandArgs).withDisableLogArchival(true).build(); final String jobId = this.getIdFromLocation(RestAssured.given(this.getRequestSpecification()) .contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)).when().port(this.port) .post(JOBS_API).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())) .header(HttpHeaders.LOCATION, Matchers.notNullValue()).extract().header(HttpHeaders.LOCATION)); this.waitForRunning(jobId); // Make sure we can get output for a running job RestAssured.given(this.getRequestSpecification()).accept(MediaType.APPLICATION_JSON_VALUE).when() .port(this.port).get(JOBS_API + "/{id}/output/{filePath}", jobId, "").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("run")).body("files[1].name", Matchers.is("stderr")) .body("files[2].name", Matchers.is("stdout")); RestAssured.given(this.getRequestSpecification()).when().port(this.port) .get(JOBS_API + "/{id}/output/{filePath}", jobId, "stdout").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(ContentType.TEXT.toString())); // Let it run for a couple of seconds Thread.sleep(2000); // Send a kill request to the job. final RestDocumentationFilter killResultFilter = RestAssuredRestDocumentation .document("{class-name}/killJob/", Snippets.ID_PATH_PARAM); RestAssured.given(this.getRequestSpecification()).filter(killResultFilter).when().port(this.port) .delete(JOBS_API + "/{id}", jobId).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())); this.waitForDone(jobId); RestAssured.given(this.getRequestSpecification()).when().port(this.port).get(JOBS_API + "/{id}", jobId) .then().statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.is(MediaTypes.HAL_JSON_UTF8_VALUE)).body(ID_PATH, Matchers.is(jobId)) .body(STATUS_PATH, Matchers.is(JobStatus.KILLED.toString())) .body(STATUS_MESSAGE_PATH, Matchers.is(JobStatusMessages.JOB_KILLED_BY_USER)); // Kill the job again to make sure it doesn't cause a problem. RestAssured.given(this.getRequestSpecification()).filter(killResultFilter).when().port(this.port) .delete(JOBS_API + "/{id}", jobId).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())); }