users@jersey.java.net

RE: [Jersey] simplest unit test bootstrapping

From: Florian Hehlen <Florian.Hehlen_at_imc.nl>
Date: Wed, 10 Mar 2010 17:09:13 +0100

Hi,

Using Grizzly would be my first choice, but I am crippled by an environment where any testing dependencies will also end up in my production!

The other thing is that we are not using Hudson but good old fashion ant!

If I was using Grizzly would I be able to do tests like I suggested below? I think it is key to test that the URL binding is binding to the right methods. I have APIs with many many finder-methods that all return lists of a same entities. The key thing would be to have a single instance of a resource that I can access both by making direct method calls and restful calls.

Another key thing is that I would like to avoid having to use Spring in my unit tests. I would like to instantiate a Resource class, set it's dependencies by hand, and then wrap it in a jax-rs container.... Am I asking for to much?

Cheers,
Florian Hehlen

From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
Sent: Tuesday, March 02, 2010 10:14 AM
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] simplest unit test bootstrapping

Hi Florian,

Why don't you use say the Grizzly servlet support in conjunction with Spring and the Jersey test framework?

IMHO that would be the easiest approach rather than mocking things up. I realize this gets blurs the line between functional and unit testing but works rather well with JUnit. For automated testing it is important that you have a port management facility to avoid conflicts, Hudson provides such a feature.

Paul.

On Feb 23, 2010, at 5:11 PM, Florian Hehlen wrote:


NOTE: sorry if some of you have received this twice. I have sent it once earlier today but did not see it appear on the mailing list.

Hi,

I am building an app that combines Spring and JAX-RS. I am looking for the simplest way to test my resources(including the path bindings). What I would ideally like to do is to not use spring in my unit tests but just boot-strap an individual resource into the simplest HTTPContainerFactory and test it. The problem is that I can get the resource loaded but since some of the attributes of the resource are loaded by Spring I then get NullPointerExceptions when I try to test it.

Ideally I would like to create an instance of a resource, initialize it with all of its required members(which is usually done by Spring), and then hand it over to a some jersey context so that I can make resource calls on it. One thing that seems crucial for me to test with a restful app is that the resource calls actually land in the expected method calls. I use a fair bit of regular expressions and therefore would like to do the following type of test:


public void testGetDate() {

       assertEquals( myResource.getDate(1), resource().path("/event/1/date").get(Date.class) );
}

Is there any way to do this? I have been able to get tests boot-strapped as shown in the sample code but these assume you want to initialize a whole spring application. This in turn doing more than just a unit test and maintaining a lot of per-test spring configuration.

Cheers,
Florian


________________________________
The information in this e-mail is intended only for the person or entity to which it is addressed.

It may contain confidential and /or privileged material. If someone other than the intended recipient should receive this e-mail, he / she shall not be entitled to read, disseminate, disclose or duplicate it.

If you receive this e-mail unintentionally, please inform us immediately by "reply" and then delete it from your system. Although this information has been compiled with great care, neither IMC Financial Markets & Asset Management nor any of its related entities shall accept any responsibility for any errors, omissions or other inaccuracies in this information or for the consequences thereof, nor shall it be bound in any way by the contents of this e-mail or its attachments. In the event of incomplete or incorrect transmission, please return the e-mail to the sender and permanently delete this message and any attachments.

Messages and attachments are scanned for all known viruses. Always scan attachments before opening them.


________________________________
The information in this e-mail is intended only for the person or entity to which it is addressed.

It may contain confidential and /or privileged material. If someone other than the intended recipient should receive this e-mail, he / she shall not be entitled to read, disseminate, disclose or duplicate it.

If you receive this e-mail unintentionally, please inform us immediately by "reply" and then delete it from your system. Although this information has been compiled with great care, neither IMC Financial Markets & Asset Management nor any of its related entities shall accept any responsibility for any errors, omissions or other inaccuracies in this information or for the consequences thereof, nor shall it be bound in any way by the contents of this e-mail or its attachments. In the event of incomplete or incorrect transmission, please return the e-mail to the sender and permanently delete this message and any attachments.

Messages and attachments are scanned for all known viruses. Always scan attachments before opening them.