This object provides an service that waits for http connections and delivers documents in a http stream
to the caller.
There is a default document that will be delivered for any
URL
given.
You may change this default document by invoking
addRecource(String pathOfUrl, String documentContent, String mimeTyp)
or
addRecource(String pathOfUrl, File document, String mimeTyp).
on the created instance of
de.tt.mns4j.http.MockHttpServer with pathOfUrl = "/".
Of cause you can have unique documents for certain
URL.
To do this have your unittest call either
addRecource(String pathOfUrl, String documentContent, String mimeTyp)
or
addRecource(String pathOfUrl, File document, String mimeTyp).
The resource will be added to a map with the pathName as key ande the resorce as value. If you gave different resources for the same path a request against the mock server instance will return the last one.
Its always important to test failure conditions on your code. But for instance how do you force an apache http server to deliver a http 500 error when your unittest needs it? With mns4j this is easy: just let your unittest call addRecourceFailing(String pathOfUrl, int errorNumber) on the de.tt.mns4j.http.MockHttpServer object. This will force the the mock server instance to send a HTTP-error errorNumber to the client that requested pathOfUrl.
Note that if you add a path here as well as with addResource() you will allways get the error returned.
You can get the current resources map when you call getResources(). The same is true for the errorRequests map with getErrorRequests(). later you can put back this maps using setResources(Map recourcesMap) or setErrorRequests(Map recourcesMap) respectively.
In case your code builds the path of the URLs dynamically and you want to check them you can get a list of requests received by the the mock server instance and process it with assertations. After processing this list you can reset it by calling clearRequestList().