com.atlassian.sal.testresources.net
Class MockRequest

java.lang.Object
  extended by com.atlassian.sal.testresources.net.MockRequest
All Implemented Interfaces:
Request<MockRequest,MockResponse>

public class MockRequest
extends Object
implements Request<MockRequest,MockResponse>

Mock request that provides getters to all the information that is passed in, and also setters for the response body that should be returned for execute(), or the response that should be passed to the response handler.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.sal.api.net.Request
Request.MethodType
 
Constructor Summary
MockRequest(Request.MethodType methodType, String url)
           
 
Method Summary
 MockRequest addAuthentication(Authenticator authenticator)
          Adds generic Authenticator to the request.
 MockRequest addBasicAuthentication(String username, String password)
          Adds basic authentication to the request.
 MockRequest addHeader(String headerName, String headerValue)
          Adds the specified header to the request, not overwriting any previous value.
 MockRequest addRequestParameters(String... params)
          Sets parameters of the request.
 MockRequest addSeraphAuthentication(String username, String password)
          Adds seraph authentication to the request.
 MockRequest addTrustedTokenAuthentication()
          Adds TrustedTokenAuthentication to the request.
 MockRequest addTrustedTokenAuthentication(String username)
          Adds TrustedTokenAuthentication to the request.
 String execute()
          Executes a request and if response is successful, returns response as a string.
 void execute(ResponseHandler responseHandler)
          Executes the request.
<RET> RET
executeAndReturn(ReturningResponseHandler<MockResponse,RET> responseHandler)
          Executes the request and returns a result value.
 List<Authenticator> getAuthenticators()
           
 String getBasicPassword()
           
 String getBasicUser()
           
 int getConnectionTimeout()
           
 List<String> getHeader(String headerName)
           
 Map<String,List<String>> getHeaders()
           
 Request.MethodType getMethodType()
           
 String getRequestBody()
           
 String getRequestContentType()
           
 List<String> getRequestParameters()
           
 Response getResponse()
           
 String getSeraphPassword()
           
 String getSeraphUser()
           
 int getSoTimeout()
           
 String getTrustedTokenUser()
           
 String getUrl()
           
 boolean isTrustedTokenAuthentication()
           
 MockRequest setConnectionTimeout(int connectionTimeout)
          Setting connection timeout in milliseconds.
 MockRequest setEntity(Object entity)
          Set an entity as the request body
 MockRequest setFiles(List<RequestFilePart> files)
          Sets file parts of the request.
 MockRequest setFollowRedirects(boolean follow)
          Sets whether the request should transparently follow a redirect from the server.
 MockRequest setHeader(String headerName, String headerValue)
          Sets the specified header to the request, overwriting any previous value.
 MockRequest setRequestBody(String requestBody)
          Sets the body of the request.
 MockRequest setRequestContentType(String contentType)
          Sets Content-Type of the body of the request.
 void setResponse(MockResponse response)
           
 void setResponseBody(String responseBody)
           
 MockRequest setSoTimeout(int soTimeout)
          Setting socket timeout in milliseconds.
 MockRequest setUrl(String url)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockRequest

public MockRequest(Request.MethodType methodType,
                   String url)
Method Detail

setConnectionTimeout

public MockRequest setConnectionTimeout(int connectionTimeout)
Description copied from interface: Request
Setting connection timeout in milliseconds.

Specified by:
setConnectionTimeout in interface Request<MockRequest,MockResponse>
Parameters:
connectionTimeout - The timeout in milliseconds
Returns:
a reference to this object.

setSoTimeout

public MockRequest setSoTimeout(int soTimeout)
Description copied from interface: Request
Setting socket timeout in milliseconds.

Specified by:
setSoTimeout in interface Request<MockRequest,MockResponse>
Parameters:
soTimeout - the timeout in milliseconds
Returns:
a reference to this object.

setUrl

