Class MockRestClient.Builder
- All Implemented Interfaces:
BeanStoreOverridable<MockRestClient.Builder>
- Enclosing class:
- MockRestClient
MockRestClient.- Since:
- 9.2.1
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds and returns theMockRestClient.contextPath(String value) Sets the servlet context path (e.g.defaultParser(Parser value) Sets an explicit default parser used when the responseContent-Typematches no registered parser.noTrace()Sends aNo-Trace: true header with every request, so the server leaves the stack trace of a failed call out of its log record.overridingBeanStore(BeanStore value) Installs aBeanStoreas theoverridingParentof theRestContext's bean store, so test-time overrides (e.g.
-
Method Details
-
contextPath
Sets the servlet context path (e.g."/myapp").- Parameters:
value- The context path. May benull .- Returns:
- This object.
-
overridingBeanStore
Installs aBeanStoreas theoverridingParentof theRestContext's bean store, so test-time overrides (e.g.TestBeanStore) resolve at tier 1 of the lookup chain — above the resource's local@Beanfactory entries.Setting this disables the per-resource
RestContextcache 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:
overridingBeanStorein interfaceBeanStoreOverridable<MockRestClient.Builder>- Parameters:
value- The override layer. Can benull to clear a previously-set value.- Returns:
- This object.
- Since:
- 10.0.0
-
defaultParser
Sets an explicit default parser used when the responseContent-Typematches no registered parser.Setting this also causes the client to advertise the parser's media types in the
Acceptheader, 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 benull .- Returns:
- This object.
-
noTrace
Sends aNo-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 theMockRestClient.- Returns:
- A new instance. Never
null .
-