ying lcs wrote:
I have the following code which uses HttpClient to do a post request.
Can you please tell tell me what is a good way to test it? Can I
create a mock http server object for the test to run against?

HttpClient cli = getClient();
HttpPost method;

method = new HttpPost(url);
HttpResponse resp = null;
resp = cli.execute(method);

Thank you.


Yes, you can.

There is a mock HTTP server implementation for HttpClient 3.x we use to test more complex HTTP scenarios:

http://svn.apache.org/repos/asf/httpcomponents/oac.hc3x/trunk/src/test/org/apache/commons/httpclient/server/

However, I would _strongly_ recommend using the testing framework of HttpClient 4.0 instead of the old 3.x stuff:

http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/localserver/

It is actually a complete, HTTP/1.1 compliant, embeddable HTTP server based on HttpCore, the same component stack used internally by HttpClient 4.0.

Hope this helps.

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to