Fixed wrong method delegation; fixes gh-889
This commit is contained in:
@@ -33,7 +33,9 @@ import au.com.dius.pact.model.v3.messaging.Message
|
||||
import au.com.dius.pact.model.v3.messaging.MessagePact
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.PackageScope
|
||||
|
||||
import org.springframework.cloud.contract.spec.Contract
|
||||
import org.springframework.cloud.contract.spec.internal.RegexPatterns
|
||||
import org.springframework.cloud.contract.verifier.util.JsonPaths
|
||||
import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter
|
||||
|
||||
@@ -47,6 +49,8 @@ import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter
|
||||
@PackageScope
|
||||
class MessagingSCContractCreator {
|
||||
|
||||
RegexPatterns regexPatterns = new RegexPatterns()
|
||||
|
||||
private static final String FULL_BODY = '$'
|
||||
|
||||
Collection<Contract> convertFrom(MessagePact pact) {
|
||||
@@ -104,13 +108,13 @@ class MessagingSCContractCreator {
|
||||
} else if (rule instanceof NumberTypeMatcher) {
|
||||
switch (rule.numberType) {
|
||||
case NumberTypeMatcher.NumberType.NUMBER:
|
||||
jsonPath(key, byRegex(number()))
|
||||
jsonPath(key, byRegex(regexPatterns.number()))
|
||||
break
|
||||
case NumberTypeMatcher.NumberType.INTEGER:
|
||||
jsonPath(key, byRegex(anInteger()))
|
||||
jsonPath(key, byRegex(regexPatterns.anInteger()))
|
||||
break
|
||||
case NumberTypeMatcher.NumberType.DECIMAL:
|
||||
jsonPath(key, byRegex(aDouble()))
|
||||
jsonPath(key, byRegex(regexPatterns.aDouble()))
|
||||
break
|
||||
default:
|
||||
throw new RuntimeException("Unsupported number type!")
|
||||
|
||||
@@ -37,6 +37,7 @@ class PactContractConverterSpec extends Specification {
|
||||
File pact509Json = new File(PactContractConverterSpec.getResource("/pact/pact_509.json").toURI())
|
||||
File pactv2Json = new File(PactContractConverterSpec.getResource("/pact/pact_v2.json").toURI())
|
||||
File pactv3Json = new File(PactContractConverterSpec.getResource("/pact/pact_v3.json").toURI())
|
||||
File pactv3Issue889Json = new File(PactContractConverterSpec.getResource("/pact/pact_v3_issue_889.json").toURI())
|
||||
File pactv3MessagingJson = new File(PactContractConverterSpec.getResource("/pact/pact_v3_messaging.json").toURI())
|
||||
File pactv3UnsupportedRuleLogicJson = new File(PactContractConverterSpec.getResource("/pact/pact_v3_unsupported_rule_logic.json").toURI())
|
||||
@Subject PactContractConverter converter = new PactContractConverter()
|
||||
@@ -617,6 +618,14 @@ class PactContractConverterSpec extends Specification {
|
||||
contracts == expectedContracts
|
||||
}
|
||||
|
||||
@Issue("#889")
|
||||
def "should not throw an exception when parsing Pact file with different matchers"() {
|
||||
when:
|
||||
converter.convertFrom(pactv3Issue889Json)
|
||||
then:
|
||||
noExceptionThrown()
|
||||
}
|
||||
|
||||
def "should convert from pact v3 messaging to one SC message contract"() {
|
||||
|
||||
given:
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"consumer": {
|
||||
"name": "order-manager"
|
||||
},
|
||||
"provider": {
|
||||
"name": "lineitem-worker"
|
||||
},
|
||||
"messages": [
|
||||
{
|
||||
"description": "A message sent to order-exchange",
|
||||
"metaData": {
|
||||
"sentTo": "order-exchange"
|
||||
},
|
||||
"contents": {
|
||||
"lineItemId": "string",
|
||||
"orderId": "XXX-XXXXXX-000000-0000C",
|
||||
"timestamp": 1550500138678,
|
||||
"marketId": "MRKTDE",
|
||||
"status": "PROCESSED"
|
||||
},
|
||||
"providerStates": [
|
||||
{
|
||||
"name": "statusMessageCreated()"
|
||||
}
|
||||
],
|
||||
"matchingRules": {
|
||||
"body": {
|
||||
"$.timestamp": {
|
||||
"matchers": [
|
||||
{
|
||||
"match": "number"
|
||||
}
|
||||
],
|
||||
"combine": "AND"
|
||||
},
|
||||
"$.lineItemId": {
|
||||
"matchers": [
|
||||
{
|
||||
"match": "type"
|
||||
}
|
||||
],
|
||||
"combine": "AND"
|
||||
},
|
||||
"$.orderId": {
|
||||
"matchers": [
|
||||
{
|
||||
"match": "regex",
|
||||
"regex": "[A-Z]{3}-[A-Z]{6}-[0-9]{6}-[0-9A-F]{5}"
|
||||
}
|
||||
],
|
||||
"combine": "AND"
|
||||
},
|
||||
"$.marketId": {
|
||||
"matchers": [
|
||||
{
|
||||
"match": "regex",
|
||||
"regex": "[A-Z]{6}"
|
||||
}
|
||||
],
|
||||
"combine": "AND"
|
||||
},
|
||||
"$.status": {
|
||||
"matchers": [
|
||||
{
|
||||
"match": "regex",
|
||||
"regex": "[A-Z,_]*"
|
||||
}
|
||||
],
|
||||
"combine": "AND"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"pact-specification": {
|
||||
"version": "3.0.0"
|
||||
},
|
||||
"pact-jvm": {
|
||||
"version": "3.5.13"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user