List of usage examples for org.springframework.restdocs.payload PayloadDocumentation requestFields
public static RequestFieldsSnippet requestFields(List<FieldDescriptor> descriptors)
From source file:com.netflix.genie.web.controllers.ApplicationRestControllerIntegrationTests.java
/** * Test to make sure we can add configurations to the application after it is created. * * @throws Exception on configuration problems */// w w w . j av a 2 s .c om @Test public void canAddConfigsToApplication() throws Exception { Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L)); this.createConfigResource( new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).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(Snippets.CONFIG_FIELDS) // request payload fields ); 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.JSON_CONTENT_TYPE_HEADER, // response headers PayloadDocumentation.responseFields(Snippets.CONFIG_FIELDS) // response fields ); this.canAddElementsToResource(APPLICATIONS_API + "/{id}/configs", ID, addResultHandler, getResultHandler); }
From source file:com.netflix.genie.web.controllers.ClusterRestControllerIntegrationTests.java
/** * Test to make sure we can add tags to the cluster after it is created. * * @throws Exception on configuration problems *//*from www . j av a 2 s . com*/ @Test public void canAddTagsToCluster() throws Exception { Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(0L)); this.createConfigResource(new Cluster.Builder(NAME, USER, VERSION, ClusterStatus.UP).withId(ID).build(), null); final String api = CLUSTERS_API + "/{id}/tags"; final RestDocumentationResultHandler addResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request header Snippets.ID_PATH_PARAM, // Path parameters PayloadDocumentation.requestFields(Snippets.TAGS_FIELDS) // Request fields ); 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.JSON_CONTENT_TYPE_HEADER, // Response header PayloadDocumentation.responseFields(Snippets.TAGS_FIELDS)); this.canAddTagsToResource(api, ID, NAME, addResultHandler, getResultHandler); }
From source file:com.netflix.genie.web.controllers.CommandRestControllerIntegrationTests.java
/** * Test to make sure we can add dependencies to the command after it is created. * * @throws Exception on configuration problems *//* www . j a v a 2 s. c o m*/ @Test public void canAddDependenciesToCommand() throws Exception { Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(0L)); this.createConfigResource( new Command.Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE, CHECK_DELAY).withId(ID) .build(), null); final RestDocumentationResultHandler addResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // path params Snippets.CONTENT_TYPE_HEADER, // request header PayloadDocumentation.requestFields(Snippets.DEPENDENCIES_FIELDS) // response fields ); final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // path params Snippets.JSON_CONTENT_TYPE_HEADER, // response headers PayloadDocumentation.responseFields(Snippets.DEPENDENCIES_FIELDS) // response fields ); this.canAddElementsToResource(COMMANDS_API + "/{id}/dependencies", ID, addResultHandler, getResultHandler); }
From source file:com.netflix.genie.web.controllers.ApplicationRestControllerIntegrationTests.java
/** * Test to make sure we can update the configurations for an application after it is created. * * @throws Exception on configuration problems *///ww w . ja v a 2s .com @Test public void canUpdateConfigsForApplication() throws Exception { Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L)); this.createConfigResource( new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(), null); final RestDocumentationResultHandler updateResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request header Snippets.ID_PATH_PARAM, // Path parameters PayloadDocumentation.requestFields(Snippets.CONFIG_FIELDS) // Request fields ); this.canUpdateElementsForResource(APPLICATIONS_API + "/{id}/configs", ID, updateResultHandler); }
From source file:com.netflix.genie.web.controllers.ClusterRestControllerIntegrationTests.java
/** * Test to make sure we can update the tags for a cluster after it is created. * * @throws Exception on configuration problems *//*from w ww. j ava 2 s .c o m*/ @Test public void canUpdateTagsForCluster() throws Exception { Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(0L)); this.createConfigResource(new Cluster.Builder(NAME, USER, VERSION, ClusterStatus.UP).withId(ID).build(), null); final String api = CLUSTERS_API + "/{id}/tags"; final RestDocumentationResultHandler updateResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request header Snippets.ID_PATH_PARAM, // Path parameters PayloadDocumentation.requestFields(Snippets.TAGS_FIELDS) // Request fields ); this.canUpdateTagsForResource(api, ID, NAME, updateResultHandler); }
From source file:com.netflix.genie.web.controllers.CommandRestControllerIntegrationTests.java
/** * Test to make sure we can update the dependencies for an command after it is created. * * @throws Exception on configuration problems *///from ww w . j a v a 2s .c o m @Test public void canUpdateDependenciesForCommand() throws Exception { Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(0L)); this.createConfigResource( new Command.Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE, CHECK_DELAY).withId(ID) .build(), null); final RestDocumentationResultHandler updateResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request header Snippets.ID_PATH_PARAM, // Path parameters PayloadDocumentation.requestFields(Snippets.DEPENDENCIES_FIELDS) // Request fields ); this.canUpdateElementsForResource(COMMANDS_API + "/{id}/dependencies", ID, updateResultHandler); }
From source file:com.netflix.genie.web.controllers.ApplicationRestControllerIntegrationTests.java
/** * Test to make sure we can add dependencies to the application after it is created. * * @throws Exception on configuration problems *//*from w ww .ja v a 2 s . c o m*/ @Test public void canAddDependenciesToApplication() throws Exception { Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L)); this.createConfigResource( new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(), null); final RestDocumentationResultHandler addResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // path params Snippets.CONTENT_TYPE_HEADER, // request header PayloadDocumentation.requestFields(Snippets.DEPENDENCIES_FIELDS) // response fields ); final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.ID_PATH_PARAM, // path params Snippets.JSON_CONTENT_TYPE_HEADER, // response headers PayloadDocumentation.responseFields(Snippets.DEPENDENCIES_FIELDS) // response fields ); this.canAddElementsToResource(APPLICATIONS_API + "/{id}/dependencies", ID, addResultHandler, getResultHandler); }
From source file:com.netflix.genie.web.controllers.CommandRestControllerIntegrationTests.java
/** * Test to make sure we can add tags to the command after it is created. * * @throws Exception on configuration problems */// w w w.java 2 s . com @Test public void canAddTagsToCommand() throws Exception { Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(0L)); this.createConfigResource( new Command.Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE, CHECK_DELAY).withId(ID) .build(), null); final String api = COMMANDS_API + "/{id}/tags"; final RestDocumentationResultHandler addResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request header Snippets.ID_PATH_PARAM, // Path parameters PayloadDocumentation.requestFields(Snippets.TAGS_FIELDS) // Request fields ); 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.JSON_CONTENT_TYPE_HEADER, // Response header PayloadDocumentation.responseFields(Snippets.TAGS_FIELDS)); this.canAddTagsToResource(api, ID, NAME, addResultHandler, getResultHandler); }
From source file:com.netflix.genie.web.controllers.ApplicationRestControllerIntegrationTests.java
/** * Test to make sure we can update the dependencies for an application after it is created. * * @throws Exception on configuration problems *//* w ww . ja va2s. co m*/ @Test public void canUpdateDependenciesForApplication() throws Exception { Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L)); this.createConfigResource( new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(), null); final RestDocumentationResultHandler updateResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), Snippets.CONTENT_TYPE_HEADER, // Request header Snippets.ID_PATH_PARAM, // Path parameters PayloadDocumentation.requestFields(Snippets.DEPENDENCIES_FIELDS) // Request fields ); this.canUpdateElementsForResource(APPLICATIONS_API + "/{id}/dependencies", ID, updateResultHandler); }
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 . j av 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); }