[undertow-dev] Writing tests for HTTP handlers

Michael Hixson michael.hixson at gmail.com
Tue Aug 8 09:10:18 EDT 2017


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


More information about the undertow-dev mailing list