Let's say I'm writing an application and I need to be able to do something like this:
String url = "https://someurl/";
GetMethod method = new GetMethod(URLEncoder.encode(url));
String content = method.getResponseBodyAsString();
Is there a way to provide a mock server that would let me handle the https request? What I'm looking for is a way to write unit tests, but I need to be able to mock the part that actually goes out to https://someurl so I can get a known response back.
You could always launch a
thttpd
server as part of your unit test to serve the requests locally. Though, ideally, you have a well testedGetMethod
, and then you can just mock it, and not have to actually have a remote server around for ALL of your tests.Resources
Use xml mimic stub server, that can simulate static http response based on request parameters, headers, etc. It is very simple to configure and use it.
http://xmlmimic.sourceforge.net/ http://sourceforge.net/projects/xmlmimic/