Support for stub priority
This commit is contained in:
committed by
Mariusz Smykuła
parent
9639e7395a
commit
9ccc2a2b8a
@@ -11,6 +11,7 @@ import io.codearte.accurest.dsl.internal.Response
|
||||
@ToString(includeFields = true, includePackage = false, includeNames = true)
|
||||
class GroovyDsl {
|
||||
|
||||
Integer priority
|
||||
Request request
|
||||
Response response
|
||||
|
||||
@@ -21,6 +22,10 @@ class GroovyDsl {
|
||||
return dsl
|
||||
}
|
||||
|
||||
void priority(int priority) {
|
||||
this.priority = new Integer(priority)
|
||||
}
|
||||
|
||||
void request(@DelegatesTo(Request) Closure closure) {
|
||||
this.request = new Request()
|
||||
closure.delegate = request
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.codearte.accurest.dsl
|
||||
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.transform.CompileDynamic
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
@@ -8,14 +9,21 @@ class WireMockStubStrategy {
|
||||
|
||||
private final WireMockRequestStubStrategy wireMockRequestStubStrategy
|
||||
private final WireMockResponseStubStrategy wireMockResponseStubStrategy
|
||||
private final Integer priority
|
||||
|
||||
WireMockStubStrategy(GroovyDsl groovyDsl) {
|
||||
this.wireMockRequestStubStrategy = new WireMockRequestStubStrategy(groovyDsl)
|
||||
this.wireMockResponseStubStrategy = new WireMockResponseStubStrategy(groovyDsl)
|
||||
this.priority = groovyDsl.priority
|
||||
}
|
||||
|
||||
@CompileDynamic
|
||||
String toWireMockClientStub() {
|
||||
return JsonOutput.prettyPrint(JsonOutput.toJson([request : wireMockRequestStubStrategy.buildClientRequestContent(),
|
||||
response: wireMockResponseStubStrategy.buildClientResponseContent()]))
|
||||
def wiremockStubDefinition = [request : wireMockRequestStubStrategy.buildClientRequestContent(),
|
||||
response: wireMockResponseStubStrategy.buildClientResponseContent()]
|
||||
if (priority) {
|
||||
wiremockStubDefinition.priority = priority
|
||||
}
|
||||
return JsonOutput.prettyPrint(JsonOutput.toJson(wiremockStubDefinition))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1152,6 +1152,35 @@ class WireMockGroovyDslSpec extends WireMockSpec {
|
||||
''')
|
||||
}
|
||||
|
||||
def "should generate stub with priority"() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
priority 9
|
||||
request {
|
||||
method('POST')
|
||||
url("test")
|
||||
}
|
||||
response {
|
||||
status 406
|
||||
}
|
||||
}
|
||||
when:
|
||||
def json = toWireMockClientJsonStub(groovyDsl)
|
||||
then:
|
||||
parseJson(json) == parseJson('''
|
||||
{
|
||||
"priority": 9,
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"url": "test"
|
||||
},
|
||||
"response": {
|
||||
"status": 406
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
String toJsonString(value) {
|
||||
new JsonBuilder(value).toPrettyString()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user