Java Code Examples for org.springframework.restdocs.payload.PayloadDocumentation

The following examples show how to use org.springframework.restdocs.payload.PayloadDocumentation. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
void canAddConfigsToApplication() throws Exception {
    this.createConfigResource(
        new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(),
        null
    );

    final RestDocumentationFilter addFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.CONTENT_TYPE_HEADER, // request headers
        Snippets.ID_PATH_PARAM, // path parameters
        PayloadDocumentation.requestFields(Snippets.CONFIG_FIELDS) // request payload fields
    );
    final RestDocumentationFilter getFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        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, addFilter, getFilter);
}
 
Example 2
@Test
void canAddDependenciesToApplication() throws Exception {
    this.createConfigResource(
        new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(),
        null
    );

    final RestDocumentationFilter addFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.ID_PATH_PARAM, // path params
        Snippets.CONTENT_TYPE_HEADER, // request header
        PayloadDocumentation.requestFields(Snippets.DEPENDENCIES_FIELDS) // response fields
    );
    final RestDocumentationFilter getFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        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,
        addFilter,
        getFilter
    );
}
 
Example 3
@Test
void canUpdateDependenciesForApplication() throws Exception {
    this.createConfigResource(
        new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(),
        null
    );

    final RestDocumentationFilter updateFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        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,
        updateFilter
    );
}
 
Example 4
@Test
void canAddTagsToApplication() throws Exception {
    this.createConfigResource(
        new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(),
        null
    );
    final String api = APPLICATIONS_API + "/{id}/tags";

    final RestDocumentationFilter addFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.ID_PATH_PARAM, // path params
        Snippets.CONTENT_TYPE_HEADER, // request header
        PayloadDocumentation.requestFields(Snippets.TAGS_FIELDS) // response fields
    );
    final RestDocumentationFilter getFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        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, addFilter, getFilter);
}
 
Example 5
@Test
void canUpdateTagsForApplication() throws Exception {
    this.createConfigResource(
        new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(),
        null
    );
    final String api = APPLICATIONS_API + "/{id}/tags";

    final RestDocumentationFilter updateFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.CONTENT_TYPE_HEADER, // Request header
        Snippets.ID_PATH_PARAM, // Path parameters
        PayloadDocumentation.requestFields(Snippets.TAGS_FIELDS) // Request fields
    );
    this.canUpdateTagsForResource(api, ID, NAME, updateFilter);
}
 
Example 6
@Test
void canAddConfigsToCommand() throws Exception {
    this.createConfigResource(
        new Command
            .Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE_AND_ARGS, CHECK_DELAY)
            .withId(ID)
            .build(),
        null
    );

    final RestDocumentationFilter addFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.ID_PATH_PARAM, // path params
        Snippets.CONTENT_TYPE_HEADER, // request header
        PayloadDocumentation.requestFields(Snippets.CONFIG_FIELDS) // response fields
    );
    final RestDocumentationFilter getFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        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, addFilter, getFilter);
}
 
Example 7
@Test
void canUpdateConfigsForCommand() throws Exception {
    this.createConfigResource(
        new Command
            .Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE_AND_ARGS, CHECK_DELAY)
            .withId(ID)
            .build(),
        null
    );

    final RestDocumentationFilter updateFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.CONTENT_TYPE_HEADER, // Request header
        Snippets.ID_PATH_PARAM, // Path parameters
        PayloadDocumentation.requestFields(Snippets.CONFIG_FIELDS) // Request fields
    );
    this.canUpdateElementsForResource(COMMANDS_API + "/{id}/configs", ID, updateFilter);
}
 
Example 8
@Test
void canUpdateDependenciesForCommand() throws Exception {
    this.createConfigResource(
        new Command.Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE_AND_ARGS, CHECK_DELAY)
            .withId(ID)
            .build(),
        null
    );

    final RestDocumentationFilter updateFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        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,
        updateFilter
    );
}
 
