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@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@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/undertow-dev