com.github.kristofa.test.http
Class MockHttpServer

java.lang.Object
  extended by com.github.kristofa.test.http.MockHttpServer

public class MockHttpServer
extends Object

Mock Http Server which can be used to return upfront defined responses for a set of http requests.

Mock http server will in its default configuration return code 598 in case it receives a request which was not foreseen. In case of an internal exception it will return http returncode 599.

Author:
kristof

Nested Class Summary
 class MockHttpServer.ExpectationHandler
           
 
Field Summary
static String DELETE
           
static String GET
           
static String POST
           
static String PUT
           
 
Constructor Summary
MockHttpServer(int port, HttpResponseProvider responseProvider)
          Creates a new instance.
 
Method Summary
 void setExceptionResponseCode(int code)
          Allows to set a custom response code to be returned when an unexpected exception happens.
 void setNoMatchFoundResponseCode(int code)
          Allows you to set a custom response code to be returned when no matching response is found.
 void start()
          Starts the server.
 void stop()
          Closes the server.
 void verify()
          Verify if we got all requests as expected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GET

public static final String GET
See Also:
Constant Field Values

POST

public static final String POST
See Also:
Constant Field Values

PUT

public static final String PUT
See Also:
Constant Field Values

DELETE

public static final String DELETE
See Also:
Constant Field Values
Constructor Detail

MockHttpServer

public MockHttpServer(int port,
                      HttpResponseProvider responseProvider)
Creates a new instance.

Parameters:
port - Port on which mock server should operate.
responseProvider - HttpResponseProvider. Should not be null.
Method Detail

start

public void start()
           throws IOException
Starts the server.

Throws:
IOException - In case starting fails.

stop

public void stop()
          throws IOException
Closes the server.

Throws:
IOException - In case closing fails.

verify

public void verify()
            throws UnsatisfiedExpectationException
Verify if we got all requests as expected.

Throws:
UnsatisfiedExpectationException - In case we got unexpected requests or we did not get all requests we expected.

setNoMatchFoundResponseCode

public void setNoMatchFoundResponseCode(int code)
Allows you to set a custom response code to be returned when no matching response is found.

If not set the default code is 598.

Parameters:
code - HTTP response code to return when no matching response is found.

setExceptionResponseCode

public void setExceptionResponseCode(int code)
Allows to set a custom response code to be returned when an unexpected exception happens.

If not set the default code is 599.

Parameters:
code - HTTP response code to return when an unexpected exception happens.


Copyright © 2014. All Rights Reserved.