diff --git a/consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/ArrayUnorderedTest.java b/consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/ArrayUnorderedTest.java new file mode 100644 index 000000000..d0afd6643 --- /dev/null +++ b/consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/ArrayUnorderedTest.java @@ -0,0 +1,47 @@ +package au.com.dius.pact.consumer.junit5; + +import au.com.dius.pact.consumer.MockServer; +import au.com.dius.pact.consumer.dsl.PactDslWithProvider; +import au.com.dius.pact.core.model.PactSpecVersion; +import au.com.dius.pact.core.model.RequestResponsePact; +import au.com.dius.pact.core.model.annotations.Pact; +import org.apache.hc.client5.http.fluent.Request; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpResponse; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.io.IOException; + +import static au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonArrayUnordered; +import static org.junit.jupiter.api.Assertions.assertEquals; + +@ExtendWith(PactConsumerTestExt.class) +public class ArrayUnorderedTest { + @Test + @PactTestFor( + providerName = "PactProvider", + pactMethod = "pactPassIdArray", + pactVersion = PactSpecVersion.V3) + void testContract(MockServer mockServer) throws IOException { + HttpResponse response = Request.post(mockServer.getUrl() + "/passIdArray") + .bodyString("[{\"id\":\"123\"}]", ContentType.APPLICATION_JSON).execute().returnResponse(); + assertEquals(response.getCode(), 200); + } + + @Pact(consumer = "PactConsumer") + RequestResponsePact pactPassIdArray(PactDslWithProvider provider) { + return provider + .uponReceiving("publish entity") + .path("/passIdArray") + .method("POST") + .body( + newJsonArrayUnordered(refs -> + refs.object(ref -> ref.stringType("id", "123")) + ).build() + ) + .willRespondWith() + .status(200) + .toPact(); + } +} diff --git a/consumer/src/main/kotlin/au/com/dius/pact/consumer/MockHttpServer.kt b/consumer/src/main/kotlin/au/com/dius/pact/consumer/MockHttpServer.kt index 840cad86e..22a90d612 100755 --- a/consumer/src/main/kotlin/au/com/dius/pact/consumer/MockHttpServer.kt +++ b/consumer/src/main/kotlin/au/com/dius/pact/consumer/MockHttpServer.kt @@ -197,6 +197,7 @@ abstract class BaseMockServer(val pact: BasePact, val config: MockProviderConfig ), GeneratorTestMode.Consumer) } is PartialRequestMatch -> { + logger.error { "PartialRequestMatch: ${matchResult.description()}" } val interaction = matchResult.problems.keys.first().asSynchronousRequestResponse()!! mismatchedRequests.putIfAbsent(interaction.request, mutableListOf()) mismatchedRequests[interaction.request]?.add(PactVerificationResult.PartialMismatch( 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 b12886960..e327fe360 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 @@ -499,7 +499,6 @@ data class ContentTypeMatcher(val contentType: String) : MatchingRule { */ object EqualsIgnoreOrderMatcher : MatchingRule { override fun toMap(spec: PactSpecVersion) = mapOf("match" to "ignore-order") - override fun canMatch(contentType: ContentType) = true override fun validateForVersion(pactVersion: PactSpecVersion): List { return if (pactVersion < PactSpecVersion.V4) { listOf("Ignore Order matchers can only be used with Pact specification versions >= V4") @@ -521,7 +520,6 @@ object EqualsIgnoreOrderMatcher : MatchingRule { */ data class MinEqualsIgnoreOrderMatcher(val min: Int) : MatchingRule { override fun toMap(spec: PactSpecVersion) = mapOf("match" to "ignore-order", "min" to min) - override fun canMatch(contentType: ContentType) = true override fun validateForVersion(pactVersion: PactSpecVersion): List { return if (pactVersion < PactSpecVersion.V4) { listOf("Ignore Order matchers can only be used with Pact specification versions >= V4") @@ -543,7 +541,6 @@ data class MinEqualsIgnoreOrderMatcher(val min: Int) : MatchingRule { */ data class MaxEqualsIgnoreOrderMatcher(val max: Int) : MatchingRule { override fun toMap(spec: PactSpecVersion) = mapOf("match" to "ignore-order", "max" to max) - override fun canMatch(contentType: ContentType) = true override fun validateForVersion(pactVersion: PactSpecVersion): List { return if (pactVersion < PactSpecVersion.V4) { listOf("Ignore Order matchers can only be used with Pact specification versions >= V4") @@ -565,7 +562,6 @@ data class MaxEqualsIgnoreOrderMatcher(val max: Int) : MatchingRule { */ data class MinMaxEqualsIgnoreOrderMatcher(val min: Int, val max: Int) : MatchingRule { override fun toMap(spec: PactSpecVersion) = mapOf("match" to "ignore-order", "min" to min, "max" to max) - override fun canMatch(contentType: ContentType) = true override fun validateForVersion(pactVersion: PactSpecVersion): List { return if (pactVersion < PactSpecVersion.V4) { listOf("Ignore Order matchers can only be used with Pact specification versions >= V4")