-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(regression): HTTP Pact with root json array fails when using unor…
…dered array matching #1631
- Loading branch information
1 parent
be8d57d
commit 639f7f8
Showing
3 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/ArrayUnorderedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters