From 33b67cce70253c9f22b65c18390fdabcb4c2d653 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Sun, 5 Apr 2020 10:00:18 +1000 Subject: [PATCH] feat: update readmes on provider state injection #1061 (cherry picked from commit c509048eb74b0e61c9c848ae9f1ac83d22c19c05) --- pact-jvm-consumer-groovy/README.md | 3 ++- pact-jvm-consumer-junit/README.md | 6 ++++++ pact-jvm-consumer-junit5/README.md | 5 +++++ pact-jvm-consumer/README.md | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pact-jvm-consumer-groovy/README.md b/pact-jvm-consumer-groovy/README.md index cce8bdcc24..6989de21ab 100644 --- a/pact-jvm-consumer-groovy/README.md +++ b/pact-jvm-consumer-groovy/README.md @@ -624,6 +624,7 @@ of where this would be useful is API calls that require an ID which would be aut provider side, so there is no way to know what the ID would be beforehand. The DSL method `fromProviderState` allows you to set an expression that will be parsed with the values returned from the provider states. +For the body, you can use the key value instead of an expression. For example, assume that an API call is made to get the details of a user by ID. A provider state can be defined that specifies that the user must be exist, but the ID will be created when the user is created. So we can then define an @@ -635,7 +636,7 @@ service { uponReceiving('a request for user harry') withAttributes(method: 'get', path: fromProviderState('/api/user/${id}', '/api/user/100')) withBody { - name(~/\w+/, 'harry') + name(fromProviderState('userName', 'harry')) // looks up the value using the userName key } } ``` diff --git a/pact-jvm-consumer-junit/README.md b/pact-jvm-consumer-junit/README.md index fb8de5f092..b4d4f39524 100644 --- a/pact-jvm-consumer-junit/README.md +++ b/pact-jvm-consumer-junit/README.md @@ -730,3 +730,9 @@ expression for the path where the ID will be replaced with the value returned fr ```java .pathFromProviderState("/api/users/${id}", "/api/users/100") ``` + +You can also just use the key instead of an expression: + +```java + .valueFromProviderState('userId', 'userId', 100) // will look value using userId as the key +``` diff --git a/pact-jvm-consumer-junit5/README.md b/pact-jvm-consumer-junit5/README.md index 7d2062d764..220fc24e6a 100644 --- a/pact-jvm-consumer-junit5/README.md +++ b/pact-jvm-consumer-junit5/README.md @@ -174,3 +174,8 @@ expression for the path where the ID will be replaced with the value returned fr ```java .pathFromProviderState("/api/users/${id}", "/api/users/100") ``` +You can also just use the key instead of an expression: + +```java + .valueFromProviderState('userId', 'userId', 100) // will look value using userId as the key +``` diff --git a/pact-jvm-consumer/README.md b/pact-jvm-consumer/README.md index e5d34b0460..050b4b9b15 100644 --- a/pact-jvm-consumer/README.md +++ b/pact-jvm-consumer/README.md @@ -408,3 +408,9 @@ expression for the path where the ID will be replaced with the value returned fr ```java .pathFromProviderState("/api/users/${id}", "/api/users/100") ``` + +You can also just use the key instead of an expression: + +```java + .valueFromProviderState('userId', 'userId', 100) // will look value using userId as the key +```