Skip to content

Commit 2a9ac69

Browse files
committed
doc: add example using MessagePactBuilder with string content #1669
1 parent e297ef7 commit 2a9ac69

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

consumer/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The library is available on maven central using:
1414

1515
* group-id = `au.com.dius.pact`
1616
* artifact-id = `consumer`
17-
* version-id = `4.2.x`
17+
* version-id = `4.4.x`
1818

1919
## DSL Usage
2020

@@ -506,14 +506,14 @@ When you come accross the `body()` method of `PactDslWithProvider` builder start
506506
The call to `LambdaDsl` replaces the call to instance `new PactDslJsonArray()` and `new PactDslJsonBody()` of the pact library.
507507

508508
```java
509-
io.pactfoundation.consumer.dsl.LambdaDsl.*
509+
au.com.dius.pact.consumer.dsl.LambdaDsl.*
510510
```
511511

512512
### Response body as json array
513513

514514
```java
515515

516-
import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonArray;
516+
import static au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonArray;
517517

518518
...
519519

@@ -534,7 +534,7 @@ builder.given("some state")
534534

535535
```java
536536

537-
import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonBody;
537+
import static au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonBody;
538538

539539
...
540540

consumer/junit5/README.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The library is available on maven central using:
99

1010
* group-id = `au.com.dius.pact.consumer`
1111
* artifact-id = `junit5`
12-
* version-id = `4.2.X`
12+
* version-id = `4.4.X`
1313

1414
## Usage
1515

@@ -234,6 +234,26 @@ message queue or topic as a notification or event. With Pact tests, we will be t
234234
works with the messages setup as the expectations in test. This should be the message handler code that processes the
235235
actual messages that come off the message queue in production.
236236

237+
For example:
238+
239+
```java
240+
builder.given("Some Provider State")
241+
.expectsToReceive("a test message")
242+
.withContent("{\"value\": \"test\"}")
243+
.toPact();
244+
```
245+
246+
or using a Dsl object:
247+
248+
```java
249+
builder.given("Some Provider State")
250+
.expectsToReceive("a test message")
251+
.withContent(new PactDslJsonBody()
252+
.stringValue("testParam1", "value1")
253+
.stringValue("testParam2", "value2"))
254+
.toPact();
255+
```
256+
237257
You can use either the V3 Message Pact or the V4 Asynchronous Message interaction to test these types of interactions.
238258

239259
For a V3 message pact example, see [AsyncMessageTest](https://github.com/pact-foundation/pact-jvm/blob/ac6a0eae0b18183f6f453eafddb89b90741ace42/consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/AsyncMessageTest.java).
@@ -256,7 +276,7 @@ builder.given("SomeProviderState")
256276
md.add("metadata3", 10L);
257277
md.matchRegex("partitionKey", "[A-Z]{3}\\d{2}", "ABC01");
258278
})
259-
.withContent(body)
279+
.withContent("{\"value\": \"test\"}")
260280
.toPact();
261281
```
262282

0 commit comments

Comments
 (0)