hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPCLIENT-1759) Contribute new tests that use the in-process HttpServer
Date Thu, 11 May 2017 07:41:04 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1759?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16006026#comment-16006026

ASF GitHub Bot commented on HTTPCLIENT-1759:

Github user asfgit closed the pull request at:


> Contribute new tests that use the in-process HttpServer
> -------------------------------------------------------
>                 Key: HTTPCLIENT-1759
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1759
>             Project: HttpComponents HttpClient
>          Issue Type: Test
>          Components: HttpClient (classic)
>    Affects Versions: 5.0 Alpha2
>            Reporter: John Lewis
>            Assignee: Oleg Kalnichevski
>              Labels: patch, test
>             Fix For: 5.0 Alpha2
>         Attachments: patch.txt
> Please accept this contribution of new tests that use the in-process HttpServer similar
to the way it is used with the LocalServerTestBase.  A special request handler is used to
check HTTP requests.  Before the request is sent, the request handler is told what to expect
in the request as far as headers, parameters, path, content type, and body are concerned.
 The handler checks the request against the expectations.  Then, the handler is also told
what response to return, and the response is checked when the HTTP client receives the response.
> Every HTTP method is tested in this way.
> The tests use a testing framework that is is designed to work with any HTTP client. 
For instance Groovy's HttpBuilder and RESTClient use the Apache HttpClient to make HTTP requests.
 The testing framework here can test the HttpBuilder and RESTClient as well as HttpClient.
 There just has to be an adapter for each HTTP client.  I have included one for Apache HttpClient5.
> Since I would like to reuse the test framework for other projects, I have not put the
framework in the test area so it can potentially be used for any project that uses HttpClient
to run the same tests or create new tests.  Care has been taken to make sure no testing dependency
such as JUnit or EasyMock is used in the framework.
> I used test-first development when creating this test framework.  So, I have submitted
a lot of tests which I put under the test area.
> Usage.  Generally, the idea is that you specify a test with a set of List's and Map's.
 If you write the test with Groovy, it could look something like this:
> {noformat}
>           final HttpServerTestingFramework framework = new HttpServerTestingFramework(new
>           framework.addTest(
>                               request: [
>                                   path: '/stuff',
>                                   method:'GET',
>                                   query: [param : 'something'],
>                                   headers: [header1:'stuff', header2:'more-stuff'],
>                                   contentType: 'text/plain; charset=us-ascii',
>                                   body: 'What is the meaning of life?',
>                               ],
>                               response: [
>                                   status:201,
>                                   headers: [header3:'header_stuff',],
>                                   contentType: 'text/html; charset=us-ascii',
>                                   body: '<HTML>42</HTML>',
>                               ],
>           )
>           framework.runTests();
> {noformat}
> There is also a set of tests that are created by default that exercise all of the HTTP
methods.  If you don't want these tests to run, then just delete the tests after creating
the framework:
>           framework.deleteTests();
> You can see TestHttpServerTestingFramework.java to see how the framework is used to test
HttpClient5.  Especially the defaultTests() test:
> {noformat}
>     @Test
>     public void defaultTests() throws Exception {
>         final HttpServerTestingAdapter adapter = new HttpClient5TestingAdapter();
>         // create the framework without deleting the default tests.
>         final HttpServerTestingFramework framework = new HttpServerTestingFramework();
>         framework.setAdapter(adapter);
>         framework.runTests();
>     }
> {noformat}
> I have submitted a patch file.  There are no changes to the existing HttpClient code.
 All files in the patch are new, and they do not interfere with the current functionality
of HttpClient.  I created a new package called org.apache.hc.client5.http.*testframework*.

This message was sent by Atlassian JIRA

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

View raw message