hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Unit testing HttpClient code
Date Sat, 31 Jan 2009 12:43:12 GMT
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: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message