com.github.kristofa.test.http.file
Class FileHttpResponseProvider

java.lang.Object
  extended by com.github.kristofa.test.http.file.FileHttpResponseProvider
All Implemented Interfaces:
HttpResponseProvider

public class FileHttpResponseProvider
extends Object
implements HttpResponseProvider

HttpResponseProvider that is able to serve responses for requests/responses previously saved by HttpRequestResponseFileLogger.

It supports submitting same request multiple times with different return result.

It reads all http requests on construction and keeps them in memory. It does not keep responses in memory. They are read from disk on request and not cached.

Author:
kristof
See Also:
HttpRequestResponseFileLogger, LoggingHttpProxy

Constructor Summary
FileHttpResponseProvider(String directory, String fileName)
          Creates a new instance.
FileHttpResponseProvider(String directory, String fileName, com.github.kristofa.test.http.file.HttpRequestFileReader requestFileReader, HttpResponseFileReader responseFileReader)
          Creates a new instance.
 
Method Summary
 HttpResponse getResponse(HttpRequest request)
          Gets expected response for given request.
 void verify()
          Should be executed when all requests have been submitted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileHttpResponseProvider

public FileHttpResponseProvider(String directory,
                                String fileName)
Creates a new instance. Will try to find request/response files and will throw unchecked exception in case:

Parameters:
directory - Directory from which to read files.
fileName - Base file name. Should not contain extension. Will be suffixed with sequence number and .txt extension. Should be same as used in HttpRequestResponseFileLogger.

FileHttpResponseProvider

public FileHttpResponseProvider(String directory,
                                String fileName,
                                com.github.kristofa.test.http.file.HttpRequestFileReader requestFileReader,
                                HttpResponseFileReader responseFileReader)
Creates a new instance. Will try to find request/response files and will throw unchecked exception in case:

Parameters:
directory - Directory from which to read files.
fileName - Base file name. Should not contain extension. Will be suffixed with sequence number and .txt extension. Should be same as used in HttpRequestResponseFileLogger.
requestFileReader - HTTP request file reader.
responseFileReader - HTTP response file reader.
Method Detail

getResponse

public HttpResponse getResponse(HttpRequest request)
Gets expected response for given request.

Specified by:
getResponse in interface HttpResponseProvider
Parameters:
request - HttpRequest.
Returns:
Response or null in case we don't know given request.

verify

public void verify()
            throws UnsatisfiedExpectationException
Should be executed when all requests have been submitted. Checks if all expected requests have been requested.

Specified by:
verify in interface HttpResponseProvider
Throws:
UnsatisfiedExpectationException - In case expectation were not as expected. See UnsatisfiedExpectationException.getMissingHttpRequests() and UnsatisfiedExpectationException.getUnexpectedHttpRequests() to get missing and unexpected requests.


Copyright © 2014. All Rights Reserved.