From f141a547ad7baa594b4c4906728e04a2c94857a7 Mon Sep 17 00:00:00 2001 From: Utsav Paul <91927689+Smartmind12@users.noreply.github.com> Date: Sun, 1 Oct 2023 22:13:28 +0530 Subject: [PATCH 1/2] Update stub-metadata.md Reducing vertical space in documentation for code examples using code tabs. --- _docs/stub-metadata.md | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/_docs/stub-metadata.md b/_docs/stub-metadata.md index bb26958e..a04db15b 100644 --- a/_docs/stub-metadata.md +++ b/_docs/stub-metadata.md @@ -12,7 +12,9 @@ It is possible to attach arbitrary metadata to stub mappings, which can be later Data under the `metadata` key is a JSON object (represented in Java by a `Map`). It can be added to a stub mapping on creation. -Java: +{% codetabs %} + +{% codetab Java %} ```java stubFor(get("/with-metadata") @@ -25,7 +27,9 @@ stubFor(get("/with-metadata") )); ``` -JSON: +{% endcodetab %} + +{% codetab JSON %} ```json { @@ -46,19 +50,27 @@ JSON: } ``` +{% endcodetab %} + +{% endcodetabs %} + ## Search for stubs by metadata Stubs can be found by matching against their metadata using the same matching strategies as when [matching HTTP requests](../request-matching/). The most useful matcher for this is `matchesJsonPath`: -Java: +{% codetabs %} + +{% codetab Java %} ```java List stubs = findStubsByMetadata(matchingJsonPath("$.singleItem", containing("123"))); ``` -API: +{% endcodetab %} + +{% codetab JSON %} ```json POST /__admin/mappings/find-by-metadata @@ -71,19 +83,28 @@ POST /__admin/mappings/find-by-metadata } ``` +{% endcodetab %} + +{% endcodetabs %} + ## Remove stubs by metadata Similarly, stubs with matching metadata can be removed: -Java: +{% codetabs %} + +{% codetab Java %} ```java removeStubsByMetadata(matchingJsonPath("$.singleItem", containing("123"))); ``` -API: +{% endcodetab %} + +{% codetab JSON %} ```json + POST /__admin/mappings/remove-by-metadata { @@ -94,6 +115,10 @@ POST /__admin/mappings/remove-by-metadata } ``` +{% endcodetab %} + +{% endcodetabs %} + ## Remove request journal events by metadata See [Removing items from the journal](../verifying#by-criteria) From 93571b6ce9e5006d5731f0d3ecc82c4de77f5db6 Mon Sep 17 00:00:00 2001 From: Oleg Nenashev Date: Mon, 9 Oct 2023 08:31:20 +0200 Subject: [PATCH 2/2] Update _docs/stub-metadata.md --- _docs/stub-metadata.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_docs/stub-metadata.md b/_docs/stub-metadata.md index a04db15b..4fbc1295 100644 --- a/_docs/stub-metadata.md +++ b/_docs/stub-metadata.md @@ -103,10 +103,9 @@ removeStubsByMetadata(matchingJsonPath("$.singleItem", containing("123"))); {% codetab JSON %} -```json - POST /__admin/mappings/remove-by-metadata +```json { "matchesJsonPath" : { "expression" : "$.singleItem",