diff --git a/pact-jvm-consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslJsonBody.java b/pact-jvm-consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslJsonBody.java index d5617a07c9..8619aec27e 100644 --- a/pact-jvm-consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslJsonBody.java +++ b/pact-jvm-consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslJsonBody.java @@ -881,7 +881,7 @@ public PactDslJsonBody eachKeyMappedToAnArrayLike(String exampleKey) { * @param exampleKey Example key to use for generating bodies */ public PactDslJsonBody eachKeyLike(String exampleKey) { - matchers.put(".*", matchType()); + matchers.put(rootPath + "*", matchType()); return new PactDslJsonBody(rootPath + "*.", exampleKey, this); } diff --git a/pact-jvm-provider-junit/src/main/java/au/com/dius/pact/provider/junit/loader/VersionedPactUrl.java b/pact-jvm-provider-junit/src/main/java/au/com/dius/pact/provider/junit/loader/VersionedPactUrl.java index 6cc561fb42..89189c09b7 100644 --- a/pact-jvm-provider-junit/src/main/java/au/com/dius/pact/provider/junit/loader/VersionedPactUrl.java +++ b/pact-jvm-provider-junit/src/main/java/au/com/dius/pact/provider/junit/loader/VersionedPactUrl.java @@ -16,11 +16,9 @@ * For example, when you annotate a provider test class with: *
{@literal @}VersionedPactUrl(urls = {"http://artifactory:8081/artifactory/consumercontracts/foo-bar/${foo.version}/foo-bar-${foo.version}.json"})
* And pass a system property foo.version to the JVM, for example -Dfoo.version=123 - *

*

* Then the pact tests will fetch the following contract: *

http://artifactory:8081/artifactory/consumercontracts/foo-bar/123/foo-bar-123.json
- *

* * @see VersionedPactUrlLoader pact loader */ diff --git a/pact-jvm-provider-junit/src/test/java/au/com/dius/pact/provider/junit/ArticlesContractTest.java b/pact-jvm-provider-junit/src/test/java/au/com/dius/pact/provider/junit/ArticlesContractTest.java index a9cbeb01f6..ec8de7f000 100644 --- a/pact-jvm-provider-junit/src/test/java/au/com/dius/pact/provider/junit/ArticlesContractTest.java +++ b/pact-jvm-provider-junit/src/test/java/au/com/dius/pact/provider/junit/ArticlesContractTest.java @@ -4,12 +4,34 @@ import au.com.dius.pact.provider.junit.target.HttpTarget; import au.com.dius.pact.provider.junit.target.Target; import au.com.dius.pact.provider.junit.target.TestTarget; +import com.github.restdriver.clientdriver.ClientDriverRule; +import org.apache.commons.io.IOUtils; +import org.junit.Before; +import org.junit.ClassRule; import org.junit.runner.RunWith; +import java.io.IOException; +import java.nio.charset.Charset; + +import static com.github.restdriver.clientdriver.RestClientDriver.giveEmptyResponse; +import static com.github.restdriver.clientdriver.RestClientDriver.giveResponse; +import static com.github.restdriver.clientdriver.RestClientDriver.onRequestTo; + @RunWith(PactRunner.class) @Provider("ArticlesProvider") @PactFolder("../pact-jvm-consumer-junit/build/2.11/pacts") public class ArticlesContractTest { - @TestTarget - public final Target target = new HttpTarget(8000); + @TestTarget + public final Target target = new HttpTarget(8000); + + @ClassRule + public static final ClientDriverRule embeddedService = new ClientDriverRule(8000); + + @Before + public void before() throws IOException { + String json = IOUtils.toString(getClass().getResourceAsStream("/articles.json"), Charset.defaultCharset()); + embeddedService.addExpectation( + onRequestTo("/articles.json"), giveResponse(json, "application/json") + ); + } }