Merge branch '2.1.x'
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.contract.verifier.spec.pact
|
||||
|
||||
import java.nio.file.Files
|
||||
|
||||
import au.com.dius.pact.model.Pact
|
||||
import au.com.dius.pact.model.PactSpecVersion
|
||||
import groovy.json.JsonOutput
|
||||
@@ -25,6 +27,8 @@ import spock.lang.Specification
|
||||
import spock.lang.Subject
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.verifier.TestGenerator
|
||||
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties
|
||||
import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConverter
|
||||
import org.springframework.core.io.Resource
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver
|
||||
@@ -49,6 +53,8 @@ class PactContractConverterSpec extends Specification {
|
||||
getResource("/pact/pact_v3_messaging.json").toURI())
|
||||
File pactv3UnsupportedRuleLogicJson = new File(PactContractConverterSpec.
|
||||
getResource("/pact/pact_v3_unsupported_rule_logic.json").toURI())
|
||||
File pact1043Json = new File(PactContractConverterSpec.
|
||||
getResource("/pact/for-test-generation/pact_1043.json").toURI())
|
||||
@Subject
|
||||
PactContractConverter converter = new PactContractConverter()
|
||||
|
||||
@@ -726,6 +732,20 @@ class PactContractConverterSpec extends Specification {
|
||||
e.message.
|
||||
contains("Currently only the AND combination rule logic is supported")
|
||||
}
|
||||
|
||||
@Issue("1043")
|
||||
def "should generate a test from pact and not contain a check for an empty array"() {
|
||||
given:
|
||||
File output = Files.createTempDirectory("pact").toFile()
|
||||
output.mkdirs()
|
||||
when:
|
||||
new TestGenerator(new ContractVerifierConfigProperties(contractsDslDir: pact1043Json.parentFile, generatedTestSourcesDir: output, generatedTestResourcesDir: output, basePackageForTests: "example")).generate()
|
||||
then:
|
||||
File generatedTest = new File(output, "example/ContractVerifierTest.java")
|
||||
String generatedTestText = generatedTest.text
|
||||
!generatedTestText.contains('''assertThatJson(parsedJson).array().array("['authors']").isEmpty()''')
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
{
|
||||
"provider": {
|
||||
"name": "book-catalog-service"
|
||||
},
|
||||
"consumer": {
|
||||
"name": "books-client-catalog-rest-consumer"
|
||||
},
|
||||
"interactions": [
|
||||
{
|
||||
"description": "A successful Api GET call",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"path": "/books",
|
||||
"headers": {
|
||||
"Content-Type": "application/json;charset=UTF-8"
|
||||
}
|
||||
},
|
||||
"response": {
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"Content-Type": "application/json;charset=UTF-8"
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"isbn": "978-3-86680-192-9",
|
||||
"id": 100,
|
||||
"title": "A book",
|
||||
"authors": [
|
||||
{
|
||||
"firstName": "string",
|
||||
"lastName": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"matchingRules": {
|
||||
"body": {
|
||||
"$[0].id": {
|
||||
"matchers": [
|
||||
{
|
||||
"match": "integer"
|
||||
}
|
||||
],
|
||||
"combine": "AND"
|
||||
},
|
||||
"$[0].title": {
|
||||
"matchers": [
|
||||
{
|
||||
"match": "regex",
|
||||
"regex": ".*"
|
||||
}
|
||||
],
|
||||
"combine": "AND"
|
||||
},
|
||||
"$[0].authors[0].firstName": {
|
||||
"matchers": [
|
||||
{
|
||||
"match": "type"
|
||||
}
|
||||
],
|
||||
"combine": "AND"
|
||||
},
|
||||
"$[0].authors[0].lastName": {
|
||||
"matchers": [
|
||||
{
|
||||
"match": "type"
|
||||
}
|
||||
],
|
||||
"combine": "AND"
|
||||
},
|
||||
"$[0].isbn": {
|
||||
"matchers": [
|
||||
{
|
||||
"match": "regex",
|
||||
"regex": "[0-9]{3}-[0-9]{1}-[0-9]{5}-[0-9]{3}-[0-9]{1}"
|
||||
}
|
||||
],
|
||||
"combine": "AND"
|
||||
}
|
||||
}
|
||||
},
|
||||
"generators": {
|
||||
"body": {
|
||||
"$[0].id": {
|
||||
"type": "RandomInt",
|
||||
"min": 0,
|
||||
"max": 2147483647
|
||||
},
|
||||
"$[0].authors[0].firstName": {
|
||||
"type": "RandomString",
|
||||
"size": 20
|
||||
},
|
||||
"$[0].authors[0].lastName": {
|
||||
"type": "RandomString",
|
||||
"size": 20
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"providerStates": [
|
||||
{
|
||||
"name": "get"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"pact-specification": {
|
||||
"version": "3.0.0"
|
||||
},
|
||||
"pact-jvm": {
|
||||
"version": "3.5.13"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user