I have written a helper function that can retrieve content from a url. This function can also parse a Map of parameters and feed a url or a body on request depending on GET or POST method. Let’s say this function also do other things (change headers, cookies etc…). How can I test this function against an http(s) server ? How to simulate a fake servlet that will answer to the request made by this function ?
I’ve seen that we can use mock object, or other library that are specialized in servlet unit testing. But it doesn’t seem to fit my needs as I trully need to test the request and its answer without changing the function content.
I have written a helper function that can retrieve content from a url. This
Share
I would say to start up Jetty in embedded mode within your test.
Configure it to accept a request, validate it, and return an appropriate response.
See docs here: http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty