Skip to content

Commit 8b7cc5a

Browse files
author
Ronald Holshausen
committed
add a second interaction to the example junit test
1 parent a46937a commit 8b7cc5a

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

pact-jvm-consumer-junit/src/main/java/au/com/dius/pact/consumer/ConsumerPactBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public PactFragment toFragment() {
189189
JavaConverters$.MODULE$.asScalaBufferConverter(existing.interactions).asScala());
190190
}
191191

192-
public PactDslRequestWithPath uponRecieving(String description) {
192+
public PactDslRequestWithPath uponReceiving(String description) {
193193
addInteraction();
194194
return new PactDslRequestWithPath(existing, description);
195195
}

pact-jvm-consumer-junit/src/test/java/au/com/dius/pact/consumer/ConsumerClient.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package au.com.dius.pact.consumer;
22

3-
43
import org.apache.http.client.fluent.Request;
54

65
import java.io.IOException;
@@ -13,6 +12,14 @@ public ConsumerClient(String url) {
1312
}
1413

1514
public String get(String path) throws IOException {
16-
return Request.Get(url + path).execute().returnContent().asString();
15+
return Request.Get(url + path)
16+
.addHeader("testreqheader", "testreqheadervalue")
17+
.execute().returnContent().asString();
18+
}
19+
20+
public int options(String path) throws IOException {
21+
return Request.Options(url + path)
22+
.addHeader("testreqheader", "testreqheadervalue")
23+
.execute().returnResponse().getStatusLine().getStatusCode();
1724
}
1825
}

pact-jvm-consumer-junit/src/test/java/au/com/dius/pact/consumer/ExampleJavaConsumerPactTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@ protected PactFragment createFragment(ConsumerPactBuilder.PactDslWithProvider bu
1919
.path("/")
2020
.method("GET")
2121
.headers(headers)
22-
.body("{\"test\":true}")
22+
.body("")
2323
.willRespondWith()
2424
.status(200)
2525
.headers(headers)
26-
.body("{\"responsetest\":true}").toFragment();
26+
.body("{\"responsetest\":true}")
27+
.uponReceiving("a second test interaction")
28+
.method("OPTIONS")
29+
.headers(headers)
30+
.willRespondWith()
31+
.status(200)
32+
.headers(headers)
33+
.body("")
34+
.toFragment();
2735
}
2836

2937

@@ -40,6 +48,7 @@ protected String consumerName() {
4048
@Override
4149
protected void runTest(String url) {
4250
try {
51+
assertEquals(new ConsumerClient(url).options("/"), 200);
4352
assertEquals(new ConsumerClient(url).get("/"), "{\"responsetest\":true}");
4453
} catch (Exception e) {
4554
throw new RuntimeException(e);

0 commit comments

Comments
 (0)