Class MockHttpEnvironment

java.lang.Object
com.vaadin.browserless.mocks.MockHttpEnvironment

public final class MockHttpEnvironment extends Object
The connection details every MockRequest reports.

There is no HTTP connection behind a browserless test, so the values a container would derive from one are read from here instead. Set one to put the application under test into the situation you want to assert on — setSecure(true) to exercise a code path that requires HTTPS, for example.

The values are global and are not reset between tests, so a test that changes one has to restore it afterwards, or later tests will see it.

For internal use only. May be renamed or removed in a future release.

  • Method Details

    • getLocalPort

      public static int getLocalPort()
      Returns the port MockRequest.getLocalPort() reports, i.e. the one the request was received on. Defaults to 8080.
      Returns:
      the local port
    • setLocalPort

      public static void setLocalPort(int localPort)
      Sets the port MockRequest.getLocalPort() reports.
      Parameters:
      localPort - the local port
    • getServerPort

      public static int getServerPort()
      Returns the port MockRequest.getServerPort() reports, i.e. the one the request was addressed to. Defaults to 8080.
      Returns:
      the server port
    • setServerPort

      public static void setServerPort(int serverPort)
      Sets the port MockRequest.getServerPort() reports.
      Parameters:
      serverPort - the server port
    • getRemotePort

      public static int getRemotePort()
      Returns the port MockRequest.getRemotePort() reports, i.e. the client's. Defaults to 8080.
      Returns:
      the remote port
    • setRemotePort

      public static void setRemotePort(int remotePort)
      Sets the port MockRequest.getRemotePort() reports.
      Parameters:
      remotePort - the remote port
    • getAuthType

      public static String getAuthType()
      Returns the authentication scheme MockRequest.getAuthType() reports, such as HttpServletRequest.FORM_AUTH.

      Defaults to null, i.e. the request is not authenticated — which is independent of the principal the request carries, set through MockRequest.setUserPrincipalInt(java.security.Principal).

      Returns:
      the authentication scheme, or null
    • setAuthType

      public static void setAuthType(String authType)
      Sets the authentication scheme MockRequest.getAuthType() reports.
      Parameters:
      authType - the authentication scheme, or null for an unauthenticated request
    • isSecure

      public static boolean isSecure()
      Tells whether MockRequest.isSecure() reports the request as having arrived over HTTPS. Defaults to false; nothing else about the request changes with it.
      Returns:
      true if requests are reported as secure
    • setSecure

      public static void setSecure(boolean isSecure)
      Sets whether MockRequest.isSecure() reports the request as having arrived over HTTPS.
      Parameters:
      isSecure - true to report requests as secure