Merge pull request #130 from adam-wojszczyk/issues/127-better-naming-for-server/client-definition
[#127] Add stub as an alias for client and test as an alias for server
This commit is contained in:
@@ -78,10 +78,18 @@ class Common {
|
||||
return new ClientDslProperty(clientValue)
|
||||
}
|
||||
|
||||
ClientDslProperty stub(Object clientValue) {
|
||||
return new ClientDslProperty(clientValue)
|
||||
}
|
||||
|
||||
ServerDslProperty server(Object serverValue) {
|
||||
return new ServerDslProperty(serverValue)
|
||||
}
|
||||
|
||||
ServerDslProperty test(Object serverValue) {
|
||||
return new ServerDslProperty(serverValue)
|
||||
}
|
||||
|
||||
void assertThatSidesMatch(Pattern pattern, String value) {
|
||||
assert value ==~ pattern
|
||||
}
|
||||
|
||||
@@ -329,6 +329,37 @@ class MockMvcSpockMethodBuilderSpec extends Specification {
|
||||
spockTest.contains('responseBody == "test"')
|
||||
}
|
||||
|
||||
@Issue("#127")
|
||||
def 'should use "stub" as an alias for "client"'() {
|
||||
given:
|
||||
GroovyDsl contractDsl = GroovyDsl.make {
|
||||
request {
|
||||
method "GET"
|
||||
url "test"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
body(
|
||||
property: value(
|
||||
stub(123),
|
||||
test(123)
|
||||
)
|
||||
)
|
||||
headers {
|
||||
header('Content-Type': 'application/json')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
MockMvcSpockMethodBodyBuilder builder = new MockMvcSpockMethodBodyBuilder(contractDsl)
|
||||
BlockBuilder blockBuilder = new BlockBuilder(" ")
|
||||
when:
|
||||
builder.appendTo(blockBuilder)
|
||||
then:
|
||||
blockBuilder.toString().contains("responseBody.property == 123")
|
||||
}
|
||||
|
||||
@Issue('113')
|
||||
def "should generate regex test for String in response header"() {
|
||||
given:
|
||||
|
||||
@@ -1181,6 +1181,42 @@ class WireMockGroovyDslSpec extends WireMockSpec {
|
||||
''')
|
||||
}
|
||||
|
||||
@Issue("#127")
|
||||
def 'should use "test" as an alias for "server"'() {
|
||||
given:
|
||||
GroovyDsl groovyDsl = GroovyDsl.make {
|
||||
request {
|
||||
method('POST')
|
||||
body(
|
||||
property: value(stub("value"), test("value"))
|
||||
)
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
when:
|
||||
String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub()
|
||||
then:
|
||||
new JsonSlurper().parseText(wireMockStub) == new JsonSlurper().parseText('''
|
||||
{
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"bodyPatterns": [
|
||||
{
|
||||
"equalToJson": "{\\"property\\":\\"value\\"}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"response": {
|
||||
"status": 200
|
||||
}
|
||||
}
|
||||
''')
|
||||
and:
|
||||
stubMappingIsValidWireMockStub(wireMockStub)
|
||||
}
|
||||
|
||||
@Issue("#121")
|
||||
def 'should generate stub with empty list as a value of a field'() {
|
||||
given:
|
||||
|
||||
Reference in New Issue
Block a user