Merge branch 'master' into 2.0.x

This commit is contained in:
Marcin Grzejszczak
2017-09-30 19:15:14 +02:00
8 changed files with 112 additions and 3 deletions

View File

@@ -15,7 +15,7 @@
<description>Spring Cloud Contract Dependencies</description>
<properties>
<wiremock.version>2.8.0</wiremock.version>
<jsonassert.version>0.4.9</jsonassert.version>
<jsonassert.version>0.4.10</jsonassert.version>
<aether.version>1.0.2.v20150114</aether.version>
</properties>
<dependencyManagement>

View File

@@ -63,7 +63,7 @@
<dependency>
<groupId>com.toomuchcoding.jsonassert</groupId>
<artifactId>jsonassert</artifactId>
<version>0.4.9</version>
<version>0.4.10</version>
<scope>test</scope>
</dependency>
<dependency>

View File

@@ -62,7 +62,7 @@
<dependency>
<groupId>com.toomuchcoding.jsonassert</groupId>
<artifactId>jsonassert</artifactId>
<version>0.4.9</version>
<version>0.4.10</version>
<scope>test</scope>
</dependency>
<dependency>

View File

@@ -115,6 +115,9 @@ class JaxRsClientJUnitMethodBodyBuilder extends JUnitMethodBodyBuilder {
protected appendHeaders(BlockBuilder bb) {
request.headers?.executeForEachHeader { Header header ->
if (headerOfAbsentType(header)) {
return
}
if (header.name == 'Content-Type' || header.name == 'Accept') return
bb.addLine(".header(\"${header.name}\", \"${header.serverValue}\")")
}

View File

@@ -120,6 +120,9 @@ class JaxRsClientSpockMethodRequestProcessingBodyBuilder extends SpockMethodRequ
protected appendHeaders(BlockBuilder bb) {
request.headers?.executeForEachHeader { Header header ->
if (headerOfAbsentType(header)) {
return
}
if (header.name == 'Content-Type' || header.name == 'Accept') return // Particular headers are set via 'request' / 'entity' methods
bb.addLine(".header('${header.name}', '${header.serverValue}')")
}

View File

@@ -95,6 +95,9 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder {
@Override
protected void processInput(BlockBuilder bb) {
request.headers?.executeForEachHeader { Header header ->
if (headerOfAbsentType(header)) {
return
}
bb.addLine(getHeaderString(header))
}
if (request.body) {
@@ -107,6 +110,11 @@ abstract class RequestProcessingMethodBodyBuilder extends MethodBodyBuilder {
}
}
protected boolean headerOfAbsentType(Header header) {
return header.serverValue instanceof MatchingStrategy &&
((MatchingStrategy) header.serverValue).type == MatchingStrategy.Type.ABSENT
}
@Override
protected void when(BlockBuilder bb) {
bb.addLine(getInputString(request))

View File

@@ -315,6 +315,39 @@ DocumentContext parsedJson = JsonPath.parse(json);
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
}
@Issue("#424")
def "should not put an absent header to the request [#methodBuilderName]"() {
given:
Contract contractDsl = Contract.make {
request {
method 'GET'
url '/mytest'
headers {
header('myheader', absent())
}
}
response {
status 200
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
then:
!blockBuilder.toString().contains("myheader")
and:
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, blockBuilder.toString())
and:
stubMappingIsValidWireMockStub(contractDsl)
where:
methodBuilderName | methodBuilder
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
}
def "should use fixed delay milliseconds in the generated test [#methodBuilderName]"() {
given:
Contract contractDsl = Contract.make {

View File

@@ -1880,7 +1880,69 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie
''', wireMockStub)
and:
stubMappingIsValidWireMockStub(wireMockStub)
}
@Issue('#427')
def "should not fail to generate a stub when arrays are there in the request"() {
given:
Contract groovyDsl = Contract.make {
request {
method "POST"
urlPath('/batch/persons')
body("""
[{
"fruitsILike": [
"apple"
]
},
{
"fruitsILike": [
]
},
{
"fruitsILike": [
"orange"
]
}]
""")
}
response {
status 201
headers {
contentType(applicationJsonUtf8())
}
body("""{
"id": "foo"
}"
""")
}
}
when:
String wireMockStub = new WireMockStubStrategy("Test", new ContractMetadata(null, false, 0, null, groovyDsl), groovyDsl).toWireMockClientStub()
then:
AssertionUtil.assertThatJsonsAreEqual('''
{
"request" : {
"urlPath" : "/batch/persons",
"method" : "POST",
"bodyPatterns" : [ {
"matchesJsonPath" : "$[*].['fruitsILike'][?(@ == 'orange')]"
}, {
"matchesJsonPath" : "$[*].['fruitsILike'][?(@ == 'apple')]"
} ]
},
"response" : {
"status" : 201,
"body" : "{\\"id\\":\\"foo\\"}",
"headers" : {
"Content-Type" : "application/json;charset=UTF-8"
},
"transformers" : [ "response-template" ]
}
}
''', wireMockStub)
and:
stubMappingIsValidWireMockStub(wireMockStub)
}
@Issue('#385')