Example usage for org.springframework.restdocs.payload PayloadDocumentation responseFields

List of usage examples for org.springframework.restdocs.payload PayloadDocumentation responseFields

Introduction

In this page you can find the example usage for org.springframework.restdocs.payload PayloadDocumentation responseFields.

Prototype

public static ResponseFieldsSnippet responseFields(List<FieldDescriptor> descriptors) 

Source Link

Document

Returns a Snippet that will document the fields of the API operation's response payload.

Usage

From source file:com.netflix.genie.web.controllers.ClusterRestControllerIntegrationTests.java

/**
 * Test to make sure we can add dependencies to the cluster after it is created.
 *
 * @throws Exception on configuration problems
 *///w w  w.  j av a  2  s  .  c om
@Test
public void canAddDependenciesToCluster() 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 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(CLUSTERS_API + "/{id}/dependencies", ID, addResultHandler, getResultHandler);
}

From source file:com.netflix.genie.web.controllers.CommandRestControllerIntegrationTests.java

/**
 * Test to make sure we can add configurations to the command after it is created.
 *
 * @throws Exception on configuration problems
 */// w  w w . j a  v a 2 s  .  c  o m
@Test
public void canAddConfigsToCommand() 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.CONFIG_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.CONFIG_FIELDS) // response fields
    );
    this.canAddElementsToResource(COMMANDS_API + "/{id}/configs", ID, addResultHandler, getResultHandler);
}

From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java

private void checkJobApplications(final int documentationId, final String id) {
    final RestDocumentationFilter getResultFilter = RestAssuredRestDocumentation.document(
            "{class-name}/" + documentationId + "/getJobApplications/", Snippets.ID_PATH_PARAM, // Path parameters
            Snippets.HAL_CONTENT_TYPE_HEADER, // Response Headers
            PayloadDocumentation.responseFields(PayloadDocumentation.subsectionWithPath("[]")
                    .description("The applications for the job").attributes(Snippets.EMPTY_CONSTRAINTS)) // Response fields
    );/*from   w ww.  j av  a  2 s.  c o m*/

    RestAssured.given(this.getRequestSpecification()).filter(getResultFilter).when().port(this.port)
            .get(JOBS_API + "/{id}/applications", id).then().statusCode(Matchers.is(HttpStatus.OK.value()))
            .contentType(Matchers.is(MediaTypes.HAL_JSON_UTF8_VALUE)).body("$", Matchers.hasSize(2))
            .body("[0].id", Matchers.is(APP1_ID)).body("[1].id", Matchers.is(APP2_ID));
}

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
 *///from   w ww.  j  a  va  2 s  .  c  o m
@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 w  w w.ja  v  a2s  . co m
@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
 *//*from www.jav 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 add dependencies to the application after it is created.
 *
 * @throws Exception on configuration problems
 *//*from   w  w  w  .  j av a2s. 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  ww.  java 2  s  . c om
@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.JobRestControllerIntegrationTests.java

private void checkJobApplications(final int documentationId, final String id) throws Exception {
    final RestDocumentationResultHandler getResultHandler = MockMvcRestDocumentation.document(
            "{class-name}/" + documentationId + "/getJobApplications/",
            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 applications for the job").attributes(Snippets.EMPTY_CONSTRAINTS)) // Response fields
    );// w  w  w .  j a v a2 s.  co  m
    this.mvc.perform(RestDocumentationRequestBuilders.get(JOBS_API + "/{id}/applications", id))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andExpect(MockMvcResultMatchers.jsonPath("$", Matchers.hasSize(2)))
            .andExpect(MockMvcResultMatchers.jsonPath("$[0].id", Matchers.is(APP1_ID)))
            .andExpect(MockMvcResultMatchers.jsonPath("$[1].id", Matchers.is(APP2_ID))).andDo(getResultHandler);
}

From source file:com.netflix.genie.web.controllers.ApplicationRestControllerIntegrationTests.java

/**
 * Test to make sure we can add tags to the application after it is created.
 *
 * @throws Exception on configuration problems
 */// ww w .  j  av a 2s .c om
@Test
public void canAddTagsToApplication() 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 String api = APPLICATIONS_API + "/{id}/tags";

    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.TAGS_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 parameters
            Snippets.JSON_CONTENT_TYPE_HEADER, // response headers
            PayloadDocumentation.responseFields(Snippets.TAGS_FIELDS) // response fields
    );
    this.canAddTagsToResource(api, ID, NAME, addResultHandler, getResultHandler);
}