[undertow-dev] Writing tests for HTTP handlers

Tomaž Cerar tomaz.cerar at gmail.com
Tue Aug 8 10:41:53 EDT 2017


You could use DefaultServer junit runner for your tests.

Same "framework" that undertow tests are written with.

for example see
https://github.com/undertow-io/undertow/blob/master/core/src/test/java/io/undertow/server/handlers/file/FileHandlerTestCase.java

or pretty much any other test.

--
tomaz



On Tue, Aug 8, 2017 at 3:10 PM, Michael Hixson <michael.hixson at gmail.com>
wrote:

> Hello,
>
> I want to write junit tests for my application's HttpHandlers and I'm
> wondering what the best way to simulate a request/response exchange
> is.  How do other people go about this?
>
> My first thought was that I want to somehow:
>
> 1) Build up a valid HttpServerExchange object to represent my incoming
> request (likely the HTTP method, request URI, HTTP headers, and
> request entity/body would vary from test to test)
>
> 2) Instantiate my HttpHandler directly, and invoke its handleRequest
> method directly
>
> 3) Obtain a CompletableFuture that will complete when the exchange
> completes (possibly by adding an
> io.undertow.server.ExchangeCompletionListener to my exchange)
>
> 4) Verify the contents of the response (possibly by examining the
> HttpServerExchange object and by using an
> io.undertow.conduits.StoredResponseStreamSinkConduit to record the
> response entity)
>
> This would all happen without creating an Undertow instance or binding
> to any ports.
>
> I started writing my own mock request/response library classes and
> they're getting complicated enough that I'd rather reuse someone
> else's work here if possible.
>
> Maybe I'm going down the wrong path...  I could create an Undertow
> server instance and use something like a Jersey client to make actual
> HTTP requests.  Is that what other people do in their tests?
>
> -Michael
> _______________________________________________
> undertow-dev mailing list
> undertow-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/undertow-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20170808/53255012/attachment.html 


More information about the undertow-dev mailing list