org.springframework.restdocs.operation.preprocess.Preprocessors Java Examples

The following examples show how to use org.springframework.restdocs.operation.preprocess.Preprocessors. 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
Source File: ControllerTestTemplate.java    From coderadar with MIT License 5 votes vote down vote up
/**
 * Wraps the static document() method of RestDocs and configures it to pretty print request and
 * response JSON structures.
 */
protected RestDocumentationResultHandler document(String identifier, Snippet... snippets) {
  return MockMvcRestDocumentation.document(
      identifier,
      Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
      Preprocessors.preprocessResponse(Preprocessors.prettyPrint()),
      snippets);
}
 
Example #2
Source File: RestControllerIntegrationTestBase.java    From genie with Apache License 2.0 5 votes vote down vote up
@BeforeEach
    void beforeBase(final RestDocumentationContextProvider documentationContextProvider) {
        this.jobRepository.deleteAll();
        this.clusterRepository.deleteAll();
        this.commandRepository.deleteAll();
        this.applicationRepository.deleteAll();
        this.criterionRepository.deleteAll();
        this.fileRepository.deleteAll();
        this.tagRepository.deleteAll();
        this.agentConnectionRepository.deleteAll();

        this.requestSpecification = new RequestSpecBuilder()
            .addFilter(
                RestAssuredRestDocumentation
                    .documentationConfiguration(documentationContextProvider)
                    .snippets().withAdditionalDefaults(new WireMockSnippet())
                    .and()
                    .operationPreprocessors()
                    .withRequestDefaults(
                        Preprocessors.prettyPrint(),
                        Preprocessors.modifyUris().scheme(URI_SCHEME).host(URI_HOST).removePort()
                    )
                    .withResponseDefaults(
                        Preprocessors.prettyPrint(),
                        Preprocessors.modifyUris().host(URI_HOST).scheme(URI_SCHEME).removePort()
                    )
            )
//            .addFilter(new RequestLoggingFilter())
//            .addFilter(new ResponseLoggingFilter())
            .build();

        // The proper way to do this is annotate `port` with @LocalServerPort.
        // However what looks like a race condition during context initialization makes the test sporadically fail.
        // This should work more reliably since it happens after context is initialized
        this.port = this.environment.getRequiredProperty(LOCAL_TEST_SERVER_PORT_PROPERTY_NAME, Integer.class);
    }
 
Example #3
Source File: ResponseModifyingPreprocessors.java    From spring-auto-restdocs with Apache License 2.0 2 votes vote down vote up
/**
 * Only modifies the content of a response.
 * <p>
 * Contains {@link #replaceBinaryContent()}, {@link #limitJsonArrayLength(ObjectMapper)}
 *
 * @param objectMapper object mapper instance
 * @return a response shortening preprocessor
 */
public static OperationResponsePreprocessor shortenContent(ObjectMapper objectMapper) {
    return Preprocessors.preprocessResponse(replaceBinaryContent(),
            limitJsonArrayLength(objectMapper));
}