org.springframework.restdocs.RestDocumentationContextProvider Java Examples

The following examples show how to use org.springframework.restdocs.RestDocumentationContextProvider. 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: EmployeeRepositoryTest.java    From spring-data-jpa-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up.
 *
 * @param restDocumentation the rest documentation
 */
@BeforeEach
protected void setUp(RestDocumentationContextProvider restDocumentation) {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
            .apply(documentationConfiguration(restDocumentation)
                    .operationPreprocessors()
                    .withRequestDefaults(prettyPrint())
            )
            .build();
}
 
Example #2
Source File: SpringDataJpaDemoApplicationTests.java    From spring-data-jpa-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up.
 *
 * @param restDocumentation the rest documentation
 */
@BeforeEach
protected void setUp(RestDocumentationContextProvider restDocumentation) {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
            .apply(documentationConfiguration(restDocumentation)
                    .operationPreprocessors()
                    .withRequestDefaults(prettyPrint())
            )
            .build();
}
 
Example #3
Source File: FraudBaseWithStandaloneSetup.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup(TestInfo info, RestDocumentationContextProvider restDocumentation) {
	RestAssuredMockMvc.standaloneSetup(MockMvcBuilders
			.standaloneSetup(new FraudDetectionController())
			.apply(documentationConfiguration(restDocumentation))
			.alwaysDo(document(
					getClass().getSimpleName() + "_" + info.getDisplayName())));
}
 
Example #4
Source File: FraudBaseWithWebAppSetup.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup(TestInfo info, RestDocumentationContextProvider restDocumentation) {
	RestAssuredMockMvc.mockMvc(MockMvcBuilders.webAppContextSetup(this.context)
			.apply(documentationConfiguration(restDocumentation))
			.alwaysDo(document(
					getClass().getSimpleName() + "_" + info.getDisplayName()))
			.build());
}
 
Example #5
Source File: ControllerTestTemplate.java    From coderadar with MIT License 5 votes vote down vote up
@BeforeEach
public void setup(RestDocumentationContextProvider restDocumentation) {
  MockitoAnnotations.initMocks(this);
  mvc =
      MockMvcBuilders.webAppContextSetup(applicationContext)
          .apply(MockMvcRestDocumentation.documentationConfiguration(restDocumentation))
          .build();
}
 
Example #6
Source File: ApiDocumentationJUnit5IntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@BeforeEach
public void setUp(WebApplicationContext webApplicationContext, RestDocumentationContextProvider restDocumentation) {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
        .apply(documentationConfiguration(restDocumentation))
        .alwaysDo(document("{method-name}", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint())))
        .build();
}
 
Example #7
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 #8
Source File: SpringRestDocsUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@BeforeEach
public void setup(WebApplicationContext webApplicationContext, RestDocumentationContextProvider restDocumentation) {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
        .apply(documentationConfiguration(restDocumentation))
        .build();
}