Example 9
@Test
void canAddTagsToCommand() throws Exception {
    this.createConfigResource(
        new Command
            .Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE_AND_ARGS, CHECK_DELAY)
            .withId(ID)
            .build(),
        null
    );
    final String api = COMMANDS_API + "/{id}/tags";

    final RestDocumentationFilter addFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.CONTENT_TYPE_HEADER, // Request header
        Snippets.ID_PATH_PARAM, // Path parameters
        PayloadDocumentation.requestFields(Snippets.TAGS_FIELDS) // Request fields
    );
    final RestDocumentationFilter getFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.ID_PATH_PARAM, // Path parameters
        Snippets.JSON_CONTENT_TYPE_HEADER, // Response header
        PayloadDocumentation.responseFields(Snippets.TAGS_FIELDS)
    );
    this.canAddTagsToResource(api, ID, NAME, addFilter, getFilter);
}
 
Example 10
@Test
void canUpdateTagsForCommand() throws Exception {
    this.createConfigResource(
        new Command
            .Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE_AND_ARGS, CHECK_DELAY)
            .withId(ID)
            .build(),
        null
    );
    final String api = COMMANDS_API + "/{id}/tags";

    final RestDocumentationFilter updateFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.CONTENT_TYPE_HEADER, // Request header
        Snippets.ID_PATH_PARAM, // Path parameters
        PayloadDocumentation.requestFields(Snippets.TAGS_FIELDS) // Request fields
    );
    this.canUpdateTagsForResource(api, ID, NAME, updateFilter);
}
 
Example 11
Source Project: genie   Source File: Snippets.java    License: Apache License 2.0 6 votes vote down vote up
static ResponseFieldsSnippet resolveClustersForCommandClusterCriteriaResponsePayload() {
    return PayloadDocumentation
        .responseFields(
            PayloadDocumentation
                .fieldWithPath("[]")
                .attributes(EMPTY_CONSTRAINTS)
                .description("The list of criterion and associated resolved clusters")
                .type(JsonFieldType.ARRAY)
                .optional()
        )
        .andWithPrefix(
            "[].",
            PayloadDocumentation
                .fieldWithPath("criterion")
                .attributes(EMPTY_CONSTRAINTS)
                .description("The criterion that was evaluated to yield the resources")
                .type(JsonFieldType.OBJECT),
            PayloadDocumentation
                .fieldWithPath("resources")
                .attributes(EMPTY_CONSTRAINTS)
                .description("The resources that were resolved by evaluating the criterion")
                .type(JsonFieldType.ARRAY)
        )
        .andWithPrefix("[].criterion.", getCriterionFieldDescriptors())
        .andWithPrefix("[].resources[].", getClusterFieldDescriptors());
}
 
Example 12
Source Project: genie   Source File: Snippets.java    License: Apache License 2.0 6 votes vote down vote up
private static FieldDescriptor[] getApplicationFieldDescriptors() {
    return ArrayUtils.addAll(
        getConfigFieldDescriptors(APPLICATION_CONSTRAINTS),
        PayloadDocumentation
            .fieldWithPath("type")
            .attributes(getConstraintsForField(APPLICATION_CONSTRAINTS, "type"))
            .description("The type of application this is (e.g. hadoop, presto, spark). Can be used to group.")
            .type(JsonFieldType.STRING)
            .optional(),
        PayloadDocumentation
            .fieldWithPath("status")
            .attributes(getConstraintsForField(APPLICATION_CONSTRAINTS, "status"))
            .description(
                "The status of the application. Options: " + Arrays.toString(ApplicationStatus.values())
            )
            .type(JsonFieldType.STRING),
        PayloadDocumentation
            .fieldWithPath("dependencies")
            .attributes(getConstraintsForField(APPLICATION_CONSTRAINTS, "dependencies"))
            .description("The dependencies for the application")
            .type(JsonFieldType.ARRAY)
            .optional()
    );
}
 
Example 13
Source Project: genie   Source File: Snippets.java    License: Apache License 2.0 6 votes vote down vote up
private static FieldDescriptor[] getClusterFieldDescriptors() {
    return ArrayUtils.addAll(
        getConfigFieldDescriptors(CLUSTER_CONSTRAINTS),
        PayloadDocumentation
            .fieldWithPath("status")
            .attributes(getConstraintsForField(CLUSTER_CONSTRAINTS, "status"))
            .description(
                "The status of the cluster. Options: " + Arrays.toString(ClusterStatus.values())
            )
            .type(JsonFieldType.STRING),
        PayloadDocumentation
            .fieldWithPath("dependencies")
            .attributes(getConstraintsForField(CLUSTER_CONSTRAINTS, "dependencies"))
            .description("The dependencies for the cluster")
            .type(JsonFieldType.ARRAY)
            .optional()
    );
}
 
