-
Notifications
You must be signed in to change notification settings - Fork 117
add REST Assured Support #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mduesterhoeft
merged 10 commits into
ePages-de:master
from
cnsgithub:rest-assured-support
Dec 21, 2018
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d4c2d4b
add REST Assured Support
cnsgithub ef2aa74
update Readme.md
cnsgithub bac2ffa
fix kotlin lint failures (code style, wildcard imports)
cnsgithub bd768d3
Move duplicated code in wrappers to common abstract base class
cnsgithub 7bd14cb
Create two new modules for mockmvc and restassured support
cnsgithub 63c86f8
Add dependency on new restdocs-api-spec-mockmvc module (now required …
cnsgithub 6dd3ac8
Fix: add missing dependency on jaxb-api - caused spring ApplicationCo…
cnsgithub 910b7c6
Fix: build adjustments for gradle5
cnsgithub 6019c91
Remove dependency on test classes from restdoc-api-spec module
cnsgithub 9df75e7
Add example for RestAssuredRestDocumentationWrapper usage to README.md
cnsgithub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
|
||
| plugins { | ||
| kotlin("jvm") | ||
| } | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| maven { url = uri("https://jitpack.io") } | ||
| } | ||
|
|
||
| val springBootVersion: String by extra | ||
| val springRestDocsVersion: String by extra | ||
| val junitVersion: String by extra | ||
|
|
||
| dependencies { | ||
| compile(kotlin("stdlib-jdk8")) | ||
|
|
||
| compile(project(":restdocs-api-spec")) | ||
| compile("org.springframework.restdocs:spring-restdocs-mockmvc:$springRestDocsVersion") | ||
|
|
||
| testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion") { | ||
| exclude("junit") | ||
| } | ||
| testCompile("org.junit.jupiter:junit-jupiter-engine:$junitVersion") | ||
| testImplementation("org.junit-pioneer:junit-pioneer:0.2.2") | ||
| testCompile("org.springframework.boot:spring-boot-starter-hateoas:$springBootVersion") | ||
| } | ||
|
|
98 changes: 98 additions & 0 deletions
98
...ec-mockmvc/src/main/kotlin/com/epages/restdocs/apispec/MockMvcRestDocumentationWrapper.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package com.epages.restdocs.apispec | ||
|
|
||
| import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation | ||
| import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler | ||
| import org.springframework.restdocs.operation.preprocess.OperationRequestPreprocessor | ||
| import org.springframework.restdocs.operation.preprocess.OperationResponsePreprocessor | ||
| import org.springframework.restdocs.snippet.Snippet | ||
| import java.util.function.Function | ||
|
|
||
| /** | ||
| * Convenience class to migrate to restdocs-openapi in a non-invasive way. | ||
| * It is a wrapper and replacement for MockMvcRestDocumentation that transparently adds a ResourceSnippet with the descriptors provided in the given snippets. | ||
| */ | ||
| object MockMvcRestDocumentationWrapper : RestDocumentationWrapper() { | ||
|
|
||
| @JvmOverloads @JvmStatic | ||
| fun document( | ||
| identifier: String, | ||
| resourceDetails: ResourceSnippetDetails, | ||
| requestPreprocessor: OperationRequestPreprocessor? = null, | ||
| responsePreprocessor: OperationResponsePreprocessor? = null, | ||
| snippetFilter: Function<List<Snippet>, List<Snippet>> = Function.identity(), | ||
| vararg snippets: Snippet | ||
| ): RestDocumentationResultHandler { | ||
|
|
||
| val enhancedSnippets = | ||
| enhanceSnippetsWithResourceSnippet( | ||
| resourceDetails = resourceDetails, | ||
| snippetFilter = snippetFilter, | ||
| snippets = *snippets | ||
| ) | ||
|
|
||
| if (requestPreprocessor != null && responsePreprocessor != null) { | ||
| return MockMvcRestDocumentation.document( | ||
| identifier, | ||
| requestPreprocessor, | ||
| responsePreprocessor, | ||
| *enhancedSnippets | ||
| ) | ||
| } else if (requestPreprocessor != null) { | ||
| return MockMvcRestDocumentation.document(identifier, requestPreprocessor, *enhancedSnippets) | ||
| } else if (responsePreprocessor != null) { | ||
| return MockMvcRestDocumentation.document(identifier, responsePreprocessor, *enhancedSnippets) | ||
| } | ||
|
|
||
| return MockMvcRestDocumentation.document(identifier, *enhancedSnippets) | ||
| } | ||
|
|
||
| @JvmOverloads @JvmStatic | ||
| fun document( | ||
| identifier: String, | ||
| description: String? = null, | ||
| summary: String? = null, | ||
| privateResource: Boolean = false, | ||
| deprecated: Boolean = false, | ||
| requestPreprocessor: OperationRequestPreprocessor? = null, | ||
| responsePreprocessor: OperationResponsePreprocessor? = null, | ||
| snippetFilter: Function<List<Snippet>, List<Snippet>> = Function.identity(), | ||
| vararg snippets: Snippet | ||
| ): RestDocumentationResultHandler { | ||
| return document( | ||
| identifier = identifier, | ||
| resourceDetails = ResourceSnippetParametersBuilder() | ||
| .description(description) | ||
| .summary(summary) | ||
| .privateResource(privateResource) | ||
| .deprecated(deprecated), | ||
| requestPreprocessor = requestPreprocessor, | ||
| responsePreprocessor = responsePreprocessor, | ||
| snippetFilter = snippetFilter, | ||
| snippets = *snippets | ||
| ) | ||
| } | ||
|
|
||
| @JvmStatic | ||
| fun document( | ||
| identifier: String, | ||
| requestPreprocessor: OperationRequestPreprocessor, | ||
| vararg snippets: Snippet | ||
| ): RestDocumentationResultHandler { | ||
| return document(identifier, null, null, false, false, requestPreprocessor, snippets = *snippets) | ||
| } | ||
|
|
||
| @JvmStatic | ||
| fun document( | ||
| identifier: String, | ||
| description: String, | ||
| privateResource: Boolean, | ||
| vararg snippets: Snippet | ||
| ): RestDocumentationResultHandler { | ||
| return document(identifier, description, null, privateResource, snippets = *snippets) | ||
| } | ||
|
|
||
| @JvmStatic | ||
| fun resourceDetails(): ResourceSnippetDetails { | ||
| return ResourceSnippetParametersBuilder() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would rather not share code between the tests. Mainly because I think the gradle setup for this is a little exotic and also complex. I would rather go for the code duplication here.