Package org.springframework.test.web.client

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


  /**
   * 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

  /**
   * 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

  /**
   * Get the body of the request as a UTF-8 string and compare it to the given String.
   */
  public RequestMatcher string(final String expectedContent) {
    return new RequestMatcher() {
      @Override
      public void match(ClientHttpRequest request) throws IOException, AssertionError {
        MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
        assertEquals("Request content", expectedContent, mockRequest.getBodyAsString());
      }
View Full Code Here

  /**
   * Compare the body of the request to the given byte array.
   */
  public RequestMatcher bytes(final byte[] expectedContent) {
    return new RequestMatcher() {
      @Override
      public void match(ClientHttpRequest request) throws IOException, AssertionError {
        MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
        assertEquals("Request content", expectedContent, mockRequest.getBodyAsBytes());
      }
View Full Code Here

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

   * @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() {
      @Override
      public void match(ClientHttpRequest request) throws IOException, AssertionError {
        assertThat("Request URI", request.getURI().toString(), matcher);
      }
    };
View Full Code Here

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

   * @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() {
      @Override
      public void match(ClientHttpRequest request) throws AssertionError {
        AssertionErrors.assertEquals("Unexpected HttpMethod", method, request.getMethod());
      }
    };
View Full Code Here

   * @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() {
      @Override
      public void match(ClientHttpRequest request) throws IOException, AssertionError {
        AssertionErrors.assertEquals("Unexpected request", uri, request.getURI());
      }
    };
View Full Code Here

TOP

Related Classes of org.springframework.test.web.client.RequestMatcher

Copyright © 2018 www.massapicom. 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.