-
-
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.
- Loading branch information
Alexander Zottnick
committed
Sep 19, 2016
1 parent
555c0d8
commit 7f49e74
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...umer-junit/src/test/java/au/com/dius/pact/consumer/exampleclients/ArticlesRestClient.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,16 @@ | ||
package au.com.dius.pact.consumer.exampleclients; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.fluent.Request; | ||
|
||
import java.io.IOException; | ||
|
||
public class ArticlesRestClient { | ||
|
||
public HttpResponse getArticles(String baseUrl) | ||
throws IOException { | ||
|
||
return Request.Get(baseUrl + "/articles.json") | ||
.execute().returnResponse(); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
pact-jvm-consumer-junit/src/test/java/au/com/dius/pact/consumer/examples/ArticlesTest.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,58 @@ | ||
package au.com.dius.pact.consumer.examples; | ||
|
||
import au.com.dius.pact.consumer.Pact; | ||
import au.com.dius.pact.consumer.PactProviderRule; | ||
import au.com.dius.pact.consumer.PactVerification; | ||
import au.com.dius.pact.consumer.dsl.PactDslJsonBody; | ||
import au.com.dius.pact.consumer.dsl.PactDslWithProvider; | ||
import au.com.dius.pact.consumer.exampleclients.ArticlesRestClient; | ||
import au.com.dius.pact.model.PactFragment; | ||
import org.apache.commons.collections4.MapUtils; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Example taken from https://groups.google.com/forum/#!topic/pact-support/-Kk_OxvcJQY | ||
*/ | ||
public class ArticlesTest { | ||
Map<String, String> headers = MapUtils.putAll(new HashMap<String, String>(), | ||
new String[]{"Content-Type", "application/json"}); | ||
|
||
@Rule | ||
public PactProviderRule provider = new PactProviderRule("ArticlesProvider", "localhost", 1234, this); | ||
|
||
@Pact(provider = "ArticlesProvider", consumer = "ArticlesConsumer") | ||
public PactFragment articlesFragment(PactDslWithProvider builder) { | ||
return builder | ||
.given("Pact for Issue 313") | ||
.uponReceiving("retrieving article data") | ||
.path("/articles.json") | ||
.method("GET") | ||
.willRespondWith() | ||
.headers(headers) | ||
.status(200) | ||
.body( | ||
new PactDslJsonBody() | ||
.minArrayLike("articles", 1) | ||
.object("variants") | ||
.eachKeyLike("0032") | ||
.stringType("description", "sample description") | ||
.closeObject() | ||
.closeObject() | ||
.closeObject() | ||
.closeArray() | ||
) | ||
.toFragment(); | ||
} | ||
|
||
@PactVerification("ArticlesProvider") | ||
@Test | ||
public void testArticles() throws IOException { | ||
ArticlesRestClient providerRestClient = new ArticlesRestClient(); | ||
providerRestClient.getArticles("http://localhost:1234"); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...vm-provider-junit/src/test/java/au/com/dius/pact/provider/junit/ArticlesContractTest.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,15 @@ | ||
package au.com.dius.pact.provider.junit; | ||
|
||
import au.com.dius.pact.provider.junit.loader.PactFolder; | ||
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 org.junit.runner.RunWith; | ||
|
||
@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); | ||
} |
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,12 @@ | ||
|
||
{ | ||
"articles": [ | ||
{ | ||
"variants": { | ||
"1234": { | ||
"description": "sample description" | ||
} | ||
} | ||
} | ||
] | ||
} |