I am trying to unit test a Spring bean I implemented, but come across a difficulty here. This bean is to call a distant REST service on certain occasions.
However, in my tests, I would like it to call a mock servlet inside my test context, not a distant server.
The call is made using Apache's httpclient library, the URL is set in the applicationContext (so I can provide any fake URI to the bean when testing). The service should return a stream.
The call looks like the following:
HttpClient client = new DefaultHttpClient();
URIBuilder builder = new URIBuilder(theURIProvidedInContext);
// set parameters on builder
URI uri = builder.build();
HttpGet get = new HttpGet(uri);
HttpEntity entity = client.execute(get).getEntity();
return entity.getContent();
I searched Google all morning but only found how to unit-test servlets. Can anybody give some insight here?