org.springframework.test.web.servlet.phpunit

Class HostRequestMatcher

  • java.lang.Object
    • org.springframework.test.web.servlet.phpunit.HostRequestMatcher
  • All Implemented Interfaces:
    WebRequestMatcher


    public final class HostRequestMatcher
    extends java.lang.Object
    implements WebRequestMatcher
    A WebRequestMatcher that allows matching on the host and optionally the port of WebRequest#getUrl().

    For example, the following would match any request to the host "code.jquery.com" without regard for the port.

    WebRequestMatcher cdnMatcher = new HostMatcher("code.jquery.com");

    Multiple hosts can also be passed in. For example, the following would match any request to the host "code.jquery.com" or the host "cdn.com" without regard for the port.

    WebRequestMatcher cdnMatcher = new HostMatcher("code.jquery.com", "cdn.com");

    Alternatively, one can also specify the port. For example, the following would match any request to the host "code.jquery.com" with the port of 80.

    WebRequestMatcher cdnMatcher = new HostMatcher("code.jquery.com:80");

    The above cdnMatcher would match "http://code.jquery.com/jquery.js" which has a default port of 80 and "http://code.jquery.com:80/jquery.js". However, it would not match "https://code.jquery.com/jquery.js" which has a default port of 443.

    Since:
    4.2
    Author:
    Rob Winch, Sam Brannen
    See Also:
    UrlRegexRequestMatcher, DelegatingWebConnection
    • Constructor Summary

      Constructors 
      Constructor and Description
      HostRequestMatcher(java.lang.String... hosts)
      Create a new HostRequestMatcher for the given hosts — for example: "localhost", "example.com:443", etc.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      boolean matches(com.gargoylesoftware.phpunit.WebRequest request)
      Whether this matcher matches on the supplied web request.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HostRequestMatcher

        public HostRequestMatcher(java.lang.String... hosts)
        Create a new HostRequestMatcher for the given hosts — for example: "localhost", "example.com:443", etc.
        Parameters:
        hosts - the hosts to match on
    • Method Detail

      • matches

        public boolean matches(com.gargoylesoftware.phpunit.WebRequest request)
        Description copied from interface: WebRequestMatcher
        Whether this matcher matches on the supplied web request.
        Specified by:
        matches in interface WebRequestMatcher
        Parameters:
        request - the WebRequest to attempt to match on
        Returns:
        true if this matcher matches on the WebRequest