Class MockRestClient.Builder

All Implemented Interfaces:
BeanStoreOverridable<MockRestClient.Builder>
Enclosing class:
MockRestClient

Builder class.
  • Constructor Details

    • Builder

      protected Builder()
      No-arg constructor.

      Provided so that this class can be easily subclassed.

  • Method Details

    • build

      Description copied from class: Context.Builder
      Build the object.
      Overrides:
      build in class RestClient.Builder<MockRestClient.Builder>
      Returns:
      The built object.
    • contextPath

      Identifies the context path for the REST resource.

      This value is used to deconstruct the request URL and set the appropriate URL getters on the HttpServletRequest object correctly.

      Should either be a value such as "/foo" or an empty string.

      The following fixes are applied to non-conforming strings.

      • nulls and "/" are converted to empty strings.
      • Trailing slashes are trimmed.
      • Leading slash is added if needed.
      Parameters:
      value - The context path.
      Returns:
      This object.
    • copy

      Description copied from class: Context.Builder
      Copy creator.
      Overrides:
      copy in class RestClient.Builder<MockRestClient.Builder>
      Returns:
      A new mutable copy of this builder.
    • debug

      Description copied from class: RestClient.Builder
      Sets the value for the Debug request header on all requests.

      This is a shortcut for calling headerData().append(Debug.of(value)).

      Overrides:
      debug in class RestClient.Builder<MockRestClient.Builder>
      Returns:
      This object.
      See Also:
    • parsers

      public MockRestClient.Builder parsers(Class<? extends Parser>... value)
      Description copied from class: RestClient.Builder
      Parsers.

      Associates the specified Parsers with the HTTP client.

      The parsers are used to parse the HTTP response body into a POJO.

      The parser that best matches the Accept header will be used to parse the response body.
      If no Accept header is specified, the first parser in the list will be used.

      Notes:
      Example:

      // Create a client that uses JSON and XML transport for response bodies. RestClient client = RestClient .create() .parser(JsonParser.class, XmlParser.class) .build();

      Overrides:
      parsers in class RestClient.Builder<MockRestClient.Builder>
      Parameters:
      value - The new value for this setting.
      The default value is JsonParser.DEFAULT.
      Returns:
      This object.
    • pathVars

      Add resolved path variables to this client.

      Allows you to add resolved parent path variables when performing tests on child resource classes.

      Example:

      // A parent class with a path variable. @Rest( path="/parent/{foo}", children={ Child.class } ) public class Parent { ... } // A child class that uses the parent path variable. @Rest public class Child { @RestGet public String get(@Path("foo") String foo) { return foo; } }

      // Test the method that uses the parent path variable. MockRestClient .create(Child.class) .json5() .pathVars("foo","bar") .build() .get("/") .run() .assertStatus().asCode().is(200) .assertContent().is("bar");

      Needs review
      Parameters:
      value - The path variables.
      Returns:
      This object.
      See Also:
    • pathVars

      Add resolved path variables to this client.

      Identical to pathVars(Map) but allows you to specify as a list of key/value pairs.

      Parameters:
      pairs - The key/value pairs. Must be an even number of parameters.
      Returns:
      This object.
    • restBean

      Specifies the Rest-annotated bean class or instance to test against.
      Parameters:
      value - The Rest-annotated bean class or instance.
      Returns:
      This object.
    • restContext

      Specifies the RestContext created for the REST bean.
      Parameters:
      value - The RestContext created for the REST bean.
      Returns:
      This object.
    • overridingBeanStore

      Installs a BeanStore as the overridingParent of the RestContext's bean store, so test-time overrides (e.g. TestBeanStore) resolve at tier 1 of the lookup chain — above the resource's local @Bean factory entries.

      Setting this disables the per-resource RestContext cache for the duration of this build, so the overlay is not silently shared with a previously-cached instance.

      Specified by:
      overridingBeanStore in interface BeanStoreOverridable<MockRestClient.Builder>
      Parameters:
      value - The override layer. Can be null to clear a previously-set value.
      Returns:
      This object.
      Since:
      10.0.0
    • serializers

      public MockRestClient.Builder serializers(Class<? extends Serializer>... value)
      Description copied from class: RestClient.Builder
      Serializers.

      Associates the specified Serializers with the HTTP client.

      The serializer is used to serialize POJOs into the HTTP request body.

      The serializer that best matches the Content-Type header will be used to serialize the request body.
      If no Content-Type header is specified, the first serializer in the list will be used.

      Notes:
      Example:

      // Create a client that uses JSON and XML transport for request bodies. RestClient client = RestClient .create() .serializers(JsonSerializer.class, XmlSerializer.class) .sortCollections() // Sort any collections being serialized. .build();

      Overrides:
      serializers in class RestClient.Builder<MockRestClient.Builder>
      Parameters:
      value - The new value for this setting.
      The default is JsonSerializer.
      Returns:
      This object.
    • servletPath

      Identifies the servlet path for the REST resource.

      This value is used to deconstruct the request URL and set the appropriate URL getters on the HttpServletRequest object correctly.

      Should either be a value such as "/foo" or an empty string.

      The following fixes are applied to non-conforming strings.

      • nulls and "/" are converted to empty strings.
      • Trailing slashes are trimmed.
      • Leading slash is added if needed.
      Parameters:
      value - The context path.
      Returns:
      This object.
    • suppressLogging

      Suppress logging on this client.
      Returns:
      This object.