Example 14
Source Project: genie   Source File: Snippets.java    License: Apache License 2.0 6 votes vote down vote up
private static FieldDescriptor[] getBaseFieldDescriptors(final ConstraintDescriptions constraintDescriptions) {
    return new FieldDescriptor[]{
        PayloadDocumentation
            .fieldWithPath("id")
            .attributes(getConstraintsForField(constraintDescriptions, "id"))
            .description("The id. If not set the system will set one.")
            .type(JsonFieldType.STRING)
            .optional(),
        PayloadDocumentation
            .fieldWithPath("created")
            .attributes(getConstraintsForField(constraintDescriptions, "created"))
            .description("The UTC time of creation. Set by system. ISO8601 format including milliseconds.")
            .type(JsonFieldType.STRING)
            .optional(),
        PayloadDocumentation
            .fieldWithPath("updated")
            .attributes(getConstraintsForField(constraintDescriptions, "updated"))
            .description("The UTC time of last update. Set by system. ISO8601 format including milliseconds.")
            .type(JsonFieldType.STRING)
            .optional(),
    };
}
 
Example 15
Source Project: genie   Source File: JobRestControllerIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
private void checkJobStatus(final int documentationId, final String id) {
    final RestDocumentationFilter getResultFilter = RestAssuredRestDocumentation.document(
        "{class-name}/" + documentationId + "/getJobStatus/",
        Snippets.ID_PATH_PARAM, // Path parameters
        Snippets.JSON_CONTENT_TYPE_HEADER, // Response Headers
        PayloadDocumentation.responseFields(
            PayloadDocumentation
                .fieldWithPath("status")
                .description("The job status. One of: " + Arrays.toString(JobStatus.values()))
                .attributes(Snippets.EMPTY_CONSTRAINTS)
        ) // Response fields
    );

    RestAssured
        .given(this.getRequestSpecification())
        .filter(getResultFilter)
        .when()
        .port(this.port)
        .get(JOBS_API + "/{id}/status", id)
        .then()
        .contentType(Matchers.containsString(MediaType.APPLICATION_JSON_VALUE))
        .body(STATUS_PATH, Matchers.is(JobStatus.SUCCEEDED.toString()));
}
 
Example 16
Source Project: genie   Source File: JobRestControllerIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
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
    );

    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.containsString(MediaTypes.HAL_JSON_VALUE))
        .body("$", Matchers.hasSize(2))
        .body("[0].id", Matchers.is(APP1_ID))
        .body("[1].id", Matchers.is(APP2_ID));
}
 
Example 17
@Test
void canAddConfigsToCluster() throws Exception {
    this.createConfigResource(new Cluster.Builder(NAME, USER, VERSION, ClusterStatus.UP).withId(ID).build(), null);

    final RestDocumentationFilter addFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.ID_PATH_PARAM, // path params
        Snippets.CONTENT_TYPE_HEADER, // request header
        PayloadDocumentation.requestFields(Snippets.CONFIG_FIELDS) // response fields
    );
    final RestDocumentationFilter getFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.ID_PATH_PARAM, // path params
        Snippets.JSON_CONTENT_TYPE_HEADER, // response headers
        PayloadDocumentation.responseFields(Snippets.CONFIG_FIELDS) // response fields
    );
    this.canAddElementsToResource(CLUSTERS_API + "/{id}/configs", ID, addFilter, getFilter);
}
 
Example 18
@Test
void canAddDependenciesToCluster() throws Exception {
    this.createConfigResource(new Cluster.Builder(NAME, USER, VERSION, ClusterStatus.UP).withId(ID).build(), null);

    final RestDocumentationFilter addFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.ID_PATH_PARAM, // path params
        Snippets.CONTENT_TYPE_HEADER, // request header
        PayloadDocumentation.requestFields(Snippets.DEPENDENCIES_FIELDS) // response fields
    );
    final RestDocumentationFilter getFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        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, addFilter, getFilter);
}
 
