Package dev.aherscu.qa.jgiven.rest.steps
Class RestVerifications<SELF extends RestVerifications<SELF>>
- java.lang.Object
-
- com.tngtech.jgiven.base.StageBase<SELF>
-
- com.tngtech.jgiven.Stage<SELF>
-
- dev.aherscu.qa.jgiven.commons.utils.StageEx<SELF>
-
- dev.aherscu.qa.jgiven.commons.steps.GenericVerifications<RestScenarioType,SELF>
-
- dev.aherscu.qa.jgiven.rest.steps.RestVerifications<SELF>
-
- Type Parameters:
SELF
- the type of the subclass
- All Implemented Interfaces:
dev.aherscu.qa.jgiven.commons.model.ScenarioType<RestScenarioType>
@ThreadSafe public class RestVerifications<SELF extends RestVerifications<SELF>> extends dev.aherscu.qa.jgiven.commons.steps.GenericVerifications<RestScenarioType,SELF>
Generic REST client verifications. Verifications on the response retrieved by previous action.- Author:
- aherscu
-
-
Field Summary
Fields Modifier and Type Field Description protected ThreadLocal<jakarta.ws.rs.core.Response>
closedResponse
The retrieved response in closed state.protected ThreadLocal<String>
responseContent
The retrieved response contents.
-
Constructor Summary
Constructors Constructor Description RestVerifications()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
attachActualResponse()
Attaches the actual response content, after first verification completed.protected <T> Supplier<T>
invoke(jakarta.ws.rs.client.Invocation invocation, Function<String,T> converter)
Creates a supplier which when called, executes specified invocation, stores the closed response and response content, and calls the specified converter on response content.SELF
the_response_contains_JSON(String expectedJson)
Verifies response has expected JSON contents.SELF
the_response_contents(Iterable<? extends dev.aherscu.qa.testing.utils.assertions.JsonAssertion<?>> expectedContents)
Verifies that the JSON data structure contained byResponse
matches several JSON key:matcher pairs.SELF
the_response_contents(org.hamcrest.Matcher<String> expected)
Verifies that theResponse
matches specified Hamcrest expression.SELF
the_response_status(org.hamcrest.Matcher<jakarta.ws.rs.core.Response.Status.Family> familyMatcher)
Verifies the response status family.-
Methods inherited from class dev.aherscu.qa.jgiven.commons.steps.GenericVerifications
beforeScenarioConfigurePolling, eventually, eventually, eventually_assert_that, should_succeed, the_file_$_should_contain, the_file_$_should_match, the_JSON_file_$_should_contain
-
-
-
-
Field Detail
-
responseContent
@ExpectedScenarioState protected ThreadLocal<String> responseContent
The retrieved response contents.
-
closedResponse
@ExpectedScenarioState protected ThreadLocal<jakarta.ws.rs.core.Response> closedResponse
The retrieved response in closed state.- See Also:
RestActions
-
-
Method Detail
-
the_response_contains_JSON
public SELF the_response_contains_JSON(String expectedJson)
Verifies response has expected JSON contents.- Parameters:
expectedJson
- the expected JSON contents- Returns:
StageBase.self()
-
the_response_contents
public SELF the_response_contents(Iterable<? extends dev.aherscu.qa.testing.utils.assertions.JsonAssertion<?>> expectedContents)
Verifies that the JSON data structure contained byResponse
matches several JSON key:matcher pairs.- Parameters:
expectedContents
- the expected contents, where each key is a JSON Path expression and the value is a Hamcrest matcher- Returns:
StageBase.self()
-
the_response_contents
public SELF the_response_contents(org.hamcrest.Matcher<String> expected)
Verifies that theResponse
matches specified Hamcrest expression.- Parameters:
expected
- the expected expression- Returns:
StageBase.self()
-
the_response_status
public SELF the_response_status(org.hamcrest.Matcher<jakarta.ws.rs.core.Response.Status.Family> familyMatcher)
Verifies the response status family.- Parameters:
familyMatcher
- matching expression- Returns:
StageBase.self()
-
invoke
protected final <T> Supplier<T> invoke(jakarta.ws.rs.client.Invocation invocation, Function<String,T> converter)
Creates a supplier which when called, executes specified invocation, stores the closed response and response content, and calls the specified converter on response content.Attaches the response.
- Type Parameters:
T
- the type expected from the converter- Parameters:
invocation
- a JAX-RS invocationconverter
- something to execute on response content- Returns:
- supplier that executes the specified invocation
-
attachActualResponse
@AfterStage protected void attachActualResponse()
Attaches the actual response content, after first verification completed.This is suitable when a synchronous verification is performed, i.e. when assuming that actions are always stable and the response might be verified multiple times.
Override with empty implementation to disable.
-
-