Skip to content

Commit 2d877cc

Browse files
authored
doc: correct documentation to store and retrieve a full body (#116)
- provided test case to ensure functionality <!-- Please describe your pull request here. --> ## References #115 <!-- References to relevant GitHub issues and pull requests, esp. upstream and downstream changes --> ## Submitter checklist - [ ] Recommended: Join [WireMock Slack](https://slack.wiremock.org/) to get any help in `#help-contributing` or a project-specific channel like `#wiremock-java` - [ ] The PR request is well described and justified, including the body and the references - [ ] The PR title represents the desired changelog entry - [ ] The repository's code style is followed (see the contributing guide) - [ ] Test coverage that demonstrates that the change works as expected - [ ] For new features, there's necessary documentation in this pull request or in a subsequent PR to [wiremock.org](https://github.com/wiremock/wiremock.org) <!-- Put an `x` into the [ ] to show you have filled the information. The template comes from https://github.com/wiremock/.github/blob/main/.github/pull_request_template.md You can override it by creating .github/pull_request_template.md in your own repository -->
1 parent 79ad6ef commit 2d877cc

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ Full example for storing a state:
410410
}
411411
```
412412

413-
To record a complete response body, use:
413+
To record a complete response body, use (**ATTENTION**: tripple `{{{`):
414414

415415
```json
416416
{
@@ -422,7 +422,7 @@ To record a complete response body, use:
422422
"parameters": {
423423
"context": "{{jsonPath response.body '$.id'}}",
424424
"state": {
425-
"fullBody": "{{jsonPath response.body '$'}}"
425+
"fullBody": "{{{jsonPath response.body '$'}}}"
426426
}
427427
}
428428
}

src/test/java/org/wiremock/extensions/state/functionality/StateTemplateHelperProviderExtensionTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,20 @@ void test_returnsState() {
578578
getContext(contextName, (result) -> assertThat(result).containsExactlyEntriesOf(request));
579579
}
580580

581+
582+
@DisplayName("returns body from previous request")
583+
@Test
584+
void test_returnsBody() {
585+
Map<String, Object> request = Map.of("contextValue", "aContextValue", "otherKey", "otherValue");
586+
createContextStatePostStub(Map.of("fullBody", "{{{jsonPath request.body '$'}}}"));
587+
createContextGetStub("{{{state context=request.pathSegments.[1] property='fullBody' }}}");
588+
589+
var expectedResult = new HashMap<>(request);
590+
expectedResult.put("contextName", contextName);
591+
postContext(contextName, request);
592+
getContext(contextName, (result) -> assertThat(result).containsExactlyInAnyOrderEntriesOf(expectedResult));
593+
}
594+
581595
@DisplayName("with default specified returns property from previous request")
582596
@Test
583597
void test_withDefaultReturnsState() {

0 commit comments

Comments
 (0)