com.github.kristofa.test.http
Class SimpleHttpResponseProvider

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

public class SimpleHttpResponseProvider
extends AbstractHttpResponseProvider

HttpResponseProvider that keeps expected request/responses in memory. Its purpose is to match simple requests that can be easily programmatically defined in code. It supports matching:

It does not support other http headers than Content-Type. If other http header parameters are present in HttpRequest they will be ignored.

Author:
kristof
See Also:
MockHttpServer

Constructor Summary
SimpleHttpResponseProvider()
           
 
Method Summary
 SimpleHttpResponseProvider expect(Method method, String path)
          Provide an expected request without content.
 SimpleHttpResponseProvider expect(Method method, String path, String contentType, String requestEntity)
          Provide an expected request with content.
 void reset()
          Reset the response provider to its original state
 SimpleHttpResponseProvider respondWith(int httpCode, String contentType, String requestEntity)
          Provide expected response for latest given request.
 
Methods inherited from class com.github.kristofa.test.http.AbstractHttpResponseProvider
addExpected, addHttpRequestMatchingFilter, getResponse, lazyInitializeExpectedRequestsAndResponses, resetState, verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleHttpResponseProvider

public SimpleHttpResponseProvider()
Method Detail

expect

public SimpleHttpResponseProvider expect(Method method,
                                         String path,
                                         String contentType,
                                         String requestEntity)
Provide an expected request with content.

Parameters:
method - HTTP method.
path - Path. Path can contain query parameters, eg: path?a=b&b=c
contentType - Content type.
requestEntity - Request entity as string.
Returns:
current SimpleHttpResponseProvider. Allows chaining calls.

expect

public SimpleHttpResponseProvider expect(Method method,
                                         String path)
Provide an expected request without content.

Parameters:
method - HTTP method.
path - Path. Path can contain query parameters, eg: path?a=b&b=c
Returns:
current SimpleHttpResponseProvider. Allows chaining calls.

respondWith

public SimpleHttpResponseProvider respondWith(int httpCode,
                                              String contentType,
                                              String requestEntity)
Provide expected response for latest given request.

Parameters:
httpCode - Http response code.
contentType - Content type.
requestEntity - Data.
Returns:
current SimpleHttpResponseProvider. Allows chaining calls.

reset

public void reset()
Reset the response provider to its original state



Copyright © 2014. All Rights Reserved.