### Spring Boot REST Controller Example Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-spring/README.md An example of a Spring Boot REST controller that handles GET requests to '/hello'. It returns a ResponseEntity with the string "Hello world!". ```java package com.yourcompany.app.api; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/hello") public ResponseEntity hello() { return ResponseEntity.ok("Hello world!"); } } ``` -------------------------------- ### Access Scenario Examples Variable (Gherkin) Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Provides access to the `_examples` variable, which holds values from the 'Examples' table in Scenario Templates. This allows dynamic referencing of example data within the `Background` or other steps. ```gherkin Background: Given that we call "{{_examples.url}}" Scenario Template: When we ... Then we receive ... ... Example: | url | | http://backend1/endpoint | | http://backend2/endpoint | ``` -------------------------------- ### WireMock Templating Syntax: Path Parameter Access Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/MIGRATION.md Illustrates the difference in accessing path parameters between MockServer and WireMock syntax, with an example. ```APIDOC ## WireMock Templating: Path Parameter Access ### Description This section demonstrates how to access path parameters using WireMock's `request.pathSegments` array, contrasting it with the older MockServer syntax. ### Method N/A (Templating) ### Endpoint N/A ### Parameters #### Request Body N/A ### Request Example N/A ### Response N/A ### Response Example ```gherkin Given that getting on "http://backend/v1/resource/item/(\\d+)" will return: """yml item_id: \{{request.pathSegments.6}} """ ``` #### Before (MockServer) ```gherkin Given that getting on "http://backend/v1/resource/item/(\d+)" will return: """yml item_id: {{{[_request.pathParameterList.0.values.0.value]}}} """ ``` #### After (WireMock) WireMock uses the `request.pathSegments` array. For a path like `/v1/resource/item/123`, `request.pathSegments.6` would correspond to `123` (assuming indices start after initial segments not captured by regex, or adjust index as per actual path splitting). **Note:** Ensure correct indexing based on your specific URL structure and how segments are parsed. ``` -------------------------------- ### Dependency Update Example Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/MIGRATION.md Example of how to update your pom.xml to use the new `tzatziki-http` artifact and exclude `cucumber-picocontainer`. ```APIDOC ## Dependency Update ### Description Update your `pom.xml` to include the `tzatziki-http` module and exclude `cucumber-picocontainer` if you are using it with `tzatziki-spring`. ### Method N/A (Configuration) ### Endpoint N/A ### Parameters #### Request Body N/A ### Request Example ```xml com.decathlon.tzatziki tzatziki-http 1.0.x test io.cucumber cucumber-picocontainer ``` ### Response N/A ### Response Example N/A ``` -------------------------------- ### Using the `split` Template Helper: MockServer vs WireMock Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/MIGRATION.md Shows the difference in using the `split` helper function for processing path parameters, highlighting the change in accessing path segments. ```gherkin Given that getting on "http://backend/v1/resource/items/(.*)" will return a List: """ {{#split _request.pathParameterList.0.values.0.value [,]}} - item_id: {{this}} {{/split}} """ ``` ```gherkin Given that getting on "http://backend/v1/resource/items/(.*)" will return a List: """ \{{#split request.pathSegments.6 ','}} - item_id: \{{this}} \{{/split}} """ ``` -------------------------------- ### Static Method Updates Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/MIGRATION.md Details on how static utility methods have been moved from `MockFaster` to `HttpUtils`. ```APIDOC ## Static Method Updates ### Description Static utility methods previously available in `MockFaster` have been relocated to the `HttpUtils` class. ### Method N/A (Code Refactoring) ### Endpoint N/A ### Parameters #### Request Body N/A ### Request Example N/A ### Response N/A ### Response Example N/A #### Code Changes - `MockFaster.url()` should be updated to `HttpUtils.url()` - `MockFaster.reset()` should be updated to `HttpUtils.reset()` ``` -------------------------------- ### Spring Boot Application Class Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-spring/README.md An example of a basic Spring Boot application class. This class serves as the entry point for a Spring Boot application and is used to bootstrap the testing context. ```java package com.yourcompany.app; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class HelloApplication { public static void main(String[] args) { SpringApplication.run(HelloApplication.class, args); } } ``` -------------------------------- ### Access Query Parameters: MockServer vs WireMock Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/MIGRATION.md Demonstrates how to access query parameters in Gherkin steps, showing the difference between MockServer's syntax and WireMock's `request.query` object. ```gherkin Given that calling "http://backend/hello?name=.*" will return: """yml message: Hello {{{[_request.queryStringParameterList.0.values.0.value]}}}! """ ``` ```gherkin Given that calling "http://backend/hello?name=.*" will return: """yml message: \{{request.query.name}}! """ ``` -------------------------------- ### Creating Custom Assertion Flags Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Provides a Java example for adding custom assertion flags to the library, showing how to define logic for new assertion types. ```java Asserts.addFlag("isEvenAndInBounds", (input, expected) -> { String[] bounds = Splitter.on('|').trimResults().omitEmptyStrings().splitToList(expected).toArray(String[]::new); int inputInt = Integer.parseInt(input); int min = Integer.parseInt(bounds[0]); int max = Integer.parseInt(bounds[1]); org.junit.jupiter.api.Assertions.assertTrue(() -> inputInt >= min && inputInt <= max && inputInt % 2 == 0); }); ``` -------------------------------- ### Call method with parameters by order or name (Gherkin) Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Shows two ways to call methods with parameters: by matching parameter order or by using parameter names via introspection (requires `-parameters` compilation flag). Examples cover different parameter types and expected outcomes. ```gherkin Given that aListWrapper is a ListWrapper: """ wrapper: - hello - bob """ When the method of aListWrapper is called with parameters: """ """ Then _method_output is equal to: """ """ And aListWrapper is equal to: """ """ Examples: | methodCalled | params | expectedReturn | expectedListState | | get | {"anyName":0} | hello | {"wrapper":["hello","bob"]} | get | {"anotherName":1} | bob | {"wrapper":["hello","bob"]} | add | {"byArgOrder1":1,"byArgOrder2":"mr"} | ?isNull | {"wrapper":["hello","mr","bob"]} | add | {"element":"mr","index":1} | ?isNull | {"wrapper":["hello","mr","bob"]} ``` -------------------------------- ### Gherkin Syntax for Inserting Data Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md These Gherkin examples illustrate different ways to insert data using the `ObjectSteps`. They cover plain text content, map-like content, and typed objects, including the use of fully qualified names for clarity. ```gherkin Given that content is: """ my plain text content """ ``` ```gherkin Given that content is a Map: """ message: my plain text content """ ``` ```gherkin Given that tom is a User: """ id: 1 name: tom """ ``` ```gherkin Given that tom is a com.decathlon.users.model.User: ... ``` -------------------------------- ### Gherkin Syntax for HTTP GET and Response Body Assertion Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Shows the Gherkin equivalent for performing an HTTP GET request and asserting the response body matches 'Hello world!'. ```gherkin When we get "http://backend/hello" Then we receive "Hello world!" ``` -------------------------------- ### Update Tzatziki HTTP Dependency (Maven) Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/MIGRATION.md Updates the `tzatziki-http` Maven dependency to the latest version and excludes `cucumber-picocontainer` to prevent conflicts when used with `tzatziki-spring`. ```xml com.decathlon.tzatziki tzatziki-http 1.0.x test io.cucumber cucumber-picocontainer ``` -------------------------------- ### CucumberTest Runner Class Setup Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md This Java code demonstrates how to configure a Cucumber test runner class using JUnit. It includes necessary annotations for running Cucumber tests, specifying plugins for output formatting, and defining the glue package for steps. ```java package com.yourcompany; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions(plugin = {"pretty", "json:target/cucumber.json"}, glue = "com.decathlon.tzatziki.steps", tags = "not @ignore") public class CucumberTest {} ``` -------------------------------- ### Gherkin Table for Populating Nested Objects Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md This Gherkin example demonstrates how to populate nested object properties using a table format. It shows how to map column headers, including dot notation for nested fields, to object properties. ```gherkin Given that users is a List: | id | name | group.id | group.name | | 1 | bob | 1 | admin | ``` -------------------------------- ### Basic HTTP GET Request and Assertion Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Demonstrates how to perform a basic HTTP GET request and assert the response body using RestAssured syntax, which is then translated into Gherkin. ```java given().get("http://backend/hello") .then() .assertThat() .body(equalTo("Hello world!")); ``` -------------------------------- ### Adjust Path Matching Wildcards: MockServer vs WireMock Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/MIGRATION.md Explains the adjustment needed for path matching wildcards, converting MockServer's `*` or `.*` to WireMock's regex capturing groups `(.*)`. ```gherkin And "http://backend/v1/resource/items/*" has received 0 POST ``` ```gherkin And "http://backend/v1/resource/items/(.*)" has received 0 POST ``` -------------------------------- ### Accessing Path Parameters in WireMock Templating Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/MIGRATION.md Demonstrates how to access path parameters in WireMock responses using `request.pathSegments` array, contrasting with the older MockServer syntax. ```gherkin Given that getting on "http://backend/v1/resource/item/(\d+)" will return: """yml item_id: \{{request.pathSegments.6}} """ ``` -------------------------------- ### Custom Date Adapter in Java Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Provides a Java code example for adding a custom date type adapter to handle specific date formats, like 'minguodate', within the library. ```java Time.addCustomTypeAdapter("minguodate", (date, zoneId) -> MinguoDate.from(date.toInstant().atZone(zoneId).toLocalDate())); ``` -------------------------------- ### HTTP Queries with Tzatziki Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md This section covers how to perform HTTP requests (GET, POST, PUT, DELETE, etc.) and assert their responses using Tzatziki's Gherkin steps. It details how to specify request methods, bodies, headers, and how to assert status codes and response bodies. ```APIDOC ## HTTP Queries ### Description This library wraps RestAssured in a Gherkin syntax to simplify HTTP request testing. ### Methods - `get` - `post` - `put` - `patch` - `delete` - `head` - `trace` - `call` (alias for `get`) ### Basic Usage ```gherkin When we get "http://backend/hello" Then we receive "Hello world!" ``` ### Asserting Status ```gherkin Then we receive a status OK ``` ### Asserting Status and Body ```gherkin Then we receive a status OK and: """ message: Hello user! """ ``` *Note: Status can be specified by name, code, or both (e.g., `OK`, `200`, `OK_200`).* ### Sending Requests with Headers and Body ```gherkin When we send on "http://backend/hello": """ method: POST headers: Some-Token: Some-Value body: payload: message: some value """ ``` *Note: OPTIONS requests are only supported using the detailed format.* ### Sending Plain Text Payload ```gherkin # again an alternative format When we post on "http://backend/hello" a Request: """ headers: Content-Type: application/xml body: payload: | Hello world! """ ``` ### Retrying Calls ```gherkin Then a user calling "http://backend/endpoint" receives: """ key: value """ ``` *This will wait and retry until the specified value is received, as described in the timeout and retry delay section.* ``` -------------------------------- ### Asserting messages from the beginning of a Kafka topic Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-spring-kafka/README.md Asserts messages in a Kafka topic starting from the beginning, useful for re-reading messages. ```gherkin Then from the beginning the users topic contains this user: """ id: 1 name: bob """ ``` -------------------------------- ### Inverting a Test Condition in Gherkin Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Explains and provides an example of inverting a test condition in Gherkin by prefixing the step with 'it is not true that'. ```gherkin Given that user1 is a User: """ id: 1 name: bob """ Then it is not true that user1.name is equal to "tom" ``` -------------------------------- ### Gherkin Syntax for Sending Plain Text XML Payload Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Provides an example of how to send a plain text XML payload in an HTTP request using Gherkin, utilizing YAML syntax for the payload. ```gherkin # again an alternative format When we post on "http://backend/hello" a Request: """ headers: Content-Type: application/xml body: payload: | Hello world! """ ``` -------------------------------- ### Assert GET Request with Headers in Gherkin Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Asserts that a specific URL received a GET request with specified headers. Useful for verifying authentication or custom headers. ```gherkin Then "http://backend/v1/resource" has received: """ method: GET headers: x-api-key: a-valid-api-key Authorization: Bearer MyToken """ ``` -------------------------------- ### Access Request Body (JSON): MockServer vs WireMock Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/MIGRATION.md Illustrates how to access JSON data from the request body using WireMock's `parseJson` helper function, contrasting it with MockServer's direct access methods. ```gherkin # Accessing a single field Given that getting on "http://backend/endpoint" will return: """yml message: {{{[_request.body.json.text]}}} """ # Iterating over a list Given that posting on "http://backend/v1/resource/items" will return a List: """ {{#foreach _request.body}} - id: {{this.id}} name: nameOf{{this.id}} {{/foreach}} """ ``` ```gherkin # Accessing a single field Given that getting on "http://backend/endpoint" will return: """yml message: \{{lookup (parseJson request.body) 'text'}} """ # Iterating over a list Given that posting on "http://backend/v1/resource/items" will return a List: """ \{{#each (parseJson request.body)}} - id: \{{this.id}} name: nameOf\{{this.id}} \{{/each}} """ ``` -------------------------------- ### Update Request Verification Paths: MockServer vs WireMock Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/MIGRATION.md Details the change in accessing the request body when verifying payloads, moving from `payloads[x].body.json` to `payloads[x].request.body`. ```gherkin Then "http://backend/endpoint" has received 2 POST payloads And payloads[0].body.json.containers[0].zones.size == 2 And payloads[1].body.json.containers[0].zones.size == 1 ``` ```gherkin Then "http://backend/endpoint" has received 2 POST payloads And payloads[0].request.body.containers[0].zones.size == 2 And payloads[1].request.body.containers[0].zones.size == 1 ``` -------------------------------- ### Gherkin with Dot Notation for Nested Fields Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md These Gherkin examples showcase the use of dot notation within strings to specify and populate nested fields in objects. It covers both YAML and JSON formats for input. ```gherkin Scenario: we can use dot-notation to specify a single nested field Given that yamlNest is a Nest: """ subNest.bird.name: Titi """ Then yamlNest contains: """ subNest: bird: name: Titi """ Given that jsonNest is a Nest: """ { "subNest.bird.name": "Titi" } """ And jsonNest contains: """ { "subNest": { "bird": { "name": "Titi" } } } """ ``` -------------------------------- ### Gherkin - Navigation and Element Actions Source: https://github.com/decathlon/tzatziki/wiki/Module-:-Tzatziki-front Gherkin steps for navigating to URLs, performing actions like FILL or CLICK on elements, and waiting for elements to be visible. ```gherkin browser navigate to 'url' (waiting 'cssSelector' (visible)) we perform a 'action' (with 'parameters...') on 'cssSelector' (waiting 'cssSelector' (visible)) ``` -------------------------------- ### Set Logger Levels and Pattern (Gherkin) Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-logback/README.md Demonstrates Gherkin syntax for setting the root logger level to DEBUG, a specific package logger level, and asserting log content. ```gherkin Given a root logger set to DEBUG Given a com.yourcompany logger set to DEBUG Then the logs contain: """ - ?e .* some lines """ Then the logs contains 2 lines equal to "?e .* some lines" ``` -------------------------------- ### Reading from a File in Gherkin Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Demonstrates how to read content from a file in Gherkin using the `{{{[&path/to/file]}}}` syntax and comparing it with expected output. ```gherkin # READ When bob is "{{{[&path/to/file]}}}" Then bob is equal to: """ yml id: 1 name: bob """ ``` -------------------------------- ### Gherkin Syntax for Defining Simple HTTP Mocks Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Shows basic Gherkin steps for defining mocks using WireMock, including setting return status codes for different HTTP methods and URLs. ```gherkin Given that posting on "http://backend/users" will return a status CREATED_201 Given that putting on "http://backend/test/someValue" will return a status OK_200 # wildchar on any resource and returning a status Given that calling "http://backend/.*" will return a status BAD_GATEWAY ``` -------------------------------- ### Gherkin - Using CSS Selector Referential Source: https://github.com/decathlon/tzatziki/wiki/Module-:-Tzatziki-front Demonstrates how to use predefined CSS selectors from a referential file within Gherkin steps. ```gherkin we perform a CLICK on save-button ``` -------------------------------- ### Set up OpenSearch index data (Gherkin/YAML) Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-opensearch/README.md This Gherkin step, using YAML for data, shows how to populate an OpenSearch index with documents. The `_id` field is used for document identification and is removed from the source. ```gherkin Given that the users index will contain: """yaml - _id: user1 name: John Doe email: john@example.com age: 30 - _id: user2 name: Jane Smith email: jane@example.com age: 25 """ ``` -------------------------------- ### Gherkin - List of Actions Source: https://github.com/decathlon/tzatziki/wiki/Module-:-Tzatziki-front Defines a Gherkin step to perform a sequence of actions on multiple elements, specified in YAML format, including waiting conditions. ```gherkin we perform a list of actions : yaml : - action : FILL parameters : fill input css_selector : '#select1' wait_for: '#save_button' wait_for_visible: true - action : CLICK css_selector : '#button1' wait_for: '#save_button' wait_for_visible: true ``` -------------------------------- ### Gherkin Syntax for Detailed Mock Definition Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Shows a more comprehensive Gherkin step for defining mocks, specifying request method, headers, body, and response status. ```gherkin Given that "http://backend/something" is mocked as: """ request: method: POST body: type: User payload: name: bob id: 1 response: status: ACCEPTED """ ``` -------------------------------- ### Assert Interaction Frequency with Performance Constraint in Gherkin Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Asserts the number of times a specific request (e.g., GET) was received within a given time frame. Helps in validating performance aspects of the mocked service. ```gherkin Then during 50ms "http://backend/endpoint" has received at most 1 GET ``` -------------------------------- ### Setting Current Time in Gherkin Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Demonstrates how to set a specific current time in a Gherkin test scenario using the 'Given' step and verifying it with the 'Then' step. ```gherkin Given that the current time is the first Sunday of November 2020 at midnight Then now is equal to "2020-11-01T00:00:00Z" ``` -------------------------------- ### Call static method (Gherkin) Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Demonstrates how to invoke static methods by specifying the class name instead of an instance. The parameter passing rules are the same as for instance methods. ```gherkin When the method read of com.decathlon.tzatziki.utils.Mapper is called with parameters: """ objectToRead: | id: 1 name: bob wantedType: com.decathlon.tzatziki.User """ Then _method_output.class is equal to: """ com.decathlon.tzatziki.User """ And _method_output is equal to: """ id: 1 name: bob """ ``` -------------------------------- ### Call method without parameters (Gherkin) Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Shows how to call a method that takes no parameters on an instance. The result of the method call is stored in a special variable `_method_output` for subsequent assertions. ```gherkin Given that aList is a List: """ - hello - mr """ When the method size of aList is called ``` -------------------------------- ### Run Maven Tests Source: https://github.com/decathlon/tzatziki/blob/main/CONTRIBUTING.md Command to clean the project and verify tests using Maven. This ensures that all tests pass before submitting changes. ```bash mvn clean verify ``` -------------------------------- ### Configure OpenSearch host Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-opensearch/README.md This Java code snippet demonstrates how to set the OpenSearch host system property, which the module uses to establish a connection. This is crucial for the module to locate your OpenSearch instance. ```java System.setProperty("opensearch.host", "http://localhost:9200"); ``` -------------------------------- ### Gherkin: Simulate successive calls with different responses Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Demonstrates how to configure mock responses that vary based on the number of times an endpoint is called, simulating retries or stateful behavior. Includes handling a fallback 404 response. ```gherkin Scenario: Successive calls to a mocked endpoint can reply different responses Given that "http://backend/time" is mocked as: """ response: - consumptions: 1 body: payload: morning - consumptions: 1 body: payload: noon - consumptions: 1 body: payload: afternoon - consumptions: 1 body: payload: evening - status: NOT_FOUND_404 """ Then getting on "http://backend/time" returns: """ morning """ Then getting on "http://backend/time" returns: """ noon """ Then getting on "http://backend/time" returns: """ afternoon """ Then getting on "http://backend/time" returns: """ evening """ Then getting on "http://backend/time" returns a status 404 Then getting on "http://backend/time" returns a status 404 ``` -------------------------------- ### Access System Properties (Gherkin) Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Allows access to system properties using the `_properties` context. This enables tests to read or set JVM system properties during execution. ```gherkin Scenario: we can access the system properties from the test Given that _properties.test = "something" Then _properties.test is equal to "something" ``` -------------------------------- ### Gherkin Syntax for Mocks with Delay Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Demonstrates how to define an HTTP mock that introduces a delay before returning a response, including status and body. ```gherkin # introduce a delay Given that calling "http://backend/hello" will take 10ms to return a status OK and "Hello you!" ``` -------------------------------- ### HTTP Mocking with Tzatziki Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md This section explains how to define mocks for HTTP services using Tzatziki's Gherkin steps, leveraging WireMock internally. It covers setting up simple mocks with status codes, complex mocks with request and response bodies, and advanced matching options. ```APIDOC ## Mocking and Interactions ### Description Internally, WireMock is used for defining mocks and asserting interactions. ### Defining Mocks #### Simple Mocks (Status Only) ```gherkin Given that posting on "http://backend/users" will return a status CREATED_201 Given that putting on "http://backend/test/someValue" will return a status OK_200 ``` #### Mocking with Wildcards ```gherkin # wildcard on any resource and returning a status Given that calling "http://backend/.*" will return a status BAD_GATEWAY ``` #### Mocks with Response Body ```gherkin Given that calling "http://backend/hello" will return: """ message: Hello world! """ ``` #### Mocks with Status and Response Body ```gherkin Given that calling "http://backend/hello" will return a status FORBIDDEN_403 and: """ error_message: run fools! """ ``` #### Mocks with Delay ```gherkin Given that calling "http://backend/hello" will take 10ms to return a status OK and "Hello you!" ``` ### Detailed Mock Definitions ```gherkin Given that "http://backend/something" is mocked as: """ request: method: POST body: type: User payload: name: bob id: 1 response: status: ACCEPTED """ ``` ### Request Body Matching Options By default, the body of a request will match against a mock if the request body contains at least all the fields and array elements of the mock. #### Matching Exactly (No Extra Fields) Use the keyword `only` to specify a body which will only be matched if there is no extra field. ```gherkin Given that "http://backend/something" is mocked as only: """ request: method: POST headers: # to match as JSON Content-Type: application/json body: payload: nonOrderedArray: - c - a - b response: status: ACCEPTED """ ``` #### Matching Order (Arrays) Use `only and in order` or `exactly` if you want to also match the order of the array elements. ```gherkin Given that "http://backend/something" is mocked as only and in order: """ request: method: POST headers: # to match as JSON Content-Type: application/json body: payload: myOrderedArray: - a - b - c response: status: ACCEPTED """ ``` ``` -------------------------------- ### Mock Browser HTTP Request with Gherkin Syntax Source: https://github.com/decathlon/tzatziki/wiki/Module-:-Tzatziki-front Defines how to mock an external API call made by the browser using Gherkin syntax. This allows for simulating specific request methods, bodies, and response statuses for testing purposes. ```gherkin Given that in browser "http://backend/something" is mocked as: """ request: method: POST body: type: User payload: name: bob id: 1 response: status: ACCEPTED """ ``` -------------------------------- ### CSS Selector Referential with Variables (YAML) Source: https://github.com/decathlon/tzatziki/wiki/Module-:-Tzatziki-front Shows how to define CSS selectors with placeholders in YAML that can be dynamically filled using Gherkin. ```yaml mui-button: "//button[contains(@class,'MuiButton-root') and @aria-label=%1]" ``` -------------------------------- ### Conditional Execution with 'if' Guard in Gherkin Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Shows how to use the 'if =>' syntax in Gherkin to conditionally execute steps based on a given predicate. ```gherkin Given that user is a User: """ id: 1 name: bob """ # this step will be skipped Then if user.id > 1 => user.name is equal to "tom" But if user.id == 1 => user.name is equal to "bob" ``` -------------------------------- ### Configure Logger Levels and Pattern (Java) Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-logback/README.md Provides static Java methods to programmatically set the default logger level, a specific logger level, and the default log pattern. ```java static { LoggerSteps.setDefaultLevel(Level.INFO); LoggerSteps.setLoggerlevel("com.decathlon.steps.YourSteps", Level.DEBUG); Logger.setDefaultPattern("%d %-5p [%c{1}] %m%n") } ``` -------------------------------- ### Gherkin Syntax for Asserting HTTP Status and Response Body Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Demonstrates asserting both the HTTP status (e.g., OK) and the response body content in a single Gherkin step. ```gherkin Then we receive a status OK and: """ message: Hello user! """ ``` -------------------------------- ### Writing to a File in Gherkin Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Shows the Gherkin syntax for writing content to a specified file path. The content is provided in a multi-line string, typically formatted as YAML. ```gherkin # WRITE Given that we output in "path/to/file": """ yml id: 1 name: bob """ ``` -------------------------------- ### Gherkin: Match single and repeated query parameters Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Demonstrates matching single query parameters using regex and handling repeated parameters with WireMock's including() matcher. It also shows how repeated parameters are exposed as arrays in Handlebars templates. ```gherkin Given that calling "http://backend/endpoint?item=1&item=2" will return a status OK_200 # These also match the same mock: When we call "http://backend/endpoint?item=2&item=1" # order swap When we call "http://backend/endpoint?item=1&item=2&item=3" # extra value allowed # Accessing repeated param values in template Given that calling "http://backend/collect?item=1&item=2" will return: """ items: \{{request.query.item}} """ ``` -------------------------------- ### Configure Maven Surefire Plugin for Parallel Execution Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-testng/README.md This XML configuration snippet sets up the Maven Surefire plugin to run tests in parallel using TestNG. It defines the parallel execution strategy as 'methods' and sets the thread count, along with specifying the surefire-testng dependency. ```xml org.apache.maven.plugins maven-surefire-plugin 3.0.0-M9 methods 10 org.apache.maven.surefire surefire-testng 3.0.0-M9 ``` -------------------------------- ### Gherkin Syntax for Detailed HTTP Request with Headers and Body Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Shows a detailed Gherkin step for sending an HTTP request, specifying the method, headers, and a JSON payload. ```gherkin When we send on "http://backend/hello": """ method: POST headers: Some-Token: Some-Value body: payload: message: some value """ ``` -------------------------------- ### Gherkin - Using CSS Selector Referential with Variables Source: https://github.com/decathlon/tzatziki/wiki/Module-:-Tzatziki-front Illustrates using a CSS selector with a variable placeholder, providing the variable value directly in the Gherkin step. ```gherkin we perform a CLICK on click-button('Save') ``` -------------------------------- ### Gherkin Syntax for Mocks with Response Body and Status Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Illustrates defining HTTP mocks with both a specific status code and a response body using Gherkin. ```gherkin # payload Given that calling "http://backend/hello" will return: """ message: Hello world! """ # status and payload Given that calling "http://backend/hello" will return a status FORBIDDEN_403 and: """ error_message: run fools! """ ``` -------------------------------- ### Gherkin for Fetching Database Content Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-spring-jpa/README.md Demonstrates Gherkin steps to retrieve the content of a database table or entities. It also shows how to specify ordering for the fetched data. ```gherkin Then content is the users table content ``` ```gherkin Then content is the User entities ``` ```gherkin Then content is the users table content ordered by date_of_birth desc and date_of_death ``` ```gherkin Then content is the User entities ordered by date_of_birth desc and date_of_death ``` -------------------------------- ### Configuring auto-seek for topics in Java Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-spring-kafka/README.md Configures the Tzatziki Kafka integration to automatically seek through specified topics, ensuring deterministic offsets for testing. ```java KafkaSteps.autoSeekTopics("", ...); ``` -------------------------------- ### Cache Management Steps Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-spring/README.md Provides Gherkin steps for managing caches within tests. Supports clearing all caches or specific named caches, adding key-value pairs, and asserting the presence or absence of specific data within caches. ```gherkin When we clear all the caches ``` ```gherkin When we clear the users cache ``` ```gherkin Given that the cache nameOfTheCache will contain: """ key: value """ ``` ```gherkin Then the cache nameOfTheCache contains: """ key: value """ ``` ```gherkin And it is not true that the cache nameOfTheCache contains: """ key: value1 """ ``` -------------------------------- ### OpenSearch index content verification modes (Gherkin/YAML) Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-opensearch/README.md Demonstrates different comparison modes for verifying OpenSearch index contents using Gherkin and YAML. Supports exact match, 'contains' (partial match), and conditional execution with guards. ```gherkin # Exact match (default) Then the users index contains: """yaml - name: John Doe email: john@example.com """ # Contains (partial match) Then the users index contains at least: """yaml - name: John Doe """ # Using guards for conditional execution Then if the user exists, the users index contains: """yaml - name: John Doe """ ``` -------------------------------- ### Guard Clause Syntax in Java Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Illustrates the Java annotation syntax for defining a guard clause, combining `THAT`, `GUARD`, `VARIABLE`, and `NUMBER` patterns. ```java @Then(THAT + GUARD + VARIABLE + " (?:==|is equal to) " + NUMBER + "$") ``` -------------------------------- ### Using Built-in Assertion Flags Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Demonstrates various built-in assertion flags for flexible data validation, including regex, containment, numerical, null, and type checks. ```gherkin Then bob is equal to: """ id: 1 name: ?e b.* group: ?notNull """ ``` -------------------------------- ### Gherkin: Split and process path segments with Handlebars Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Demonstrates splitting a comma-separated path segment into a list and iterating over it using Handlebars' split and each helpers for dynamic response generation. ```gherkin Given that getting on "http://backend/v1/resource/items/(.*)" will return a List: """ \{{#split request.pathSegments.6 ','}} - item_id: \{{this}} \{{/split}} """ When we call "http://backend/v1/resource/items/1,2,3" Then we receive: """ - item_id: 1 - item_id: 2 - item_id: 3 """ ``` -------------------------------- ### Publish User Message Asynchronously Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-spring-kafka/README.md This Gherkin step publishes a 'user' message asynchronously to the 'users' topic. The test execution continues immediately after publishing. ```gherkin # asynchronously When this user is published on the users topic: """ id: 1 name: bob """ ``` -------------------------------- ### Gherkin Feature File for Spring Boot Service Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-spring/README.md This is a Gherkin feature file that defines a scenario for testing a Spring Boot service. It outlines the steps to call an endpoint and verify the response. ```gherkin Feature: a polite spring boot service Scenario: our service can greet us When we call "/hello" Then we receive "Hello world!" ``` -------------------------------- ### HTMLElement Interface Methods Source: https://github.com/decathlon/tzatziki/wiki/Module-:-Tzatziki-front Provides methods to retrieve information about HTML elements, such as their ID, classes, and attributes. ```java interface HTMLElement { String getId(); List getClasses(); Map getAttributes(); } ``` -------------------------------- ### Gherkin Syntax for Retrying HTTP Calls Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Demonstrates how to configure a Gherkin step to retry an HTTP call until a specific response is received, including response content matching. ```gherkin Then a user calling "http://backend/endpoint" receives: """ key: value """ ``` -------------------------------- ### Add tzatziki-opensearch dependency (Maven) Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-opensearch/README.md This XML snippet shows how to add the tzatziki-opensearch module as a test dependency in your Maven project. Ensure you use a compatible version. ```xml com.decathlon.tzatziki tzatziki-opensearch 1.0.x test ``` -------------------------------- ### Publish User Message with Headers Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-spring-kafka/README.md This Gherkin step publishes a 'user' message to the 'exposed-users' topic, including custom headers. It demonstrates how to test message headers in Kafka integration. ```gherkin When this user is published on the exposed-users topic: """ headers: uuid: some-id value: id: 1 name: bob """ ``` -------------------------------- ### Browser Interface Methods (Playwright) Source: https://github.com/decathlon/tzatziki/wiki/Module-:-Tzatziki-front Defines methods for browser interaction like navigation, element finding, and waiting. Accepts CSS or XPath selectors and may include optional timeout parameters. ```java interface Browser { void get(String url); List find(String cssSelector); void actionOn(String cssSelector, Action action, Map params); void waitForElement(String cssSelector, boolean isVisible); void waitForUrl(String url); void reload(); } ``` -------------------------------- ### Read/Write Environment Variables (Gherkin) Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Enables reading and writing environment variables at runtime using the `_env` context. This is useful for configuring tests dynamically or verifying environment settings. ```gherkin Scenario: we can access the ENVs from the test # see com.decathlon.tzatziki.utils.Env to see how we can set an environment variable at runtime Given that _env.TEST = "something" Then _env.TEST is equal to "something" ``` -------------------------------- ### Gherkin Syntax for Exact Order Array Matching in Mocks Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Illustrates using 'only and in order' keywords in Gherkin to define a mock where the request body array must match exactly and in the specified order. ```gherkin Given that "http://backend/something" is mocked as only and in order: """ request: method: POST headers: # to match as JSON Content-Type: application/json body: payload: myOrderedArray: - a - b - c response: status: ACCEPTED """ ``` -------------------------------- ### Conditional Execution with 'else' Guard in Gherkin Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Demonstrates using 'else' or 'otherwise' keywords in Gherkin for executing steps when a preceding 'if' condition is not met. ```gherkin Given that condition is "" When if == true => ran is "if" * else ran is "else" ``` -------------------------------- ### Using Custom Assertion Flags Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md Illustrates how to use a custom-defined assertion flag with parameters, such as checking if an integer is even and within a specified range. ```gherkin id: ?isEvenAndInBounds 1 | 2 ``` -------------------------------- ### Gherkin - Element Assertion Source: https://github.com/decathlon/tzatziki/wiki/Module-:-Tzatziki-front Gherkin steps for asserting the presence of elements on a page, optionally checking for visibility and specific attributes. ```gherkin the page contains 'cssSelector' (visible) (with attributes 'key1:value1', 'key2:value2'...) ``` -------------------------------- ### Gherkin: Capture URL path segments using regex and Handlebars Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Shows how to capture dynamic parts of a URL path using regular expressions and access them in mock responses. It also illustrates using WireMock's Handlebars syntax to access path segments. ```gherkin # using a regex Given that getting on "http://backend/v1/resource/item/(\d+)" will return: """ item_id: $1 """ # using the request object with WireMock Handlebars syntax Given that getting on "http://backend/v1/resource/item/(\d+)" will return: """ item_id: \{{request.pathSegments.6}} """ ``` -------------------------------- ### Remap URL for Mocked Hosts in Java Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-http/README.md Dynamically remaps mocked hosts to the local WireMock server. Allows overriding the default remapping behavior programmatically to target different hosts or ports. ```java httpSteps.setRelativeUrlRewriter(path -> "http://:%s".formatted(path)); ``` -------------------------------- ### Gherkin Inline Value Assignment Source: https://github.com/decathlon/tzatziki/blob/main/tzatziki-core/README.md This Gherkin snippet illustrates an inline method for assigning values to variables, offering a concise alternative to multi-line string content for simple values. ```gherkin Given that someVariable is: """ someValue """ ``` ```gherkin Given that someVariable is "someValue" ```