users@jersey.java.net

Re: [Jersey] Unit testing resources

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 30 Jun 2008 10:18:21 +0200

On Jun 27, 2008, at 4:49 PM, Martin Probst wrote:

>> Hmm... so we would need to 'mock up' stuff that could be injected
>> like UriInfo, HttpHeaders and Request with information that is
>> important for the test. There is actually not that much
>> information really, the full set is: the HTTP method, the base
>> URI, the request URI, and the list of headers. Do you have any
>> ideas how that could be easily expressed in such unit tests?
>
> Spring does this using a custom @RunWith, as said. So this could
> look like this:
>
> @RunWith(JerseyTestRunner)
> @Request(baseUri = "/foo")
> class MyUnitTest {
> // ... test methods ...
> @Test
> @Request(uri = "...", headers = { ... }, method = "...")
> public void testFoo() {
> ...
> }
> }
>
> If we don't need to repeat the method and uri in every test method,
> but can optionally declare it on the containing test class, this
> might actually be ok for users.
>

OK. As a pre-requisite we need an easy way to construct the UriInfo,
HttpHeaders and Request instances, currently they are too integrated
with runtime, i think it would be useful to separate the
functionality. Unfortunately i do not have any time to pursue this at
the moment :-(

Paul.