public MockRequest setUrl(String url)
Specified by:
setUrl in interface Request<MockRequest,MockResponse>
Parameters:
url - the url to request
Returns:
a reference to this object.

setRequestBody

public MockRequest setRequestBody(String requestBody)
Description copied from interface: Request
Sets the body of the request. In default implementation only requests of type Request.MethodType.POST and Request.MethodType.PUT can have a request body.

Specified by:
setRequestBody in interface Request<MockRequest,MockResponse>
Parameters:
requestBody - the body of the request
Returns:
a reference to this object.

setFiles

public MockRequest setFiles(List<RequestFilePart> files)
Description copied from interface: Request
Sets file parts of the request. File parts can only be added if the request body is empty. Only requests of type Request.MethodType.POST and Request.MethodType.PUT can have file parts.

Specified by:
setFiles in interface Request<MockRequest,MockResponse>
Parameters:
files - the file parts, cannot be null.
Returns:
a reference to this object.

setEntity

public MockRequest setEntity(Object entity)
Description copied from interface: Request
Set an entity as the request body

Specified by:
setEntity in interface Request<MockRequest,MockResponse>
Parameters:
entity - the request entity to be marshalled, not null
Returns:
this Request object

setRequestContentType

public MockRequest setRequestContentType(String contentType)
Description copied from interface: Request
Sets Content-Type of the body of the request. In default implementation only requests of type Request.MethodType.POST and Request.MethodType.PUT can have a request body.

Specified by:
setRequestContentType in interface Request<MockRequest,MockResponse>
Parameters:
contentType - the contentType of the request
Returns:
a reference to this object.

addRequestParameters

public MockRequest addRequestParameters(String... params)
Description copied from interface: Request
Sets parameters of the request. In default implementation only requests of type Request.MethodType.POST can have parameters. For other requests include parameters in url. This method accepts an even number of arguments, in form of name, value, name, value, name, value, etc

Specified by:
addRequestParameters in interface Request<MockRequest,MockResponse>
Parameters:
params - parameters of the request in as name, value pairs
Returns:
a reference to this object.

addHeader

public MockRequest addHeader(String headerName,
                             String headerValue)
Description copied from interface: Request
Adds the specified header to the request, not overwriting any previous value. Support for this operation is optional.

Specified by:
addHeader in interface Request<MockRequest,MockResponse>
Parameters:
headerName - the header's name
headerValue - the header's value
Returns:
a reference to this object
See Also:
RequestFactory.supportsHeader()

setHeader

public MockRequest setHeader(String headerName,
                             String headerValue)
Description copied from interface: Request
Sets the specified header to the request, overwriting any previous value. Support for this operation is optional.

Specified by:
setHeader in interface Request<MockRequest,MockResponse>
Parameters:
headerName - the header's name
headerValue - the header's value
Returns:
a reference to this object
See Also:
RequestFactory.supportsHeader()

setFollowRedirects

public MockRequest setFollowRedirects(boolean follow)
Description copied from interface: Request
Sets whether the request should transparently follow a redirect from the server. The default behavior is that when a response is received with a status code in the 300s, a new request is made using the location header of the response without notifying the client. Set this to false to turn this behavior off.

Specified by:
setFollowRedirects in interface Request<MockRequest,MockResponse>
Parameters:
follow - set this to false to have the request not transparently follow redirects.
Returns:
a reference to this object.

addAuthentication

public MockRequest addAuthentication(Authenticator authenticator)
Description copied from interface: Request
Adds generic Authenticator to the request.

Specified by:
addAuthentication in interface Request<MockRequest,MockResponse>
Parameters:
authenticator - the authenticator to use for authentication
Returns:
a reference to this object.

addTrustedTokenAuthentication

public MockRequest addTrustedTokenAuthentication()
Description copied from interface: Request
Adds TrustedTokenAuthentication to the request. Trusted token authenticator uses current user to make a trusted application call.

