Previously, whenever a MockMvc perform call was made and the request and response were to be documented, calls to documentCurlRequest and documentCurlResponse had to be made. This commit updates the REST documentation framework to make the documentation of the request and response automatic. It makes use of MockMvc’s MockMvcConfigurer that was introduced in Spring 4.1. Applying RestDocumentationConfiguration once will cause all requests and responses to be documented: this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) .apply(new RestDocumentationConfiguration()).build(); The path to which the requests and response documentation snippets will be written is determined by the class and method in which the MockMvc perform call is made and is currently of the form shortClassName/methodName(Request|Response|RequestResponse).asciidoc where shortClassName is the name of the documentation class without its package. This works for both @Test methods and any non-private methods that are called from the test method. The methods must be non-private as a CGLib proxy is used to intercept the calls and configure the output path.
45 lines
1.0 KiB
Groovy
45 lines
1.0 KiB
Groovy
buildscript {
|
|
repositories {
|
|
mavenLocal()
|
|
maven {
|
|
url 'https://repo.spring.io/libs-milestone'
|
|
}
|
|
}
|
|
dependencies {
|
|
classpath 'org.springframework.restdocs:spring-restdocs-gradle-plugin:0.1.0.BUILD-SNAPSHOT'
|
|
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.0.M2'
|
|
}
|
|
}
|
|
|
|
apply plugin: 'java'
|
|
apply plugin: 'spring-boot'
|
|
apply plugin: 'eclipse'
|
|
apply plugin: 'org.springframework.restdocs'
|
|
|
|
repositories {
|
|
mavenLocal()
|
|
maven {
|
|
url 'https://repo.spring.io/libs-milestone'
|
|
}
|
|
}
|
|
|
|
group = 'com.example'
|
|
|
|
dependencies {
|
|
compile 'org.springframework.boot:spring-boot-starter-data-rest'
|
|
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
|
|
|
|
runtime 'com.h2database:h2'
|
|
|
|
documentationCompile 'com.jayway.jsonpath:json-path'
|
|
documentationCompile 'org.springframework.boot:spring-boot-starter-test'
|
|
documentationCompile 'org.springframework.restdocs:spring-restdocs-core:0.1.0.BUILD-SNAPSHOT'
|
|
|
|
}
|
|
|
|
task wrapper(type: Wrapper) {
|
|
gradleVersion = '2.1'
|
|
}
|
|
|
|
eclipseJdt.onlyIf { false }
|
|
cleanEclipseJdt.onlyIf { false } |