Example 19
@Test
void canAddTagsToCluster() throws Exception {
    this.createConfigResource(new Cluster.Builder(NAME, USER, VERSION, ClusterStatus.UP).withId(ID).build(), null);
    final String api = CLUSTERS_API + "/{id}/tags";

    final RestDocumentationFilter addFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.CONTENT_TYPE_HEADER, // Request header
        Snippets.ID_PATH_PARAM, // Path parameters
        PayloadDocumentation.requestFields(Snippets.TAGS_FIELDS) // Request fields
    );
    final RestDocumentationFilter getFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.ID_PATH_PARAM, // Path parameters
        Snippets.JSON_CONTENT_TYPE_HEADER, // Response header
        PayloadDocumentation.responseFields(Snippets.TAGS_FIELDS)
    );
    this.canAddTagsToResource(api, ID, NAME, addFilter, getFilter);
}
 
Example 20
/**
 * Generate API documentation for GET /api/greetings/{id}.
 * 
 * @throws Exception Thrown if documentation generation failure occurs.
 */
@Test
public void documentGetGreeting() throws Exception {

    // Generate API Documentation
    final MvcResult result = this.mockMvc
            .perform(RestDocumentationRequestBuilders
                    .get("/api/greetings/{id}", "0").accept(MediaType.APPLICATION_JSON))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andDo(MockMvcRestDocumentation.document("get-greeting",
                    RequestDocumentation.pathParameters(
                            RequestDocumentation.parameterWithName("id").description("The greeting identifier.")),
                    PayloadDocumentation.relaxedResponseFields(
                            PayloadDocumentation.fieldWithPath("id")
                                    .description(
                                            "The identifier. Used to reference specific greetings in API requests.")
                                    .type(JsonFieldType.NUMBER),
                            PayloadDocumentation.fieldWithPath("referenceId")
                                    .description("The supplementary identifier.").type(JsonFieldType.STRING),
                            PayloadDocumentation.fieldWithPath("text").description("The text.")
                                    .type(JsonFieldType.STRING),
                            PayloadDocumentation.fieldWithPath("version").description("The entity version.")
                                    .type(JsonFieldType.NUMBER),
                            PayloadDocumentation.fieldWithPath("createdBy").description("The entity creator.")
                                    .type(JsonFieldType.STRING),
                            PayloadDocumentation.fieldWithPath("createdAt").description("The creation timestamp.")
                                    .type(JsonFieldType.STRING),
                            PayloadDocumentation.fieldWithPath("updatedBy").description("The last modifier.")
                                    .type(JsonFieldType.STRING).optional(),
                            PayloadDocumentation.fieldWithPath("updatedAt")
                                    .description("The last modification timestamp.").type(JsonFieldType.STRING)
                                    .optional())))
            .andReturn();

    // Perform a simple, standard JUnit assertion to satisfy PMD rule
    Assert.assertEquals("failure - expected HTTP status 200", 200, result.getResponse().getStatus());

}
 
Example 21
/**
 * Generate API documentation for POST /api/greetings.
 * 
 * @throws Exception Thrown if documentation generation failure occurs.
 */
@Test
public void documentCreateGreeting() throws Exception {

    // Generate API Documentation
    final MvcResult result = this.mockMvc
            .perform(RestDocumentationRequestBuilders.post("/api/greetings").contentType(MediaType.APPLICATION_JSON)
                    .accept(MediaType.APPLICATION_JSON).content(REQUEST_BODY))
            .andExpect(MockMvcResultMatchers.status().isCreated())
            .andDo(MockMvcRestDocumentation.document("create-greeting",
                    PayloadDocumentation.relaxedRequestFields(PayloadDocumentation.fieldWithPath("text")
                            .description("The text.").type(JsonFieldType.STRING)),
                    PayloadDocumentation.relaxedResponseFields(
                            PayloadDocumentation
                                    .fieldWithPath("id")
                                    .description(
                                            "The identifier. Used to reference specific greetings in API requests.")
                                    .type(JsonFieldType.NUMBER),
                            PayloadDocumentation.fieldWithPath("referenceId")
                                    .description("The supplementary identifier.").type(JsonFieldType.STRING),
                            PayloadDocumentation.fieldWithPath("text").description("The text.")
                                    .type(JsonFieldType.STRING),
                            PayloadDocumentation.fieldWithPath("version").description("The entity version.")
                                    .type(JsonFieldType.NUMBER),
                            PayloadDocumentation.fieldWithPath("createdBy").description("The entity creator.")
                                    .type(JsonFieldType.STRING),
                            PayloadDocumentation.fieldWithPath("createdAt").description("The creation timestamp.")
                                    .type(JsonFieldType.STRING),
                            PayloadDocumentation.fieldWithPath("updatedBy").description("The last modifier.")
                                    .type(JsonFieldType.STRING).optional(),
                            PayloadDocumentation.fieldWithPath("updatedAt")
                                    .description("The last modification timestamp.").type(JsonFieldType.STRING)
                                    .optional())))
            .andReturn();

    // Perform a simple, standard JUnit assertion to satisfy PMD rule
    Assert.assertEquals("failure - expected HTTP status 201", 201, result.getResponse().getStatus());

}
 
