Skip to content

Commit

Permalink
[vividus-plugin-json] Remove deprecated JSON steps
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow committed Aug 10, 2023
1 parent eff13c6 commit 3a65ce1
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 439 deletions.
167 changes: 3 additions & 164 deletions docs/modules/plugins/pages/plugin-json.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,6 @@ The steps syntax uses two internal (VIVIDUS-only) terms:

TIP: Use https://jsonpath-c48u.onrender.com/[JsonPath online validator] to test your JsonPath.

=== Save JSON element value from context

[WARNING]
====
The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is
the combination of the <<_json_context,dynamic variable>> and the
<<_save_json_element_value,step saving JSON element value from the input>>.
The replacement pattern is:
[source,gherkin]
----
When I save JSON element value from `${json-context}` by JSON path `<jsonPath>` to <scopes> variable `<variableName>`
----
====

Saves a value of JSON element found in JSON context into the variable with the
specified name and scope.

[source,gherkin]
----
When I save JSON element value from context by JSON path `$jsonPath` to $scopes variable `$variableName`
----

* `$jsonPath` - The {json-path} used to find JSON element value.
* `$scopes` - xref:commons:variables.adoc#_scopes[The comma-separated set of the variables scopes].
* `$variableName` - The name of the variable to save the found JSON element value.

.Validate the author of the first book
[source,gherkin]
----
When I execute HTTP GET request for resource with URL `https://raw.githubusercontent.com/json-path/JsonPath/master/json-path-web-test/src/main/resources/webapp/json/goessner.json`
When I save JSON element value from context by JSON path `$.store.book[0].author` to scenario variable `author-of-first-book`
Then `${author-of-first-book}` is equal to `Nigel Rees`
----

=== Save JSON element value

Saves a value of JSON element found in the given JSON into the variable with
Expand Down Expand Up @@ -177,38 +143,6 @@ When I convert JSON `{
Then `${jsonData.store.book[1].title}` is equal to `Sword of Honour`
----

=== Convert JSON to variable from context

[WARNING]
====
The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is
the combination of the <<_json_context,dynamic variable>> and the
<<_convert_json_to_variable,step converting JSON element from the input>>.
The replacement pattern is:
[source,gherkin]
----
When I convert JSON `${json-context}` to <scopes> variable `<variableName>`
----
====

Converts JSON element into the variable with the specified name and scope.

[source,gherkin]
----
When I convert JSON from context to $scopes variable `$variableName`
----

* `$scopes` - xref:commons:variables.adoc#_scopes[The comma-separated set of the variables scopes].
* `$variableName` - The name of the variable to save the found JSON element value.

.Validate the price of the second book
[source,gherkin]
----
When I execute HTTP GET request for resource with URL `https://raw.githubusercontent.com/json-path/JsonPath/master/json-path-web-test/src/main/resources/webapp/json/goessner.json`
When I convert JSON from context to scenario variable `jsonData`
Then `${jsonData.store.book[1].price}` is = `12.99`
----

=== Patch JSON

Modified an input JSON using a sequence of operations defined in JSON patch.
Expand Down Expand Up @@ -258,32 +192,6 @@ When I find $comparisonRule '$elementsNumber' JSON elements from '$json' by '$js
* `jsonPath` - The {json-path} used to find JSON elements.
* `stepsToExecute` - The xref:ROOT:glossary.adoc#_examplestable[ExamplesTable] with a single column containing the steps to execute for each found JSON element.

[WARNING]
====
The context-based step is deprecated and will be removed in VIVIDUS 0.6.0. The
<<_json_context,dynamic variable>> must be used instead. The replacement pattern is:
[source,gherkin]
----
When I find $comparisonRule `<elementsNumber>` JSON elements from `${json-context}` by `<jsonPath>` and for each element do<stepsToExecute>
----
====

