接口 WebTestClient

所有已知实现类:
DefaultWebTestClient

public interface WebTestClient
Client for testing web servers that uses WebClient internally to perform requests while also providing a fluent API to verify responses. This client can connect to any server over HTTP, or to a WebFlux application via mock request and response objects.

Use one of the bindToXxx methods to create an instance. For example:

从以下版本开始:
4.0
作者:
Rossen Stoyanchev, Brian Clozel, Sam Brannen, Michał Rowicki, Harry Yang
另请参阅:
  • 字段详细资料

    • WEBTESTCLIENT_REQUEST_ID

      static final String WEBTESTCLIENT_REQUEST_ID
      The name of a request header used to assign a unique id to every request performed through the WebTestClient. This can be useful for storing contextual information at all phases of request processing (e.g. from a server-side component) under that id and later to look up that information once an ExchangeResult is available.
      另请参阅:
  • 方法详细资料

    • get

      Prepare an HTTP GET request.
      返回:
      a spec for specifying the target URL
    • head

      Prepare an HTTP HEAD request.
      返回:
      a spec for specifying the target URL
    • post

      Prepare an HTTP POST request.
      返回:
      a spec for specifying the target URL
    • put

      Prepare an HTTP PUT request.
      返回:
      a spec for specifying the target URL
    • patch

      Prepare an HTTP PATCH request.
      返回:
      a spec for specifying the target URL
    • delete

      Prepare an HTTP DELETE request.
      返回:
      a spec for specifying the target URL
    • options

      Prepare an HTTP OPTIONS request.
      返回:
      a spec for specifying the target URL
    • method

      WebTestClient.RequestBodyUriSpec method(cn.taketoday.http.HttpMethod method)
      Prepare a request for the specified HttpMethod.
      返回:
      a spec for specifying the target URL
    • mutate

      Return a builder to mutate properties of this web test client.
    • mutateWith

      WebTestClient mutateWith(WebTestClientConfigurer configurer)
      Mutate the WebTestClient, apply the given configurer, and build a new instance. Essentially a shortcut for:
       mutate().apply(configurer).build();
       
      参数:
      configurer - the configurer to apply
      返回:
      the mutated test client
    • bindToRouterFunction

      static WebTestClient.RouterFunctionSpec bindToRouterFunction(cn.taketoday.web.handler.function.RouterFunction<?> routerFunction)
      Use this option to set up a server from a RouterFunction. Internally the provided configuration is passed to RouterFunctions#toWebHandler. The resulting WebFlux application will be tested without an HTTP server using a mock request and response.
      参数:
      routerFunction - the RouterFunction to test
      返回:
      chained API to customize server and client config; use WebTestClient.MockServerSpec.configureClient() to transition to client config
    • bindToServer

      static WebTestClient.Builder bindToServer()
      This server setup option allows you to connect to a live server through a Reactor Netty client connector.

       WebTestClient client = WebTestClient.bindToServer()
               .baseUrl("http://localhost:8080")
               .build();
       
      返回:
      chained API to customize client config
    • bindToServer

      static WebTestClient.Builder bindToServer(cn.taketoday.http.client.reactive.ClientHttpConnector connector)
      A variant of bindToServer() with a pre-configured connector.
      返回:
      chained API to customize client config