Merge branch 'master' into 2.0.x
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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}\")")
|
||||
}
|
||||
|
||||
@@ -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}')")
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user