.Context-based step
[source,gherkin]
----
When I find $comparisonRule `$elementsNumber` JSON elements by `$jsonPath` and for each element do$stepsToExecute
----
.Alias
[source,gherkin]
----
When I find $comparisonRule '$elementsNumber' JSON elements by '$jsonPath' and for each element doa$stepsToExecute
----

* `comparisonRule` - xref:parameters:comparison-rule.adoc[The comparison rule].
* `elementsNumber` - The expected number of elements.
* `jsonPath` - The {json-path} used to find JSON elements.
* `stepsToExecute` - The xref:ROOT:glossary.adoc#_examplestable[ExamplesTable] with a single column containing the steps to execute for each found JSON element.

.Validate each `accountId` consists of digits
[source,gherkin]
----
Expand All @@ -305,8 +213,8 @@ When I find > `0` JSON elements from `
]
}
` by `$.accounts.*` and for each element do
|step |
|Then number of JSON elements by JSON path `$[?(@.accountId =~ /\d+/i)]` is equal to 1|
|step |
|Then number of JSON elements from `${json-context}` by JSON path `$[?(@.accountId =~ /\d+/i)]` is equal to 1 |
----

=== Execute steps on JSON elements and exit on condition
Expand Down Expand Up @@ -342,85 +250,16 @@ When I find $comparisonRule '$elementsNumber' JSON elements in '$json' by '$json
* `expectedValue` - The expected value of the variable.
* `stepsToExecute` - The xref:ROOT:glossary.adoc#_examplestable[ExamplesTable] with a single column containing the steps to execute for each found JSON element.

[WARNING]
====
The context-based step is deprecated and will be removed in VIVIDUS 0.6.0. The
<<_json_context,dynamic variable>> must be used instead. The replacement pattern is:
[source,gherkin]
----
When I find <comparisonRule> `<elementsNumber>` JSON elements in `${json-context}` by `<jsonPath>` and until variable `<variableName>` <variableMatcher> `<expectedValue>` for each element I do:<stepsToExecute>
----
====

.Context-based step
[source,gherkin]
----
When I find $comparisonRule `$elementsNumber` JSON elements in context by `$jsonPath` and until variable `$variableName` $variableMatcher `$expectedValue` for each element I do:$stepsToExecute
----

.Context-based step alias
[source,gherkin]
----
When I find $comparisonRule '$elementsNumber' JSON elements in context by '$jsonPath' and until variable '$variableName' $variableMatcher '$expectedValue' for each element I do:$stepsToExecute
----

* `comparisonRule` - xref:parameters:comparison-rule.adoc[The comparison rule].
* `elementsNumber` - The expected number of elements.
* `jsonPath` - The {json-path} used to find JSON elements.
* `variableName` - The name of the variable to validate.
* `variableMatcher` - xref:parameters:string-comparison-rule.adoc[The string comparison rule].
* `expectedValue` - The expected value of the variable.
* `stepsToExecute` - The xref:ROOT:glossary.adoc#_examplestable[ExamplesTable] with a single column containing the steps to execute for each found JSON element.

.Find the title from JSON
[source,gherkin]
----
When I execute HTTP GET request for resource with URL `https://raw.githubusercontent.com/json-path/JsonPath/master/json-path-web-test/src/main/resources/webapp/json/goessner.json`
When I find > `1` JSON elements in `${response}` by `$.store.book` and until variable `title` matches `M.+` for each element I do:
|step|
|When I save JSON element value from context by JSON path `$.title` to scenario variable `title`|
|When I save JSON element value from `${json-context}` by JSON path `$.title` to scenario variable `title`|
Then `Moby Dick` is = `${title}`
----


=== Validate JSON element value from context

[WARNING]
====
The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is
the combination of the <<_json_context,dynamic variable>> and the
<<_validate_json_element_value,step validating JSON element value from the input>>.
The replacement pattern is:
[source,gherkin]
----
Then JSON element value from `${json-context}` by JSON path `<jsonPath` <comparisonRule> `<expectedValue>`
----
====

