[#5] Simplify tests for Response
This commit is contained in:
@@ -14,13 +14,21 @@ class WiremockResponseStubStrategy extends BaseWiremockStubStrategy {
|
||||
}
|
||||
|
||||
String toWiremockClientStub() {
|
||||
return JsonOutput.toJson(buildClientRequest(response))
|
||||
return JsonOutput.toJson(buildClientResponse(response))
|
||||
}
|
||||
|
||||
private Map buildClientRequest(Response response) {
|
||||
private Map buildClientResponse(Response response) {
|
||||
return getResponseSection(response, { "TODO" }, { buildClientHeadersSection(response.headers) })
|
||||
}
|
||||
|
||||
String toWiremockServerStub() {
|
||||
return JsonOutput.toJson(buildServerResponse(response))
|
||||
}
|
||||
|
||||
private Map buildServerResponse(Response response) {
|
||||
return getResponseSection(response, { "TODO" }, { buildServerHeadersSection(response.headers) })
|
||||
}
|
||||
|
||||
private Map<String, Map<String, Object>> getResponseSection(Response response, Closure<String> buildUrlPattern, Closure<Map> buildHeaders) {
|
||||
return [response: [status : response.status,
|
||||
headers: buildHeaders()]
|
||||
|
||||
@@ -3,11 +3,12 @@ package io.codearte.accurest.dsl
|
||||
import groovy.json.JsonSlurper
|
||||
import io.coderate.accurest.dsl.GroovyDsl
|
||||
import io.coderate.accurest.dsl.WiremockResponseStubStrategy
|
||||
import spock.lang.Ignore
|
||||
import spock.lang.Specification
|
||||
|
||||
class WiremockGroovyDslResponseSpec extends Specification {
|
||||
|
||||
def 'should generate response without body for client side'() {
|
||||
def 'should generate response without body for #side side'() {
|
||||
given:
|
||||
GroovyDsl dsl = GroovyDsl.make {
|
||||
response {
|
||||
@@ -15,15 +16,26 @@ class WiremockGroovyDslResponseSpec extends Specification {
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockResponseStubStrategy(dsl).toWiremockClientStub()
|
||||
String wiremockStub = new WiremockResponseStubStrategy(dsl)."toWiremock${side}Stub"()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText(expectedStub)
|
||||
where:
|
||||
side << ['Client', 'Server']
|
||||
expectedStub << ['''
|
||||
{
|
||||
"response": {
|
||||
"status": 200
|
||||
}
|
||||
}
|
||||
''')
|
||||
''',
|
||||
|
||||
'''
|
||||
{
|
||||
"response": {
|
||||
"status": 200
|
||||
}
|
||||
}
|
||||
''']
|
||||
}
|
||||
|
||||
def 'should generate headers for response for client side'() {
|
||||
@@ -52,4 +64,30 @@ class WiremockGroovyDslResponseSpec extends Specification {
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
@Ignore("Not implemented yet")
|
||||
def 'should generate headers for response for server side'() {
|
||||
given:
|
||||
GroovyDsl dsl = GroovyDsl.make {
|
||||
response {
|
||||
status 200
|
||||
headers {
|
||||
header('Content-Type').equalTo('text/xml')
|
||||
}
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wiremockStub = new WiremockResponseStubStrategy(dsl).toWiremockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wiremockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers":
|
||||
"Content-Type": "text/xml"
|
||||
}
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,5 +266,9 @@ class WiremockGroovyDslSpec extends Specification {
|
||||
''')
|
||||
}
|
||||
|
||||
@Ignore("Not implemented yet")
|
||||
def "should generate stub with request body matching for server side"() {}
|
||||
|
||||
@Ignore("Not implemented yet")
|
||||
def "should generate stub with request query parameter matching for server side"() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user