Specified by:
addTrustedTokenAuthentication in interface Request<MockRequest,MockResponse>
Returns:
a reference to this object.

addTrustedTokenAuthentication

public MockRequest addTrustedTokenAuthentication(String username)
Description copied from interface: Request
Adds TrustedTokenAuthentication to the request. Trusted token authenticator uses the passed user to make a trusted application call.

Specified by:
addTrustedTokenAuthentication in interface Request<MockRequest,MockResponse>
Parameters:
username - The user to make the request with
Returns:
this

addBasicAuthentication

public MockRequest addBasicAuthentication(String username,
                                          String password)
Description copied from interface: Request
Adds basic authentication to the request.

Specified by:
addBasicAuthentication in interface Request<MockRequest,MockResponse>
Parameters:
username - The user name
password - The password
Returns:
a reference to this object.

addSeraphAuthentication

public MockRequest addSeraphAuthentication(String username,
                                           String password)
Description copied from interface: Request
Adds seraph authentication to the request.

Specified by:
addSeraphAuthentication in interface Request<MockRequest,MockResponse>
Parameters:
username - The user name
password - The password
Returns:
a reference to this object.

executeAndReturn

public <RET> RET executeAndReturn(ReturningResponseHandler<MockResponse,RET> responseHandler)
                     throws ResponseException
Description copied from interface: Request
Executes the request and returns a result value.

Specified by:
executeAndReturn in interface Request<MockRequest,MockResponse>
Parameters:
responseHandler - Callback handler of the response.
Throws:
ResponseProtocolException - If the server returned a malformed response
ResponseTimeoutException - If a connection timeout or read timeout occurred
ResponseTransportException - If an I/O error occurred in request transport
ResponseException - For all errors not otherwise specified

execute

public void execute(ResponseHandler responseHandler)
             throws ResponseException
Description copied from interface: Request
Executes the request.

Specified by:
execute in interface Request<MockRequest,MockResponse>
Parameters:
responseHandler - Callback handler of the response.
Throws:
ResponseProtocolException - If the server returned a malformed response
ResponseTimeoutException - If a connection timeout or read timeout occurred
ResponseTransportException - If an I/O error occurred in request transport
ResponseException - For all errors not otherwise specified

execute

public String execute()
               throws ResponseException
Description copied from interface: Request
Executes a request and if response is successful, returns response as a string. @see Response.getResponseBodyAsString()

Specified by:
execute in interface Request<MockRequest,MockResponse>
Returns:
response as String
Throws:
ResponseStatusException - If the server returned a response that contained an error code
ResponseProtocolException - If the server returned a malformed response
ResponseTimeoutException - If a connection timeout or read timeout occurred
ResponseTransportException - If an I/O error occurred in request transport
ResponseException - For all errors not otherwise specified

getMethodType

public Request.MethodType getMethodType()

getUrl

public String getUrl()

getConnectionTimeout

public int getConnectionTimeout()

getSoTimeout

public int getSoTimeout()

getRequestBody

public String getRequestBody()

getRequestContentType

public String getRequestContentType()

getRequestParameters

public List<String> getRequestParameters()

getHeaders

public Map<String,List<String>> getHeaders()
Specified by:
getHeaders in interface Request<MockRequest,MockResponse>
Returns:
an immutable Map of headers added to the request so far

getHeader

public List<String> getHeader(String headerName)

getAuthenticators

public List<Authenticator> getAuthenticators()

isTrustedTokenAuthentication

public boolean isTrustedTokenAuthentication()

getTrustedTokenUser

public String getTrustedTokenUser()

getBasicUser

public String getBasicUser()

getBasicPassword

public String getBasicPassword()

getSeraphUser

public String getSeraphUser()

getSeraphPassword

public String getSeraphPassword()

getResponse

public Response getResponse()

setResponse

public void setResponse(MockResponse response)

setResponseBody

public void setResponseBody(String responseBody)


Copyright © 2015 Atlassian. All rights reserved.