Validates if the JSON context contains the expected JSON element value matching
the comparison rule by the specified JSON path.

[source,gherkin]
----
Then JSON element value from context by JSON path `$jsonPath` $comparisonRule `$expectedValue`
----

* `$jsonPath` - The {json-path} used to find JSON element value.
* `$comparisonRule` - The comparison rule to match JSON element value depending on the https://www.json.org/json-en.html[element type]:
** for `string` - xref:parameters:string-comparison-rule.adoc[string comparison rules] are applicable,
** for `number` - xref:parameters:comparison-rule.adoc[regular comparison rules] are applicable,
** for `boolean` - only single rule `IS_EQUAL_TO` (readable form: `is equal to`) is allowed,
** for `null` - only two rules `IS_EQUAL_TO` and `IS_NOT_EQUAL_TO` (readable forms: `is equal to` and `is not equal to`) are allowed
** `array` and `object` are complex types and must be validated using another steps dedicated for JSON elements.
* `$expectedValue` - The expected value of JSON element to match according to the comparison rule.

.Validate the price of the third book is less than 9
[source,gherkin]
----
When I execute HTTP GET request for resource with URL `https://raw.githubusercontent.com/json-path/JsonPath/master/json-path-web-test/src/main/resources/webapp/json/goessner.json`
Then JSON element value from context by JSON path `$.store.book[2].price` is less than `9`
----

=== Validate JSON element value

Validates if the given JSON contains the expected JSON element value matching
Expand Down
130 changes: 0 additions & 130 deletions docs/modules/plugins/pages/plugin-rest-api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -962,43 +962,6 @@ Then '${value}' is equal to 'newCookieValue'
:json-unit-options: https://github.com/lukas-krecan/JsonUnit/blob/master/README.md#options[options]


=== Verify context contains data

[WARNING]
====
The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is
the combination of the xref:plugins:plugin-json.adoc#_json_context[dynamic variable] and the
xref:plugins:plugin-json.adoc#_validate_json_element[step validating the JSON element from the input].
The replacement pattern is:
[source,gherkin]
----
Then JSON element from `${json-context}` by JSON path `<jsonPath>` is equal to `<expectedData>`<options>
----
====

Checks if the JSON context contains an expected data by a JSON path

[source,gherkin]
----
Then JSON element by JSON path `$jsonPath` is equal to `$expectedData`$options
----

* `jsonPath` - {json-path}
* `expectedData` - expected JSON
* `options` - {json-unit-options}

.Check JSON context contains JSON object by JSON path
[source,gherkin]
----
Then JSON element by JSON path `$.accountList[0]` is equal to `
{
"accountId": 12345,
"accountName": "${json-unit.any-string}",
"status": "Active"
}
`ignoring extra fields
----

=== Verify JSON contains data

[WARNING]
Expand All @@ -1008,37 +971,6 @@ The step is still available via `vividus-plugin-rest-api`, but it'll be required
to install `vividus-plugin-json` explicitly starting from VIVIDUS 0.6.0.
====

=== Verify number of elements in context

[WARNING]
====
The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is
the combination of the xref:plugins:plugin-json.adoc#_json_context[dynamic variable] and the
xref:plugins:plugin-json.adoc#_validate_number_of_json_elements[step validating the number of JSON elements from the input].
The replacement pattern is:
[source,gherkin]
----
Then number of JSON elements from `${json-context}` by JSON path `<jsonPath>` is <comparisonRule> <elementsNumber>
----
====

Verifies that the number of elements found in the JSON context by a JSON path matches an expected number according to specified comparison rule

[source,gherkin]
----
Then number of JSON elements by JSON path `$jsonPath` is $comparisonRule $elementsNumber
----

* `jsonPath` - {json-path}
* `comparisonRule` - xref:parameters:comparison-rule.adoc[comparison rule]
* `elementsNumber` - expected elements number

