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

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

public class FileHttpResponseProvider
extends AbstractHttpResponseProvider

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
protected  void lazyInitializeExpectedRequestsAndResponses()
          Override this method if you want to lazily initialize requests/responses.
 
Methods inherited from class com.github.kristofa.test.http.AbstractHttpResponseProvider
addExpected, addHttpRequestMatchingFilter, getResponse, resetState, verify
 
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

lazyInitializeExpectedRequestsAndResponses

protected void lazyInitializeExpectedRequestsAndResponses()
Override this method if you want to lazily initialize requests/responses.

This method will be called with the first call to AbstractHttpResponseProvider.getResponse(HttpRequest).

You can initialize expected requests and responses by calling AbstractHttpResponseProvider.addExpected(HttpRequest, HttpResponseProxy).

Overrides:
lazyInitializeExpectedRequestsAndResponses in class AbstractHttpResponseProvider


Copyright © 2014. All Rights Reserved.