Example 22
/**
 * Generate API documentation for PUT /api/greetings/{id}.
 * 
 * @throws Exception Thrown if documentation generation failure occurs.
 */
@Test
public void documentUpdateGreeting() throws Exception {

    // Generate API Documentation
    final MvcResult result = this.mockMvc.perform(RestDocumentationRequestBuilders.put("/api/greetings/{id}", 1)
            .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).content(REQUEST_BODY))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andDo(MockMvcRestDocumentation.document("update-greeting",
                    RequestDocumentation.pathParameters(
                            RequestDocumentation.parameterWithName("id").description("The greeting identifier.")),
                    PayloadDocumentation.relaxedRequestFields(PayloadDocumentation.fieldWithPath("text")
                            .description("The text.").type(JsonFieldType.STRING)),
                    PayloadDocumentation.relaxedResponseFields(
                            PayloadDocumentation
                                    .fieldWithPath("id")
                                    .description(
                                            "The identifier. Used to reference specific greetings in API requests.")
                                    .type(JsonFieldType.NUMBER),
                            PayloadDocumentation.fieldWithPath("referenceId")
                                    .description("The supplementary identifier.").type(JsonFieldType.STRING),
                            PayloadDocumentation.fieldWithPath("text").description("The text.")
                                    .type(JsonFieldType.STRING),
                            PayloadDocumentation.fieldWithPath("version").description("The entity version.")
                                    .type(JsonFieldType.NUMBER),
                            PayloadDocumentation.fieldWithPath("createdBy").description("The entity creator.")
                                    .type(JsonFieldType.STRING),
                            PayloadDocumentation.fieldWithPath("createdAt").description("The creation timestamp.")
                                    .type(JsonFieldType.STRING),
                            PayloadDocumentation.fieldWithPath("updatedBy").description("The last modifier.")
                                    .type(JsonFieldType.STRING).optional(),
                            PayloadDocumentation.fieldWithPath("updatedAt")
                                    .description("The last modification timestamp.").type(JsonFieldType.STRING)
                                    .optional())))
            .andReturn();

    // Perform a simple, standard JUnit assertion to satisfy PMD rule
    Assert.assertEquals("failure - expected HTTP status 200", 200, result.getResponse().getStatus());

}
 
Example 23
/**
 * Generate API documentation for GET /api/greetings.
 * 
 * @throws Exception Thrown if documentation generation failure occurs.
 */
@Test
public void documentGetGreetings() throws Exception {

    // Generate API Documentation
    final MvcResult result = this.mockMvc
            .perform(RestDocumentationRequestBuilders.get("/api/greetings").accept(MediaType.APPLICATION_JSON))
            .andExpect(MockMvcResultMatchers.status().isOk())
            .andDo(MockMvcRestDocumentation.document("get-greetings",
                    PayloadDocumentation.relaxedResponseFields(
                            PayloadDocumentation.fieldWithPath("[].id").description(
                                    "The identifier. Used to reference specific greetings in API requests."),
                            PayloadDocumentation.fieldWithPath("[].referenceId")
                                    .description("The supplementary identifier."),
                            PayloadDocumentation.fieldWithPath("[].text").description("The text."),
                            PayloadDocumentation.fieldWithPath("[].version").description("The entity version."),
                            PayloadDocumentation.fieldWithPath("[].createdBy").description("The entity creator."),
                            PayloadDocumentation.fieldWithPath("[].createdAt")
                                    .description("The creation timestamp."),
                            PayloadDocumentation.fieldWithPath("[].updatedBy").description("The last modifier."),
                            PayloadDocumentation.fieldWithPath("[].updatedAt")
                                    .description("The last modification timestamp."))))
            .andReturn();

    // Perform a simple, standard JUnit assertion to satisfy PMD rule
    Assert.assertEquals("failure - expected HTTP status 200", 200, result.getResponse().getStatus());

}
 
