Package com.vaadin.browserless.mocks
Class MockHttpEnvironment
java.lang.Object
com.vaadin.browserless.mocks.MockHttpEnvironment
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 Summary
Modifier and TypeMethodDescriptionstatic StringReturns the authentication schemeMockRequest.getAuthType()reports, such asHttpServletRequest.FORM_AUTH.static intReturns the portMockRequest.getLocalPort()reports, i.e. the one the request was received on.static intReturns the portMockRequest.getRemotePort()reports, i.e. the client's.static intReturns the portMockRequest.getServerPort()reports, i.e. the one the request was addressed to.static booleanisSecure()Tells whetherMockRequest.isSecure()reports the request as having arrived over HTTPS.static voidsetAuthType(String authType) Sets the authentication schemeMockRequest.getAuthType()reports.static voidsetLocalPort(int localPort) Sets the portMockRequest.getLocalPort()reports.static voidsetRemotePort(int remotePort) Sets the portMockRequest.getRemotePort()reports.static voidsetSecure(boolean isSecure) Sets whetherMockRequest.isSecure()reports the request as having arrived over HTTPS.static voidsetServerPort(int serverPort) Sets the portMockRequest.getServerPort()reports.
-
Method Details
-
getLocalPort
public static int getLocalPort()Returns the portMockRequest.getLocalPort()reports, i.e. the one the request was received on. Defaults to8080.- Returns:
- the local port
-
setLocalPort
public static void setLocalPort(int localPort) Sets the portMockRequest.getLocalPort()reports.- Parameters:
localPort- the local port
-
getServerPort
public static int getServerPort()Returns the portMockRequest.getServerPort()reports, i.e. the one the request was addressed to. Defaults to8080.- Returns:
- the server port
-
setServerPort
public static void setServerPort(int serverPort) Sets the portMockRequest.getServerPort()reports.- Parameters:
serverPort- the server port
-
getRemotePort
public static int getRemotePort()Returns the portMockRequest.getRemotePort()reports, i.e. the client's. Defaults to8080.- Returns:
- the remote port
-
setRemotePort
public static void setRemotePort(int remotePort) Sets the portMockRequest.getRemotePort()reports.- Parameters:
remotePort- the remote port
-
getAuthType
Returns the authentication schemeMockRequest.getAuthType()reports, such asHttpServletRequest.FORM_AUTH.Defaults to
null, i.e. the request is not authenticated — which is independent of the principal the request carries, set throughMockRequest.setUserPrincipalInt(java.security.Principal).- Returns:
- the authentication scheme, or
null
-
setAuthType
Sets the authentication schemeMockRequest.getAuthType()reports.- Parameters:
authType- the authentication scheme, ornullfor an unauthenticated request
-
isSecure
public static boolean isSecure()Tells whetherMockRequest.isSecure()reports the request as having arrived over HTTPS. Defaults tofalse; nothing else about the request changes with it.- Returns:
trueif requests are reported as secure
-
setSecure
public static void setSecure(boolean isSecure) Sets whetherMockRequest.isSecure()reports the request as having arrived over HTTPS.- Parameters:
isSecure-trueto report requests as secure
-