Class RestActions<SELF extends 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 given Client.
      protected ThreadLocal<jakarta.ws.rs.core.Response> closedResponse
      FIXME: this is a patch.
      protected ThreadLocal<String> responseContent
      The retrieved Response's contents.
      protected ThreadLocal<jakarta.ws.rs.client.WebTarget> target
      Target (WebTarget) of Web actions in this class.
      • Fields inherited from class dev.aherscu.qa.jgiven.commons.utils.StageEx

        assertElementTimer, ATTACHEMENT_TRANSFORMER, clickTimer, currentStep, locateTimer, pollDelay, pollTimeout, retryPolicy, scrollIntoViewTimer, sendKeysTimer
    • 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 a WebTarget object.
      SELF connecting_to​(String url)  
      SELF deleting()
      Deletes an entity and retrieves the Response.
      SELF deleting​(jakarta.ws.rs.core.MultivaluedMap<String,​Object> headers)
      Deletes an entity and retrieves the Response.
      SELF getting_the_response()
      Retrieves the Response.
      SELF getting_the_response_with_headers​(jakarta.ws.rs.core.MultivaluedMap<String,​Object> headers)
      Retrieves the Response.
      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 the Response.
      SELF posting​(jakarta.ws.rs.core.Form form)
      Posts a form and retrieves the Response.
      SELF putting​(jakarta.ws.rs.client.Entity<?> entity)
      Puts an entity and retrieves the Response.
      SELF putting​(jakarta.ws.rs.client.Entity<?> entity, jakarta.ws.rs.core.MultivaluedMap<String,​Object> headers)
      Puts an entity and retrieves the Response.
      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
      • Methods inherited from class dev.aherscu.qa.jgiven.commons.utils.StageEx

        alert, attach, attachScreenshot, attachScreenshot, attachScreenshot, beforeScenarioConfigurePolling, context, element, elements, ensureElements, retry, safely, scrollIntoView
      • Methods inherited from class com.tngtech.jgiven.Stage

        and, but, given, then, when, with
      • Methods inherited from class com.tngtech.jgiven.base.StageBase

        $, $, self
    • 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 retrieved Response's contents. We hold this as a string because reading the contents of a Response 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 given Client. This client is released upon scenario completion.
        See Also:
        RestVerifications
    • Constructor Detail

      • RestActions

        public RestActions()
    • Method Detail

      • connecting_to

        public SELF connecting_to​(@NotNull
                                  @NotNull URI url)
        Creates a WebTarget object.
        Parameters:
        url - the URL
        Returns:
        StageBase.self()
        Throws:
        NullPointerException - in case the supplied argument is null
        IllegalArgumentException - in case the supplied string is not a valid URI template
      • connecting_to

        public SELF connecting_to​(String url)
      • deleting

        public SELF deleting​(jakarta.ws.rs.core.MultivaluedMap<String,​Object> headers)
        Deletes an entity and retrieves the Response.
        Parameters:
        headers - headers to add
        Returns:
        StageBase.self()
        Throws:
        IllegalStateException - if connecting_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 the Response.
        Parameters:
        headers - the headers to be added to this request
        Returns:
        StageBase.self()
        Throws:
        IllegalStateException - if connecting_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 the Response.
        Parameters:
        entity - the entity to post
        headers - the header to add
        Returns:
        StageBase.self()
        Throws:
        IllegalStateException - if connecting_to(URI) has not been called before
      • posting

        public SELF posting​(jakarta.ws.rs.core.Form form)
        Posts a form and retrieves the Response.
        Parameters:
        form - the form to post
        Returns:
        StageBase.self()
        Throws:
        IllegalStateException - if connecting_to(URI) has not been called before
      • putting

        public SELF putting​(jakarta.ws.rs.client.Entity<?> entity)
        Puts an entity and retrieves the Response.
        Parameters:
        entity - the entity to put
        Returns:
        StageBase.self()
        Throws:
        IllegalStateException - if connecting_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 the Response.
        Parameters:
        entity - the entity to put
        headers - headers to add
        Returns:
        StageBase.self()
        Throws:
        IllegalStateException - if connecting_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 an Iterable, then its items are concatenated with comma delimiters
        name - the parameter's name
        Returns:
        StageBase.self()
        Throws:
        IllegalStateException - if connecting_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 - if connecting_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 invocation
        consumer - 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