Example 24
Source Project: coderadar   Source File: ControllerTestTemplate.java    License: MIT License 5 votes vote down vote up
public FieldDescriptor withPath(String path) {
  return PayloadDocumentation.fieldWithPath(path)
      .attributes(
          Attributes.key("constraints")
              .value(
                  StringUtils.collectionToDelimitedString(
                      this.constraintDescriptions.descriptionsForProperty(path), ". ")));
}
 
Example 25
Source Project: coderadar   Source File: ControllerTestTemplate.java    License: MIT License 5 votes vote down vote up
/** Returns field descriptor for custom validators. */
public FieldDescriptor withCustomPath(String path) {
  return PayloadDocumentation.fieldWithPath(path)
      .attributes(
          Attributes.key("constraints")
              .value(
                  StringUtils.collectionToDelimitedString(
                      Collections.singletonList(customValidationDescription.getProperty(path)),
                      ". ")));
}
 
Example 26
@Test
void canUpdateConfigsForApplication() throws Exception {
    this.createConfigResource(
        new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE).withId(ID).build(),
        null
    );

    final RestDocumentationFilter updateFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        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, updateFilter);
}
 
Example 27
@Test
void canAddDependenciesToCommand() throws Exception {
    this.createConfigResource(
        new Command.Builder(NAME, USER, VERSION, CommandStatus.ACTIVE, EXECUTABLE_AND_ARGS, CHECK_DELAY)
            .withId(ID)
            .build(),
        null
    );

    final RestDocumentationFilter addFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        Snippets.ID_PATH_PARAM, // path params
        Snippets.CONTENT_TYPE_HEADER, // request header
        PayloadDocumentation.requestFields(Snippets.DEPENDENCIES_FIELDS) // response fields
    );
    final RestDocumentationFilter getFilter = RestAssuredRestDocumentation.document(
        "{class-name}/{method-name}/{step}/",
        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,
        addFilter,
        getFilter
    );
}
 
Example 28
Source Project: genie   Source File: Snippets.java    License: Apache License 2.0 5 votes vote down vote up
static ResponseFieldsSnippet getApplicationResponsePayload() {
    return PayloadDocumentation.responseFields(getApplicationFieldDescriptors())
        .and(
            PayloadDocumentation
                .subsectionWithPath("_links")
                .attributes(
                    Attributes
                        .key(CONSTRAINTS)
                        .value("")
                )
                .description("<<_hateoas,Links>> to other resources.")
                .ignored()
        );
}
 
Example 29
Source Project: genie   Source File: Snippets.java    License: Apache License 2.0 5 votes vote down vote up
static ResponseFieldsSnippet getClusterResponsePayload() {
    return PayloadDocumentation.responseFields(getClusterFieldDescriptors())
        .and(
            PayloadDocumentation
                .subsectionWithPath("_links")
                .attributes(
                    Attributes
                        .key(CONSTRAINTS)
                        .value("")
                )
                .description("<<_hateoas,Links>> to other resources.")
                .ignored()
        );
}
 
Example 30
Source Project: genie   Source File: Snippets.java    License: Apache License 2.0 5 votes vote down vote up
static ResponseFieldsSnippet getCommandResponsePayload() {
    return PayloadDocumentation.responseFields(getCommandFieldDescriptors())
        .and(
            PayloadDocumentation
                .subsectionWithPath("_links")
                .attributes(
                    Attributes
                        .key(CONSTRAINTS)
                        .value("")
                )
                .description("<<_hateoas,Links>> to other resources.")
                .ignored()
        );
}