Examples of RequestMatcher


Examples of org.springframework.test.web.client.RequestMatcher

  /**
   * Match to any request.
   */
  public static RequestMatcher anything() {
    return new RequestMatcher() {
      public void match(ClientHttpRequest request) throws AssertionError {
      }
    };
  }
View Full Code Here

Examples of org.springframework.test.web.client.RequestMatcher

   * @param matcher String matcher for the expected URI
   * @return the request matcher
   */
  public static RequestMatcher requestTo(final Matcher<String> matcher) {
    Assert.notNull(matcher, "'matcher' must not be null");
    return new RequestMatcher() {
      public void match(ClientHttpRequest request) throws IOException, AssertionError {
        MatcherAssert.assertThat("Request URI", request.getURI().toString(), matcher);
      }
    };
  }
View Full Code Here

Examples of org.springframework.test.web.client.RequestMatcher

   * @param method the HTTP method
   * @return the request matcher
   */
  public static RequestMatcher method(final HttpMethod method) {
    Assert.notNull(method, "'method' must not be null");
    return new RequestMatcher() {
      public void match(ClientHttpRequest request) throws AssertionError {
        AssertionErrors.assertEquals("Unexpected HttpMethod", method, request.getMethod());
      }
    };
  }
View Full Code Here

Examples of org.springframework.test.web.client.RequestMatcher

   * @param uri the expected URI
   * @return the request matcher
   */
  public static RequestMatcher requestTo(final URI uri) {
    Assert.notNull(uri, "'uri' must not be null");
    return new RequestMatcher() {
      public void match(ClientHttpRequest request) throws IOException, AssertionError {
        AssertionErrors.assertEquals("Unexpected request", uri, request.getURI());
      }
    };
  }
View Full Code Here

Examples of org.springframework.test.web.client.RequestMatcher

  /**
   * Assert request header values with the given Hamcrest matcher.
   */
  public static RequestMatcher header(final String name, final Matcher<? super String>... matchers) {
    return new RequestMatcher() {
      public void match(ClientHttpRequest request) {
        HttpHeaders headers = request.getHeaders();
        List<String> values = headers.get(name);
        AssertionErrors.assertTrue("Expected header <" + name + ">", values != null);
        AssertionErrors.assertTrue("Expected header <" + name + "> to have at least <" + matchers.length
View Full Code Here

Examples of org.springframework.test.web.client.RequestMatcher

   * @deprecated in favor of {@link #header(String, Matcher...)}
   */
  public static RequestMatcher headerContains(final String header, final String substring) {
    Assert.notNull(header, "'header' must not be null");
    Assert.notNull(substring, "'substring' must not be null");
    return new RequestMatcher() {
      public void match(ClientHttpRequest request) throws AssertionError {
        List<String> actualHeaders = request.getHeaders().get(header);
        AssertionErrors.assertTrue("Expected header <" + header + "> in request", actualHeaders != null);

        boolean foundMatch = false;
View Full Code Here

Examples of org.springframework.test.web.client.RequestMatcher

   * @deprecated in favor of {@link #content()} as well as {@code jsonPath(..)},
   * and {@code xpath(..)} methods in this class
   */
  public static RequestMatcher body(final String body) {
    Assert.notNull(body, "'body' must not be null");
    return new RequestMatcher() {
      public void match(ClientHttpRequest request) throws AssertionError, IOException {
        MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
        AssertionErrors.assertEquals("Unexpected body content", body, mockRequest.getBodyAsString());
      }
    };
View Full Code Here

Examples of org.springframework.test.web.client.RequestMatcher

  /**
   * Assert the request content type as a {@link MediaType}.
   */
  public RequestMatcher contentType(final MediaType expectedContentType) {
    return new RequestMatcher() {
      @Override
      public void match(ClientHttpRequest request) throws IOException, AssertionError {
        MediaType actualContentType = request.getHeaders().getContentType();
        assertTrue("Content type not set", actualContentType != null);
        assertEquals("Content type", expectedContentType, actualContentType);
View Full Code Here

Examples of org.springframework.test.web.client.RequestMatcher

  /**
   * Assert the request content type is compatible with the given
   * content type as defined by {@link MediaType#isCompatibleWith(MediaType)}.
   */
  public RequestMatcher contentTypeCompatibleWith(final MediaType contentType) {
    return new RequestMatcher() {
      @Override
      public void match(ClientHttpRequest request) throws IOException, AssertionError {
        MediaType actualContentType = request.getHeaders().getContentType();
        assertTrue("Content type not set", actualContentType != null);
        assertTrue("Content type [" + actualContentType + "] is not compatible with [" + contentType + "]",
View Full Code Here

Examples of org.springframework.test.web.client.RequestMatcher

  /**
   * Get the body of the request as a UTF-8 string and appply the given {@link Matcher}.
   */
  public RequestMatcher string(final Matcher<? super String> matcher) {
    return new RequestMatcher() {
      @Override
      public void match(ClientHttpRequest request) throws IOException, AssertionError {
        MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
        assertThat("Request content", mockRequest.getBodyAsString(), matcher);
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.