users@jersey.java.net

[Jersey] Re: Exceptions not being thrown when using JerseyTest

From: Vetle Leinonen-Roeim <vetle_at_roeim.net>
Date: Wed, 26 Mar 2014 08:57:38 +0100

Perhaps you could try to create a complete test case and share it with
us on Github?

On 26.03.14 01:29, Erik Holstad wrote:
> I tested the Grizzly, Jdk and InMemory factories and non of them are
> throwing the NPE, just seems like the fail silently, cause don't see any
> errors in the logs.
>
>
> On Tue, Mar 25, 2014 at 5:26 AM, Vetle Leinonen-Roeim <vetle_at_roeim.net>wrote:
>
>> Hi,
>>
>> What test container factory are you using? Is there a difference if you
>> another test container factory?
>>
>> Regards,
>> Vetle
>>
>> On 24.03.14 22:26, Erik Holstad wrote:
>>> I have a servlet that looks something like:
>>>
>>> @POST
>>> @Path("")
>>> @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
>>> @Produces(MediaType.APPLICATION_JSON)
>>> public Response createUser(@FormParam(Params.NAME)
>>> RequiredString name) {
>>>
>>> name.toString();
>>>
>>> return Response.ok().build();
>>> }
>>>
>>>
>>> Where RequiredString validates the input and throws a
>>> WebApplicationException if it fails.
>>>
>>> This works fine when I deploy the code to a server or even when I use the
>>> maven-jetty-plugin to run integration tests.
>>>
>>> The problem occurs when I run this using the JerseyTest class. Everything
>>> is fine when I pass in valid data into name, but as soon as I pass in
>> empty
>>> string or null I get a NPE from the toString() method on the name
>> variable
>>> instead of the WebApplicationException I would expect.
>>>
>>>
>>> When stepping through the code I see it going in to the code where the
>>> exception is being thrown, but it looks like it just fails silently and
>>> just continues the execution.
>>>
>>> Thoughts?
>>>
>>
>>
>
>