.Number of account lists in JSON is equal to 2
[source,gherkin]
----
Then number of JSON elements by JSON path `$.accountList` is equal to 2
----

=== Verify number of elements in JSON

[WARNING]
Expand All @@ -1048,37 +980,6 @@ to `vividus-plugin-json`. The step is still available via `vividus-plugin-rest-a
but it'll be required to install `vividus-plugin-json` explicitly starting from VIVIDUS 0.6.0.
====

=== Save element from context

[WARNING]
====
The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is
the combination of the xref:plugins:plugin-json.adoc#_json_context[dynamic variable] and the
xref:plugins:plugin-json.adoc#_save_json_element[step saving JSON element from the input].
The replacement pattern is:
[source,gherkin]
----
When I save JSON element from `${json-context}` by JSON path `<jsonPath>` to <scopes> variable `<variableName>`
----
====

Saves value extracted from the JSON context into a variable with specified name

[source,gherkin]
----
When I save JSON element from context by JSON path `$jsonPath` to $scopes variable `$variableName`
----

* `jsonPath` - {json-path}
* `$scopes` - xref:commons:variables.adoc#_scopes[The comma-separated set of the variables scopes].
* `$variableName` - the variable name

.Save accountId element from JSON context
[source,gherkin]
----
When I save JSON element from context by JSON path `$.accountId` to SCENARIO variable `account-id`
----

=== Save element from JSON

[WARNING]
Expand All @@ -1088,37 +989,6 @@ The step is still available via `vividus-plugin-rest-api`, but it'll be required
to install `vividus-plugin-json` explicitly starting from VIVIDUS 0.6.0.
====

=== Save number of elements in context

[WARNING]
====
The step is deprecated and will be removed in VIVIDUS 0.6.0. The replacement is
the combination of the xref:plugins:plugin-json.adoc#_json_context[dynamic variable] and the
xref:plugins:plugin-json.adoc#_save_number_of_json_elements[step saving the number of JSON elements from the input].
The replacement pattern is:
[source,gherkin]
----
When I save number of elements from `${json-context}` found by JSON path `<jsonPath>` to <scopes> variable `<variableName>`
----
====

Saves number of elements found in the JSON context by JSON path into a variable

[source,gherkin]
----
When I set number of elements found by JSON path `$jsonPath` to $scopes variable `$variableName`
----

* `jsonPath` - {json-path}
* `$scopes` - xref:commons:variables.adoc#_scopes[The comma-separated set of the variables scopes].
* `$variableName` - the variable name

.Save number of id elements
[source,gherkin]
----
When I set number of elements found by JSON path `$..id` to scenario variable `idsCount`
----

=== Save number of elements from JSON

[WARNING]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ public void saveElementsNumberByJsonPath(String json, String jsonPath, Set<Varia
* <pre>
* When I find equal to `1` JSON elements from `{"parent_id":"","elements":[{"name": "1"},{"name": "2"}]}` by
* `$.[?(@.parent_id=="")]` and for each element do
* |step |
* |Then number of JSON elements by JSON path `$..name` is = 2|
* |step |
* |Then number of JSON elements from `${json-context}` by JSON path `$..name` is = 2 |
* </pre>
*
* @param comparisonRule The rule to match the number of elements. The supported rules:
Expand Down Expand Up @@ -267,7 +267,7 @@ public void executeStepsForFoundJsonElements(ComparisonRule comparisonRule, int
* When I find &gt; `1` JSON elements in `${json}` by `$.store.book` and until variable `title` matches `M.+`
* for each element I do:
* |step|
* |When I save JSON element value from context by JSON path `$.title` to scenario variable `title`|
* |When I save JSON element value from `${json-context}` by JSON path `$.title` to scenario variable `title`|
* </pre>
*
* @param comparisonRule The rule to match the number of elements. The supported rules:
Expand Down
Loading

0 comments on commit 3a65ce1

Please sign in to comment.