List of usage examples for org.springframework.hateoas MediaTypes HAL_JSON
MediaType HAL_JSON
To view the source code for org.springframework.hateoas MediaTypes HAL_JSON.
Click Source Link
From source file:com.netflix.genie.web.controllers.ClusterRestControllerIntegrationTests.java
/** * Make sure can add the commands for a cluster. * * @throws Exception on configuration error */// w w w .ja v a 2s. c o m @Test public void canAddCommandsForACluster() throws Exception { this.createConfigResource(new Cluster.Builder(NAME, USER, VERSION, ClusterStatus.UP).withId(ID).build(), null); final String clusterCommandsAPI = CLUSTERS_API + "/{id}/commands"; this.mvc.perform(MockMvcRequestBuilders.get(clusterCommandsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.empty())); 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, 1000L) .withId(commandId1).build(), null); this.createConfigResource( new Command.Builder(placeholder, placeholder, placeholder, CommandStatus.ACTIVE, placeholder, 2000L) .withId(commandId2).build(), null); final RestDocumentationResultHandler addResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request Headers Snippets.ID_PATH_PARAM, // Path parameters PayloadDocumentation.requestFields(PayloadDocumentation.fieldWithPath("[]").description( "Array of command ids (in preferred order) to append to the existing list of commands") .attributes(Snippets.EMPTY_CONSTRAINTS)) // Request payload ); this.mvc.perform(RestDocumentationRequestBuilders.post(clusterCommandsAPI, ID) .contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList(commandId1, commandId2)))) .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(addResultHandler); this.mvc.perform(MockMvcRequestBuilders.get(clusterCommandsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(commandId1))) .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(commandId2))); //Shouldn't add anything this.mvc.perform(MockMvcRequestBuilders.post(clusterCommandsAPI, ID).contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList()))) .andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); final String commandId3 = UUID.randomUUID().toString(); this.createConfigResource(new Command.Builder(placeholder, placeholder, placeholder, CommandStatus.INACTIVE, placeholder, 1000L).withId(commandId3).build(), null); this.mvc.perform(MockMvcRequestBuilders.post(clusterCommandsAPI, ID).contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList(commandId3)))) .andExpect(MockMvcResultMatchers.status().isNoContent()); this.mvc.perform(MockMvcRequestBuilders.get(clusterCommandsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(3))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(commandId1))) .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(commandId2))) .andExpect(MockMvcResultMatchers.jsonPath("$[2].id", Matchers.is(commandId3))); // Test the filtering final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // Path parameters RequestDocumentation.requestParameters(RequestDocumentation.parameterWithName("status") .description("The status of commands to search for") .attributes(Attributes.key(Snippets.CONSTRAINTS).value(CommandStatus.values())).optional()), // Query Parameters Snippets.HAL_CONTENT_TYPE_HEADER, // Response Headers PayloadDocumentation.responseFields(PayloadDocumentation.fieldWithPath("[]") .description("The list of commands found").attributes(Snippets.EMPTY_CONSTRAINTS))); this.mvc.perform(RestDocumentationRequestBuilders.get(clusterCommandsAPI, ID).param("status", CommandStatus.INACTIVE.toString())).andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(commandId3))) .andDo(getResultHandler); }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTests.java
private void checkFindJobs(final int documentationId, final String id, final String user) throws Exception { final RestDocumentationResultHandler findResultHandler = MockMvcRestDocumentation.document( "{class-name}/" + documentationId + "/findJobs/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.JOB_SEARCH_QUERY_PARAMETERS, // Request query parameters Snippets.HAL_CONTENT_TYPE_HEADER, // Response headers Snippets.JOB_SEARCH_RESULT_FIELDS, // Result fields Snippets.SEARCH_LINKS // HAL Links );//w w w . j a v a2s. c om this.mvc.perform(MockMvcRequestBuilders.get(JOBS_API).param("user", user)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath(JOBS_LIST_PATH, Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath(JOBS_LIST_PATH + "[0].id", Matchers.is(id))) .andDo(findResultHandler); }
From source file:com.netflix.genie.web.controllers.CommandRestControllerIntegrationTests.java
/** * Make sure can add the applications for a command. * * @throws Exception on configuration error */// w ww. j a va2 s . c om @Test public void canAddApplicationsForACommand() 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"; this.mvc.perform(MockMvcRequestBuilders.get(commandApplicationsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.empty())); 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); final RestDocumentationResultHandler addResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request Headers Snippets.ID_PATH_PARAM, // Path parameters PayloadDocumentation.requestFields(PayloadDocumentation.fieldWithPath("[]") .description("Array of application ids to add to existing set of applications") .attributes(Snippets.EMPTY_CONSTRAINTS)) // Request payload ); this.mvc.perform(RestDocumentationRequestBuilders.post(commandApplicationsAPI, ID) .contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList(applicationId1, applicationId2)))) .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(addResultHandler); this.mvc.perform(MockMvcRequestBuilders.get(commandApplicationsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(applicationId1))) .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(applicationId2))); //Shouldn't add anything this.mvc.perform( MockMvcRequestBuilders.post(commandApplicationsAPI, ID).contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList()))) .andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); final String applicationId3 = UUID.randomUUID().toString(); this.createConfigResource( new Application.Builder(placeholder, placeholder, placeholder, ApplicationStatus.ACTIVE) .withId(applicationId3).build(), null); this.mvc.perform( MockMvcRequestBuilders.post(commandApplicationsAPI, ID).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsBytes(Lists.newArrayList(applicationId3)))) .andExpect(MockMvcResultMatchers.status().isNoContent()); final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // Path parameters Snippets.HAL_CONTENT_TYPE_HEADER, // Response Headers PayloadDocumentation.responseFields(PayloadDocumentation.fieldWithPath("[]") .description("The set of applications this command depends on") .attributes(Snippets.EMPTY_CONSTRAINTS))); this.mvc.perform(RestDocumentationRequestBuilders.get(commandApplicationsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(3))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(applicationId1))) .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(applicationId2))) .andExpect(MockMvcResultMatchers.jsonPath("$[2].id", Matchers.is(applicationId3))) .andDo(getResultHandler); }
From source file:com.netflix.genie.web.controllers.ClusterRestControllerIntegrationTests.java
/** * Make sure can set the commands for a cluster. * * @throws Exception on configuration error *///from ww w . j a v a 2 s .co m @Test public void canSetCommandsForACluster() throws Exception { this.createConfigResource(new Cluster.Builder(NAME, USER, VERSION, ClusterStatus.UP).withId(ID).build(), null); final String clusterCommandsAPI = CLUSTERS_API + "/{id}/commands"; this.mvc.perform(MockMvcRequestBuilders.get(clusterCommandsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.empty())); 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, 4000L) .withId(commandId1).build(), null); this.createConfigResource( new Command.Builder(placeholder, placeholder, placeholder, CommandStatus.ACTIVE, placeholder, 5000L) .withId(commandId2).build(), null); final RestDocumentationResultHandler setResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request Headers Snippets.ID_PATH_PARAM, // Path parameters PayloadDocumentation.requestFields(PayloadDocumentation.fieldWithPath("[]").description( "Array of command ids (in preferred order) to replace the existing list of commands") .attributes(Snippets.EMPTY_CONSTRAINTS)) // Request payload ); this.mvc.perform( RestDocumentationRequestBuilders.put(clusterCommandsAPI, ID).contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList(commandId1, commandId2)))) .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(setResultHandler); this.mvc.perform(MockMvcRequestBuilders.get(clusterCommandsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(commandId1))) .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(commandId2))); //Should clear commands this.mvc.perform(MockMvcRequestBuilders.put(clusterCommandsAPI, ID).contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList()))) .andExpect(MockMvcResultMatchers.status().isNoContent()); 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.ApplicationRestControllerIntegrationTests.java
/** * Make sure can get all the commands which use a given application. * * @throws Exception on configuration error *//* ww w .ja v a 2 s.c o m*/ @Test public void canGetCommandsForApplication() throws Exception { this.createConfigResource( new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(), null); final String placeholder = UUID.randomUUID().toString(); final String command1Id = UUID.randomUUID().toString(); final String command2Id = UUID.randomUUID().toString(); final String command3Id = UUID.randomUUID().toString(); this.createConfigResource( new Command.Builder(placeholder, placeholder, placeholder, CommandStatus.ACTIVE, placeholder, 1000L) .withId(command1Id).build(), null); this.createConfigResource(new Command.Builder(placeholder, placeholder, placeholder, CommandStatus.INACTIVE, placeholder, 1100L).withId(command2Id).build(), null); this.createConfigResource(new Command.Builder(placeholder, placeholder, placeholder, CommandStatus.DEPRECATED, placeholder, 1200L).withId(command3Id).build(), null); final Set<String> appIds = Sets.newHashSet(ID); this.mvc.perform(MockMvcRequestBuilders.post(COMMANDS_API + "/" + command1Id + "/applications") .contentType(MediaType.APPLICATION_JSON).content(this.objectMapper.writeValueAsBytes(appIds))) .andExpect(MockMvcResultMatchers.status().isNoContent()); this.mvc.perform(MockMvcRequestBuilders.post(COMMANDS_API + "/" + command3Id + "/applications") .contentType(MediaType.APPLICATION_JSON).content(this.objectMapper.writeValueAsBytes(appIds))) .andExpect(MockMvcResultMatchers.status().isNoContent()); final String applicationCommandsAPI = APPLICATIONS_API + "/{id}/commands"; Arrays.asList( this.objectMapper.readValue(this.mvc.perform(MockMvcRequestBuilders.get(applicationCommandsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))).andReturn() .getResponse().getContentAsByteArray(), Command[].class)) .forEach(command -> { if (!command.getId().orElseThrow(IllegalArgumentException::new).equals(command1Id) && !command.getId().orElseThrow(IllegalArgumentException::new).equals(command3Id)) { Assert.fail(); } }); // Filter by status final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // Path parameters RequestDocumentation.requestParameters(RequestDocumentation.parameterWithName("status") .description("The status of commands to search for") .attributes(Attributes.key(Snippets.CONSTRAINTS).value(CommandStatus.values())).optional()), // Query Parameters Snippets.HAL_CONTENT_TYPE_HEADER, // Response Headers PayloadDocumentation.responseFields(PayloadDocumentation.fieldWithPath("[]") .description("The list of commands found").attributes(Snippets.EMPTY_CONSTRAINTS))); this.mvc.perform(RestDocumentationRequestBuilders.get(applicationCommandsAPI, ID).param("status", CommandStatus.ACTIVE.toString(), CommandStatus.INACTIVE.toString())) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(command1Id))) .andDo(getResultHandler); }
From source file:com.netflix.genie.web.controllers.CommandRestControllerIntegrationTests.java
/** * Make sure can set the applications for a command. * * @throws Exception on configuration error */// w ww . j a v a2 s . c o m @Test public void canSetApplicationsForACommand() 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"; this.mvc.perform(MockMvcRequestBuilders.get(commandApplicationsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.empty())); final String placeholder = UUID.randomUUID().toString(); final String applicationId1 = UUID.randomUUID().toString(); final String applicationId2 = UUID.randomUUID().toString(); final String applicationId3 = 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.createConfigResource( new Application.Builder(placeholder, placeholder, placeholder, ApplicationStatus.ACTIVE) .withId(applicationId3).build(), null); final RestDocumentationResultHandler setResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request Headers Snippets.ID_PATH_PARAM, // Path parameters PayloadDocumentation.requestFields(PayloadDocumentation.fieldWithPath("[]") .description("Array of application ids to replace the existing set of applications with") .attributes(Snippets.EMPTY_CONSTRAINTS)) // Request payload ); this.mvc.perform(RestDocumentationRequestBuilders.put(commandApplicationsAPI, ID) .contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList(applicationId1, applicationId2)))) .andExpect(MockMvcResultMatchers.status().isNoContent()).andDo(setResultHandler); this.mvc.perform(MockMvcRequestBuilders.get(commandApplicationsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(applicationId1))) .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(applicationId2))); // Should flip the order this.mvc.perform( MockMvcRequestBuilders.put(commandApplicationsAPI, ID).contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper .writeValueAsBytes(Lists.newArrayList(applicationId2, applicationId1)))) .andExpect(MockMvcResultMatchers.status().isNoContent()); this.mvc.perform(MockMvcRequestBuilders.get(commandApplicationsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(applicationId2))) .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(applicationId1))); // Should reorder and add a new one this.mvc.perform( MockMvcRequestBuilders.put(commandApplicationsAPI, ID).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsBytes( Lists.newArrayList(applicationId1, applicationId2, applicationId3)))) .andExpect(MockMvcResultMatchers.status().isNoContent()); this.mvc.perform(MockMvcRequestBuilders.get(commandApplicationsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(3))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(applicationId1))) .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(applicationId2))) .andExpect(MockMvcResultMatchers.jsonPath("$[2].id", Matchers.is(applicationId3))); //Should clear applications this.mvc.perform( MockMvcRequestBuilders.put(commandApplicationsAPI, ID).contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsBytes(Lists.newArrayList()))) .andExpect(MockMvcResultMatchers.status().isNoContent()); this.mvc.perform(MockMvcRequestBuilders.get(commandApplicationsAPI, 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.ClusterRestControllerIntegrationTests.java
/** * Make sure that we can remove all the commands from a cluster. * * @throws Exception on configuration error *///from w ww . j a v a2 s . co 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.ClusterRestControllerIntegrationTests.java
/** * Make sure that we can remove a command from a cluster. * * @throws Exception on configuration error *///from w ww . j a va 2s . com @Test public void canRemoveCommandFromACluster() 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(); final String commandId3 = UUID.randomUUID().toString(); this.createConfigResource( new Command.Builder(placeholder, placeholder, placeholder, CommandStatus.ACTIVE, placeholder, 1000L) .withId(commandId1).build(), null); this.createConfigResource( new Command.Builder(placeholder, placeholder, placeholder, CommandStatus.ACTIVE, placeholder, 2000L) .withId(commandId2).build(), null); this.createConfigResource( new Command.Builder(placeholder, placeholder, placeholder, CommandStatus.ACTIVE, placeholder, 3000L) .withId(commandId3).build(), null); this.mvc.perform(MockMvcRequestBuilders.post(clusterCommandsAPI, ID).contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper .writeValueAsBytes(Lists.newArrayList(commandId1, commandId2, commandId3)))) .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.and(RequestDocumentation.parameterWithName("commandId") .description("The id of the command to remove")) // Path parameters ); this.mvc.perform( RestDocumentationRequestBuilders.delete(clusterCommandsAPI + "/{commandId}", ID, commandId2)) .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.hasSize(2))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(commandId1))) .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(commandId3))); // Check reverse side of relationship this.mvc.perform(MockMvcRequestBuilders.get(COMMANDS_API + "/{id}/clusters", commandId1)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(ID))); this.mvc.perform(MockMvcRequestBuilders.get(COMMANDS_API + "/{id}/clusters", commandId2)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.empty())); this.mvc.perform(MockMvcRequestBuilders.get(COMMANDS_API + "/{id}/clusters", commandId3)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(ID))); }
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 *//*www . j ava 2 s.c o m*/ @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())); }
From source file:com.netflix.genie.web.controllers.CommandRestControllerIntegrationTests.java
/** * Make sure that we can remove an application from a command. * * @throws Exception on configuration error */// w w w . ja v a 2 s.c om @Test public void canRemoveApplicationFromACommand() 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(); final String applicationId3 = 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.createConfigResource( new Application.Builder(placeholder, placeholder, placeholder, ApplicationStatus.ACTIVE) .withId(applicationId3).build(), null); this.mvc.perform( MockMvcRequestBuilders.post(commandApplicationsAPI, ID).contentType(MediaType.APPLICATION_JSON) .content(this.objectMapper.writeValueAsBytes( Lists.newArrayList(applicationId1, applicationId2, applicationId3)))) .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.and(RequestDocumentation.parameterWithName("applicationId") .description("The id of the application to remove")) // Path parameters ); this.mvc.perform(RestDocumentationRequestBuilders.delete(commandApplicationsAPI + "/{applicationId}", ID, applicationId2)).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.hasSize(2))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(applicationId1))) .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(applicationId3))); // Check reverse side of relationship this.mvc.perform(MockMvcRequestBuilders.get(APPLICATIONS_API + "/{id}/commands", applicationId1)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(ID))); this.mvc.perform(MockMvcRequestBuilders.get(APPLICATIONS_API + "/{id}/commands", applicationId2)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.empty())); this.mvc.perform(MockMvcRequestBuilders.get(APPLICATIONS_API + "/{id}/commands", applicationId3)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(1))) .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(ID))); }