Class MockRestClient.Builder

java.lang.Object
org.apache.juneau.rest.mock.MockRestClient.Builder
All Implemented Interfaces:
BeanStoreOverridable<MockRestClient.Builder>
Enclosing class:
MockRestClient

public static final class MockRestClient.Builder extends Object implements BeanStoreOverridable<MockRestClient.Builder>
Fluent builder for MockRestClient.
Since:
9.2.1
  • Method Details

    • contextPath

      Sets the servlet context path (e.g. "/myapp").
      Parameters:
      value - The context path. May be null.
      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.

      Example:

      var overlay = new TestBeanStore().override(MyService.class, mockSvc); try (client = MockRestClient.builder(MyResource.class) .overridingBeanStore(overlay) .build()) { client.get("/widgets/1").run().assertStatus().is(200); }

      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
    • defaultParser

      Sets an explicit default parser used when the response Content-Type matches no registered parser.

      Setting this also causes the client to advertise the parser's media types in the Accept header, so the server must be able to produce that content type. Omit this (the default) when the target resource does not have a JSON serializer configured.

      Example:

      try (client = MockRestClient.builder(MyJsonResource.class) .defaultParser(JsonParser.DEFAULT) .build()) { var api = client.getClient().remote(MyApi.class); api.someMethod(); }

      Parameters:
      value - The parser. May be null.
      Returns:
      This object.
    • noTrace

      Sends a No-Trace: true header with every request, so the server leaves the stack trace of a failed call out of its log record.

      Opt-in only; no other builder option turns it on. The one-line access record is still logged. To do the same for a single call, use RestRequest.noTrace().

      Example:

      try (client = MockRestClient.builder(MyResource.class).noTrace().build()) { client.get("/missing").run().assertStatus().is(404); }

      Returns:
      This object.
    • build

      Builds and returns the MockRestClient.
      Returns:
      A new instance. Never null.