List of usage examples for org.springframework.restdocs.mockmvc RestDocumentationRequestBuilders delete
public static MockHttpServletRequestBuilder delete(String urlTemplate, Object... urlVariables)
From source file:com.netflix.genie.web.controllers.ClusterRestControllerIntegrationTests.java
/** * Test to make sure that you can delete a cluster. * * @throws Exception on configuration error *//*from w w w. j a va2 s . c o m*/ @Test public void canDeleteACluster() throws Exception { Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(0L)); final String id1 = UUID.randomUUID().toString(); final String id2 = UUID.randomUUID().toString(); final String id3 = UUID.randomUUID().toString(); final String name1 = UUID.randomUUID().toString(); final String name2 = UUID.randomUUID().toString(); final String name3 = UUID.randomUUID().toString(); final String user1 = UUID.randomUUID().toString(); final String user2 = UUID.randomUUID().toString(); final String user3 = UUID.randomUUID().toString(); final String version1 = UUID.randomUUID().toString(); final String version2 = UUID.randomUUID().toString(); final String version3 = UUID.randomUUID().toString(); this.createConfigResource(new Cluster.Builder(name1, user1, version1, ClusterStatus.UP).withId(id1).build(), null); this.createConfigResource( new Cluster.Builder(name2, user2, version2, ClusterStatus.OUT_OF_SERVICE).withId(id2).build(), null); this.createConfigResource( new Cluster.Builder(name3, user3, version3, ClusterStatus.TERMINATED).withId(id3).build(), null); Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(3L)); final RestDocumentationResultHandler deleteResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM // path parameters ); this.mvc.perform(RestDocumentationRequestBuilders.delete(CLUSTERS_API + "/{id}", id2)) .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(deleteResultHandler); this.mvc.perform(MockMvcRequestBuilders.get(CLUSTERS_API + "/{id}", id2)) .andExpect(MockMvcResultMatchers.status().isNotFound()); Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(2L)); }
From source file:com.netflix.genie.web.controllers.CommandRestControllerIntegrationTests.java
/** * Test to make sure that you can delete a command. * * @throws Exception on configuration error *//* w ww. j av a 2s.c om*/ @Test public void canDeleteACommand() throws Exception { Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(0L)); final String id1 = UUID.randomUUID().toString(); final String id2 = UUID.randomUUID().toString(); final String id3 = UUID.randomUUID().toString(); final String name1 = UUID.randomUUID().toString(); final String name2 = UUID.randomUUID().toString(); final String name3 = UUID.randomUUID().toString(); final String user1 = UUID.randomUUID().toString(); final String user2 = UUID.randomUUID().toString(); final String user3 = UUID.randomUUID().toString(); final String version1 = UUID.randomUUID().toString(); final String version2 = UUID.randomUUID().toString(); final String version3 = UUID.randomUUID().toString(); final String executable1 = UUID.randomUUID().toString(); final String executable2 = UUID.randomUUID().toString(); final String executable3 = UUID.randomUUID().toString(); this.createConfigResource( new Command.Builder(name1, user1, version1, CommandStatus.ACTIVE, executable1, CHECK_DELAY) .withId(id1).build(), null); this.createConfigResource( new Command.Builder(name2, user2, version2, CommandStatus.ACTIVE, executable2, CHECK_DELAY) .withId(id2).build(), null); this.createConfigResource( new Command.Builder(name3, user3, version3, CommandStatus.ACTIVE, executable3, CHECK_DELAY) .withId(id3).build(), null); Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(3L)); final RestDocumentationResultHandler deleteResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM // path parameters ); this.mvc.perform(RestDocumentationRequestBuilders.delete(COMMANDS_API + "/{id}", id2)) .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(deleteResultHandler); this.mvc.perform(MockMvcRequestBuilders.get(COMMANDS_API + "/{id}", id2)) .andExpect(MockMvcResultMatchers.status().isNotFound()); Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(2L)); }
From source file:com.netflix.genie.web.controllers.ApplicationRestControllerIntegrationTests.java
/** * Test to make sure that you can delete an application. * * @throws Exception on configuration error *//*from w ww . java2 s.c o m*/ @Test public void canDeleteAnApplication() throws Exception { Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L)); final String id1 = UUID.randomUUID().toString(); final String id2 = UUID.randomUUID().toString(); final String id3 = UUID.randomUUID().toString(); final String name1 = UUID.randomUUID().toString(); final String name2 = UUID.randomUUID().toString(); final String name3 = UUID.randomUUID().toString(); final String user1 = UUID.randomUUID().toString(); final String user2 = UUID.randomUUID().toString(); final String user3 = UUID.randomUUID().toString(); final String version1 = UUID.randomUUID().toString(); final String version2 = UUID.randomUUID().toString(); final String version3 = UUID.randomUUID().toString(); this.createConfigResource( new Application.Builder(name1, user1, version1, ApplicationStatus.ACTIVE).withId(id1).build(), null); this.createConfigResource( new Application.Builder(name2, user2, version2, ApplicationStatus.DEPRECATED).withId(id2).build(), null); this.createConfigResource( new Application.Builder(name3, user3, version3, ApplicationStatus.INACTIVE).withId(id3).build(), null); Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(3L)); final RestDocumentationResultHandler deleteResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM // path parameters ); this.mvc.perform(RestDocumentationRequestBuilders.delete(APPLICATIONS_API + "/{id}", id2)) .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(deleteResultHandler); this.mvc.perform(MockMvcRequestBuilders.get(APPLICATIONS_API + "/{id}", id2)) .andExpect(MockMvcResultMatchers.status().isNotFound()); Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(2L)); }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTests.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 . j a va2s.c o m*/ @Test public void testSubmitJobMethodKill() throws Exception { Assume.assumeTrue(SystemUtils.IS_OS_UNIX); final String commandArgs = "-c 'sleep 60'"; final List<ClusterCriteria> clusterCriteriaList = new ArrayList<>(); final Set<String> clusterTags = new HashSet<>(); clusterTags.add("localhost"); final ClusterCriteria clusterCriteria = new ClusterCriteria(clusterTags); clusterCriteriaList.add(clusterCriteria); final Set<String> commandCriteria = new HashSet<>(); commandCriteria.add("bash"); final JobRequest jobRequest = new JobRequest.Builder(JOB_NAME, JOB_USER, JOB_VERSION, commandArgs, clusterCriteriaList, commandCriteria).withDisableLogArchival(true).build(); final MvcResult result = this.mvc .perform(MockMvcRequestBuilders.post(JOBS_API).contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsBytes(jobRequest))) .andExpect(MockMvcResultMatchers.status().isAccepted()) .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue())) .andReturn(); final String jobId = this.getIdFromLocation(result.getResponse().getHeader(HttpHeaders.LOCATION)); this.waitForRunning(jobId); // Let it run for a couple of seconds Thread.sleep(2000); // Send a kill request to the job. final RestDocumentationResultHandler killResultHandler = MockMvcRestDocumentation.document( "{class-name}/killJob/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM); this.mvc.perform(RestDocumentationRequestBuilders.delete(JOBS_API + "/{id}", jobId)) .andExpect(MockMvcResultMatchers.status().isAccepted()).andDo(killResultHandler); this.waitForDone(jobId); this.mvc.perform(MockMvcRequestBuilders.get(JOBS_API + "/" + jobId)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath(ID_PATH, Matchers.is(jobId))) .andExpect(MockMvcResultMatchers.jsonPath(STATUS_PATH, Matchers.is(JobStatus.KILLED.toString()))); // Kill the job again to make sure it doesn't cause a problem. this.mvc.perform(MockMvcRequestBuilders.delete(JOBS_API + "/" + jobId)) .andExpect(MockMvcResultMatchers.status().isAccepted()); }
From source file:com.netflix.genie.web.controllers.ClusterRestControllerIntegrationTests.java
/** * Make sure that we can remove all the commands from a cluster. * * @throws Exception on configuration error *///from www. j av a2 s . c o m @Test public void canRemoveCommandsFromACluster() throws Exception { this.createConfigResource(new Cluster.Builder(NAME, USER, VERSION, ClusterStatus.UP).withId(ID).build(), null); final String clusterCommandsAPI = CLUSTERS_API + "/{id}/commands"; final String placeholder = UUID.randomUUID().toString(); final String commandId1 = UUID.randomUUID().toString(); final String commandId2 = UUID.randomUUID().toString(); this.createConfigResource( new Command.Builder(placeholder, placeholder, placeholder, CommandStatus.ACTIVE, placeholder, 7000L) .withId(commandId1).build(), null); this.createConfigResource( new Command.Builder(placeholder, placeholder, placeholder, CommandStatus.ACTIVE, placeholder, 8000L) .withId(commandId2).build(), null); this.mvc.perform(MockMvcRequestBuilders.post(clusterCommandsAPI, ID).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsBytes(Lists.newArrayList(commandId1, commandId2)))) .andExpect(MockMvcResultMatchers.status().isNoContent()); final RestDocumentationResultHandler deleteResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM // Path parameters ); this.mvc.perform(RestDocumentationRequestBuilders.delete(clusterCommandsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(deleteResultHandler); this.mvc.perform(MockMvcRequestBuilders.get(clusterCommandsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.empty())); }
From source file:com.netflix.genie.web.controllers.CommandRestControllerIntegrationTests.java
/** * Make sure that we can remove all the applications from a command. * * @throws Exception on configuration error *//*from ww w. ja va 2s .c om*/ @Test public void canRemoveApplicationsFromACommand() throws Exception { this.createConfigResource( new Command.Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE, CHECK_DELAY).withId(ID) .build(), null); final String commandApplicationsAPI = COMMANDS_API + "/{id}/applications"; final String placeholder = UUID.randomUUID().toString(); final String applicationId1 = UUID.randomUUID().toString(); final String applicationId2 = UUID.randomUUID().toString(); this.createConfigResource( new Application.Builder(placeholder, placeholder, placeholder, ApplicationStatus.ACTIVE) .withId(applicationId1).build(), null); this.createConfigResource( new Application.Builder(placeholder, placeholder, placeholder, ApplicationStatus.ACTIVE) .withId(applicationId2).build(), null); this.mvc.perform(MockMvcRequestBuilders.post(commandApplicationsAPI, ID) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsBytes(Lists.newArrayList(applicationId1, applicationId2)))) .andExpect(MockMvcResultMatchers.status().isNoContent()); final RestDocumentationResultHandler deleteResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM // Path parameters ); this.mvc.perform(RestDocumentationRequestBuilders.delete(commandApplicationsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(deleteResultHandler); this.mvc.perform(MockMvcRequestBuilders.get(commandApplicationsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.empty())); }