Package dev.aherscu.qa.jgiven.rest.steps
Class RestActions<SELF extends RestActions<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.GenericActions<RestScenarioType,SELF>
-
- dev.aherscu.qa.jgiven.rest.steps.RestActions<SELF>
-
- Type Parameters:
SELF
- the type of the subclass
- All Implemented Interfaces:
dev.aherscu.qa.jgiven.commons.model.ScenarioType<RestScenarioType>
@ThreadSafe public class RestActions<SELF extends RestActions<SELF>> extends dev.aherscu.qa.jgiven.commons.steps.GenericActions<RestScenarioType,SELF>
Generic REST client actions. Act on previously set client. Each action closes the connection.- Author:
- aherscu
-
-
Field Summary
Fields Modifier and Type Field Description protected ThreadLocal<jakarta.ws.rs.client.Client>
client
The givenClient
.protected ThreadLocal<jakarta.ws.rs.core.Response>
closedResponse
FIXME: this is a patch.protected ThreadLocal<String>
responseContent
The retrievedResponse
's contents.protected ThreadLocal<jakarta.ws.rs.client.WebTarget>
target
Target (WebTarget
) of Web actions in this class.
-
Constructor Summary
Constructors Constructor Description RestActions()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SELF
appending_path(String path)
Appends a path.SELF
connecting_to(@NotNull URI url)
Creates aWebTarget
object.SELF
connecting_to(String url)
SELF
deleting()
Deletes an entity and retrieves theResponse
.SELF
deleting(jakarta.ws.rs.core.MultivaluedMap<String,Object> headers)
Deletes an entity and retrieves theResponse
.SELF
getting_the_response()
Retrieves theResponse
.SELF
getting_the_response_with_headers(jakarta.ws.rs.core.MultivaluedMap<String,Object> headers)
Retrieves theResponse
.protected Function<SELF,SELF>
invoke(jakarta.ws.rs.client.Invocation invocation)
Creates a step function which when called, executes specified invocation, stores the closed response and response content.protected Function<SELF,SELF>
invoke(jakarta.ws.rs.client.Invocation invocation, Consumer<String> consumer)
Creates a step function which when called, executes specified invocation, stores the closed response and response content, and calls the specified consumer on response content.protected SELF
invoke(Function<jakarta.ws.rs.client.Invocation.Builder,jakarta.ws.rs.core.Response> operation)
Invokes specified REST operation.SELF
posting(jakarta.ws.rs.client.Entity<?> entity, jakarta.ws.rs.core.MultivaluedMap<String,Object> headers)
Posts a form and retrieves theResponse
.SELF
posting(jakarta.ws.rs.core.Form form)
Posts a form and retrieves theResponse
.SELF
putting(jakarta.ws.rs.client.Entity<?> entity)
Puts an entity and retrieves theResponse
.SELF
putting(jakarta.ws.rs.client.Entity<?> entity, jakarta.ws.rs.core.MultivaluedMap<String,Object> headers)
Puts an entity and retrieves theResponse
.SELF
setting_$_into_query_param(Object value, String name)
Fills a value into a query parameter.-
Methods inherited from class dev.aherscu.qa.jgiven.commons.steps.GenericActions
comment, concatenate_$_files_from_$_into, deleting_directory, doing_nothing, doing_nothing, doing_nothing, failing_on_purpose_with, retrying, retrying, safely, safely
-
-
-
-
Field Detail
-
target
protected final ThreadLocal<jakarta.ws.rs.client.WebTarget> target
Target (WebTarget
) of Web actions in this class.
-
responseContent
@ProvidedScenarioState protected final ThreadLocal<String> responseContent
The retrievedResponse
's contents. We hold this as a string because reading the contents of aResponse
cannot be done twice.
-
closedResponse
@ProvidedScenarioState protected final ThreadLocal<jakarta.ws.rs.core.Response> closedResponse
FIXME: this is a patch. We should hold an extended version of Response that holds the contents as a string (see above responseContent field). Perhaps this should be done in the AutoCloseableResponse class. This has to be done in a separate version of this library in order no to break older clients.The retrieved
Response
in closed state.
-
client
@ExpectedScenarioState protected ThreadLocal<jakarta.ws.rs.client.Client> client
The givenClient
. This client is released upon scenario completion.- See Also:
RestVerifications
-
-
Method Detail
-
appending_path
public SELF appending_path(String path)
Appends a path.- Parameters:
path
- the path- Returns:
StageBase.self()
- Throws:
IllegalStateException
- ifconnecting_to(URI)
has not been called before
-
connecting_to
public SELF connecting_to(@NotNull @NotNull URI url)
Creates aWebTarget
object.- Parameters:
url
- the URL- Returns:
StageBase.self()
- Throws:
NullPointerException
- in case the supplied argument is nullIllegalArgumentException
- in case the supplied string is not a valid URI template
-
deleting
public SELF deleting()
Deletes an entity and retrieves theResponse
.- Returns:
StageBase.self()
- Throws:
IllegalStateException
- ifconnecting_to(URI)
has not been called before
-
deleting
public SELF deleting(jakarta.ws.rs.core.MultivaluedMap<String,Object> headers)
Deletes an entity and retrieves theResponse
.- Parameters:
headers
- headers to add- Returns:
StageBase.self()
- Throws:
IllegalStateException
- ifconnecting_to(URI)
has not been called before
-
getting_the_response
@NestedSteps public SELF getting_the_response()
Retrieves theResponse
.- Returns:
StageBase.self()
- Throws:
IllegalStateException
- ifconnecting_to(URI)
has not been called before
-
getting_the_response_with_headers
public SELF getting_the_response_with_headers(jakarta.ws.rs.core.MultivaluedMap<String,Object> headers)
Retrieves theResponse
.- Parameters:
headers
- the headers to be added to this request- Returns:
StageBase.self()
- Throws:
IllegalStateException
- ifconnecting_to(URI)
has not been called before
-
posting
public SELF posting(jakarta.ws.rs.client.Entity<?> entity, jakarta.ws.rs.core.MultivaluedMap<String,Object> headers)
Posts a form and retrieves theResponse
.- Parameters:
entity
- the entity to postheaders
- the header to add- Returns:
StageBase.self()
- Throws:
IllegalStateException
- ifconnecting_to(URI)
has not been called before
-
posting
public SELF posting(jakarta.ws.rs.core.Form form)
Posts a form and retrieves theResponse
.- Parameters:
form
- the form to post- Returns:
StageBase.self()
- Throws:
IllegalStateException
- ifconnecting_to(URI)
has not been called before
-
putting
public SELF putting(jakarta.ws.rs.client.Entity<?> entity)
Puts an entity and retrieves theResponse
.- Parameters:
entity
- the entity to put- Returns:
StageBase.self()
- Throws:
IllegalStateException
- ifconnecting_to(URI)
has not been called before
-
putting
public SELF putting(jakarta.ws.rs.client.Entity<?> entity, jakarta.ws.rs.core.MultivaluedMap<String,Object> headers)
Puts an entity and retrieves theResponse
.- Parameters:
entity
- the entity to putheaders
- headers to add- Returns:
StageBase.self()
- Throws:
IllegalStateException
- ifconnecting_to(URI)
has not been called before
-
setting_$_into_query_param
public SELF setting_$_into_query_param(Object value, String name)
Fills a value into a query parameter.- Parameters:
value
- the value; if the value is anIterable
, then its items are concatenated with comma delimitersname
- the parameter's name- Returns:
StageBase.self()
- Throws:
IllegalStateException
- ifconnecting_to(URI)
has not been called before
-
invoke
protected final SELF invoke(Function<jakarta.ws.rs.client.Invocation.Builder,jakarta.ws.rs.core.Response> operation)
Invokes specified REST operation.- Parameters:
operation
- the REST operation to invoke- Returns:
StageBase.self()
- Throws:
IllegalStateException
- ifconnecting_to(URI)
has not been called before
-
invoke
protected final Function<SELF,SELF> invoke(jakarta.ws.rs.client.Invocation invocation, Consumer<String> consumer)
Creates a step function which when called, executes specified invocation, stores the closed response and response content, and calls the specified consumer on response content.Attaches the response.
- Parameters:
invocation
- a JAX-RS invocationconsumer
- something to execute on response content- Returns:
- step function that executes the specified invocation
-
invoke
protected final Function<SELF,SELF> invoke(jakarta.ws.rs.client.Invocation invocation)
Creates a step function which when called, executes specified invocation, stores the closed response and response content.Attaches the response.
- Parameters:
invocation
- a JAX-RS invocation- Returns:
- step function that executes the specified invocation
-
-