diff --git a/consumer/groovy/src/test/groovy/au/com/dius/pact/consumer/groovy/MatchersSpec.groovy b/consumer/groovy/src/test/groovy/au/com/dius/pact/consumer/groovy/MatchersSpec.groovy index d1af2532bb..119d5fb092 100644 --- a/consumer/groovy/src/test/groovy/au/com/dius/pact/consumer/groovy/MatchersSpec.groovy +++ b/consumer/groovy/src/test/groovy/au/com/dius/pact/consumer/groovy/MatchersSpec.groovy @@ -24,10 +24,10 @@ class MatchersSpec extends Specification { 'regexp' | '[0-9]+' | [match: 'regex', regex: '[0-9]+'] 'hexValue' | '1234' | [match: 'regex', regex: '[0-9a-fA-F]+'] 'ipAddress' | '1.2.3.4' | [match: 'regex', regex: '(\\d{1,3}\\.)+\\d{1,3}'] - 'timestamp' | 'yyyy-mm-dd' | [match: 'timestamp', timestamp: 'yyyy-mm-dd'] - 'datetime' | 'yyyy-mm-dd' | [match: 'timestamp', timestamp: 'yyyy-mm-dd'] - 'date' | 'yyyy-mm-dd' | [match: 'date', date: 'yyyy-mm-dd'] - 'time' | 'yyyy-mm-dd' | [match: 'time', time: 'yyyy-mm-dd'] + 'timestamp' | 'yyyy-mm-dd' | [match: 'timestamp', format: 'yyyy-mm-dd'] + 'datetime' | 'yyyy-mm-dd' | [match: 'timestamp', format: 'yyyy-mm-dd'] + 'date' | 'yyyy-mm-dd' | [match: 'date', format: 'yyyy-mm-dd'] + 'time' | 'yyyy-mm-dd' | [match: 'time', format: 'yyyy-mm-dd'] 'uuid' | '12345678-1234-1234-1234-123456789012' | [match: 'regex', regex: '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'] 'equalTo' | 'value' | [match: 'equality'] 'includesStr' | 'value' | [match: 'include', value: 'value'] diff --git a/consumer/java8/src/test/groovy/io/pactfoundation/consumer/dsl/LambdaDslSpec.groovy b/consumer/java8/src/test/groovy/io/pactfoundation/consumer/dsl/LambdaDslSpec.groovy index 9c357552b5..2737029c52 100644 --- a/consumer/java8/src/test/groovy/io/pactfoundation/consumer/dsl/LambdaDslSpec.groovy +++ b/consumer/java8/src/test/groovy/io/pactfoundation/consumer/dsl/LambdaDslSpec.groovy @@ -153,9 +153,9 @@ class LambdaDslSpec extends Specification { then: result.matchers.toMap(PactSpecVersion.V3) == [ - '.dateExp': [matchers: [[match: 'date', date: 'yyyy-MM-dd']], combine: 'AND'], - '.timeExp': [matchers: [[match: 'time', time: 'HH:mm:ss']], combine: 'AND'], - '.datetimeExp': [matchers: [[match: 'timestamp', timestamp: "yyyy-MM-dd'T'HH:mm:ss"]], combine: 'AND'] + '.dateExp': [matchers: [[match: 'date', format: 'yyyy-MM-dd']], combine: 'AND'], + '.timeExp': [matchers: [[match: 'time', format: 'HH:mm:ss']], combine: 'AND'], + '.datetimeExp': [matchers: [[match: 'timestamp', format: "yyyy-MM-dd'T'HH:mm:ss"]], combine: 'AND'] ] result.generators.toMap(PactSpecVersion.V3) == [ body: [ @@ -179,9 +179,9 @@ class LambdaDslSpec extends Specification { then: result.matchers.toMap(PactSpecVersion.V3) == [ - '[0]': [matchers: [[match: 'date', date: 'yyyy-MM-dd']], combine: 'AND'], - '[1]': [matchers: [[match: 'time', time: 'HH:mm:ss']], combine: 'AND'], - '[2]': [matchers: [[match: 'timestamp', timestamp: "yyyy-MM-dd'T'HH:mm:ss"]], combine: 'AND'] + '[0]': [matchers: [[match: 'date', format: 'yyyy-MM-dd']], combine: 'AND'], + '[1]': [matchers: [[match: 'time', format: 'HH:mm:ss']], combine: 'AND'], + '[2]': [matchers: [[match: 'timestamp', format: "yyyy-MM-dd'T'HH:mm:ss"]], combine: 'AND'] ] result.generators.toMap(PactSpecVersion.V3) == [ diff --git a/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/DslPartSpec.groovy b/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/DslPartSpec.groovy index ead6fedfc6..30aa39b8d7 100644 --- a/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/DslPartSpec.groovy +++ b/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/DslPartSpec.groovy @@ -200,9 +200,9 @@ class DslPartSpec extends Specification { matcherMethod | param | matcherDefinition 'regexp' | '[0-9]+' | [match: 'regex', regex: '[0-9]+'] - 'matchTimestamp' | 'yyyy-mm-dd' | [match: 'timestamp', timestamp: 'yyyy-mm-dd'] - 'matchDate' | 'yyyy-mm-dd' | [match: 'date', date: 'yyyy-mm-dd'] - 'matchTime' | 'yyyy-mm-dd' | [match: 'time', time: 'yyyy-mm-dd'] + 'matchTimestamp' | 'yyyy-mm-dd' | [match: 'timestamp', format: 'yyyy-mm-dd'] + 'matchDate' | 'yyyy-mm-dd' | [match: 'date', format: 'yyyy-mm-dd'] + 'matchTime' | 'yyyy-mm-dd' | [match: 'time', format: 'yyyy-mm-dd'] 'matchMin' | 1 | [match: 'type', min: 1] 'matchMax' | 1 | [match: 'type', max: 1] 'includesMatcher' | 1 | [match: 'include', value: '1'] diff --git a/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonArraySpec.groovy b/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonArraySpec.groovy index 5b5fdcf4e4..e27c28f014 100644 --- a/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonArraySpec.groovy +++ b/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonArraySpec.groovy @@ -224,9 +224,9 @@ class PactDslJsonArraySpec extends Specification { expect: body.matchers.toMap(PactSpecVersion.V3) == [ - '$[0]': [matchers: [[match: 'date', date: 'yyyy-MM-dd']], combine: 'AND'], - '$[1]': [matchers: [[match: 'time', time: 'HH:mm:ss']], combine: 'AND'], - '$[2]': [matchers: [[match: 'timestamp', timestamp: "yyyy-MM-dd'T'HH:mm:ss"]], combine: 'AND']] + '$[0]': [matchers: [[match: 'date', format: 'yyyy-MM-dd']], combine: 'AND'], + '$[1]': [matchers: [[match: 'time', format: 'HH:mm:ss']], combine: 'AND'], + '$[2]': [matchers: [[match: 'timestamp', format: "yyyy-MM-dd'T'HH:mm:ss"]], combine: 'AND']] body.generators.toMap(PactSpecVersion.V3) == [body: [ '$[0]': [type: 'Date', format: 'yyyy-MM-dd', expression: 'today + 1 day'], diff --git a/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonBodySpec.groovy b/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonBodySpec.groovy index a3ad8dddd2..f91efd9e23 100644 --- a/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonBodySpec.groovy +++ b/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonBodySpec.groovy @@ -364,9 +364,9 @@ class PactDslJsonBodySpec extends Specification { expect: body.matchers.toMap(PactSpecVersion.V3) == [ - '$.dateExp': [matchers: [[match: 'date', date: 'yyyy-MM-dd']], combine: 'AND'], - '$.timeExp': [matchers: [[match: 'time', time: 'HH:mm:ss']], combine: 'AND'], - '$.datetimeExp': [matchers: [[match: 'timestamp', timestamp: "yyyy-MM-dd'T'HH:mm:ss"]], combine: 'AND']] + '$.dateExp': [matchers: [[match: 'date', format: 'yyyy-MM-dd']], combine: 'AND'], + '$.timeExp': [matchers: [[match: 'time', format: 'HH:mm:ss']], combine: 'AND'], + '$.datetimeExp': [matchers: [[match: 'timestamp', format: "yyyy-MM-dd'T'HH:mm:ss"]], combine: 'AND']] body.generators.toMap(PactSpecVersion.V3) == [body: [ '$.dateExp': [type: 'Date', format: 'yyyy-MM-dd', expression: 'today + 1 day'], diff --git a/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonRootValueSpec.groovy b/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonRootValueSpec.groovy index c928bfaf05..fbdfc949f8 100644 --- a/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonRootValueSpec.groovy +++ b/consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonRootValueSpec.groovy @@ -40,16 +40,16 @@ class PactDslJsonRootValueSpec extends Specification { def datetime = PactDslJsonRootValue.datetimeExpression('today + 1 hour') expect: - date.matchers.toMap(PactSpecVersion.V3) == [matchers: [[match: 'date', date: 'yyyy-MM-dd']], combine: 'AND'] + date.matchers.toMap(PactSpecVersion.V3) == [matchers: [[match: 'date', format: 'yyyy-MM-dd']], combine: 'AND'] date.generators.toMap(PactSpecVersion.V3) == [body: [ '': [type: 'Date', format: 'yyyy-MM-dd', expression: 'today + 1 day']]] - time.matchers.toMap(PactSpecVersion.V3) == [matchers: [[match: 'time', time: 'HH:mm:ss']], combine: 'AND'] + time.matchers.toMap(PactSpecVersion.V3) == [matchers: [[match: 'time', format: 'HH:mm:ss']], combine: 'AND'] time.generators.toMap(PactSpecVersion.V3) == [body: [ '': [type: 'Time', format: 'HH:mm:ss', expression: 'now + 1 hour']]] datetime.matchers.toMap(PactSpecVersion.V3) == [matchers: [[ - match: 'timestamp', timestamp: "yyyy-MM-dd'T'HH:mm:ss"]], combine: 'AND'] + match: 'timestamp', format: "yyyy-MM-dd'T'HH:mm:ss"]], combine: 'AND'] datetime.generators.toMap(PactSpecVersion.V3) == [body: [ '': [type: 'DateTime', format: 'yyyy-MM-dd\'T\'HH:mm:ss', expression: 'today + 1 hour']]] } diff --git a/core/model/src/main/kotlin/au/com/dius/pact/core/model/matchingrules/MatchingRules.kt b/core/model/src/main/kotlin/au/com/dius/pact/core/model/matchingrules/MatchingRules.kt index a6adb6bf5a..5bb1db0eb7 100644 --- a/core/model/src/main/kotlin/au/com/dius/pact/core/model/matchingrules/MatchingRules.kt +++ b/core/model/src/main/kotlin/au/com/dius/pact/core/model/matchingrules/MatchingRules.kt @@ -111,7 +111,7 @@ interface MatchingRule { * Matching Rule for dates */ data class DateMatcher @JvmOverloads constructor(val format: String = "yyyy-MM-dd") : MatchingRule { - override fun toMap(spec: PactSpecVersion) = mapOf("match" to "date", "date" to format) + override fun toMap(spec: PactSpecVersion) = mapOf("match" to "date", "format" to format) } /** @@ -179,14 +179,14 @@ data class RegexMatcher @JvmOverloads constructor (val regex: String, val exampl * Matcher for time values */ data class TimeMatcher @JvmOverloads constructor(val format: String = "HH:mm:ss") : MatchingRule { - override fun toMap(spec: PactSpecVersion) = mapOf("match" to "time", "time" to format) + override fun toMap(spec: PactSpecVersion) = mapOf("match" to "time", "format" to format) } /** * Matcher for time values */ data class TimestampMatcher @JvmOverloads constructor(val format: String = "yyyy-MM-dd HH:mm:ssZZZZZ") : MatchingRule { - override fun toMap(spec: PactSpecVersion) = mapOf("match" to "timestamp", "timestamp" to format) + override fun toMap(spec: PactSpecVersion) = mapOf("match" to "timestamp", "format" to format) } /** diff --git a/core/model/src/test/groovy/au/com/dius/pact/core/model/matchingrules/MatchingRuleGroupSpec.groovy b/core/model/src/test/groovy/au/com/dius/pact/core/model/matchingrules/MatchingRuleGroupSpec.groovy index b4428d71d5..95ca198f70 100644 --- a/core/model/src/test/groovy/au/com/dius/pact/core/model/matchingrules/MatchingRuleGroupSpec.groovy +++ b/core/model/src/test/groovy/au/com/dius/pact/core/model/matchingrules/MatchingRuleGroupSpec.groovy @@ -77,9 +77,9 @@ class MatchingRuleGroupSpec extends Specification { new MinTypeMatcher(1) | [match: 'type', min: 1] new MaxTypeMatcher(1) | [match: 'type', max: 1] new MinMaxTypeMatcher(2, 3) | [match: 'type', max: 3, min: 2] - new TimestampMatcher() | [match: 'timestamp', timestamp: 'yyyy-MM-dd HH:mm:ssZZZZZ'] - new TimeMatcher() | [match: 'time', time: 'HH:mm:ss'] - new DateMatcher() | [match: 'date', date: 'yyyy-MM-dd'] + new TimestampMatcher() | [match: 'timestamp', format: 'yyyy-MM-dd HH:mm:ssZZZZZ'] + new TimeMatcher() | [match: 'time', format: 'HH:mm:ss'] + new DateMatcher() | [match: 'date', format: 'yyyy-MM-dd'] new IncludeMatcher('A') | [match: 'include', value: 'A'] ValuesMatcher.INSTANCE | [match: 'values'] NullMatcher.INSTANCE | [match: 'null'] diff --git a/core/model/src/test/groovy/au/com/dius/pact/core/model/matchingrules/MatchingRulesSpec.groovy b/core/model/src/test/groovy/au/com/dius/pact/core/model/matchingrules/MatchingRulesSpec.groovy index f81f27b318..824c80777b 100644 --- a/core/model/src/test/groovy/au/com/dius/pact/core/model/matchingrules/MatchingRulesSpec.groovy +++ b/core/model/src/test/groovy/au/com/dius/pact/core/model/matchingrules/MatchingRulesSpec.groovy @@ -1,5 +1,6 @@ package au.com.dius.pact.core.model.matchingrules +import au.com.dius.pact.core.model.PactSpecVersion import au.com.dius.pact.core.support.Json import au.com.dius.pact.core.support.json.JsonValue import spock.lang.Issue @@ -236,4 +237,14 @@ class MatchingRulesSpec extends Specification { [match: 'time', time: 'HH:mm'] | new TimeMatcher('HH:mm') [match: 'time', format: 'HH:mm'] | new TimeMatcher('HH:mm') } + + def 'date/time matcher to json'() { + expect: + new TimestampMatcher().toMap(PactSpecVersion.V3) == [match: 'timestamp', format: 'yyyy-MM-dd HH:mm:ssZZZZZ'] + new TimestampMatcher('yyyy').toMap(PactSpecVersion.V3) == [match: 'timestamp', format: 'yyyy'] + new DateMatcher().toMap(PactSpecVersion.V3) == [match: 'date', format: 'yyyy-MM-dd'] + new DateMatcher('yyyy').toMap(PactSpecVersion.V3) == [match: 'date', format: 'yyyy'] + new TimeMatcher().toMap(PactSpecVersion.V3) == [match: 'time', format: 'HH:mm:ss'] + new TimeMatcher('hh').toMap(PactSpecVersion.V3) == [match: 'time', format: 'hh'] + } }