cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Wang <j...@plutom.com>
Subject Re: Unit testing JAX-RS services
Date Thu, 16 Feb 2012 02:54:26 GMT
Sorry, didn't see this message until just now...

On Fri, Feb 3, 2012 at 9:42 AM, Sergey Beryozkin <sberyozkin@gmail.com> wrote:
> On 03/02/12 03:02, Jeff Wang wrote:
>>
>> I'm having two difficulties with testing.  One practical, one theoretical.
>>
>> practical:
>> If I have any @Context annotations, I can't actually call the service
>> via a client proxy.  I need to code the call separately (and
>> manually.)
>>
> I updated the proxies to simply ignore explicit Context parameters, they are
> only populated on the server side...You'd need to pass 'null' if you have
> explicit Context params, in meantime try injecting Contexts into fields...

I've had @Context UriInfo turn up null before when field-injected
(same code works method injected), but that was a long time ago.  I'll
try this later today.

>> theoretical:
>> Using the same JSON compile unit on the service and the test seems to
>> defeat the purpose.  If I have a webpage hitting my JAX-RS server, and
>> I change the name of a field, I'd like to have my test point that out,
>> so that when I fix my test, I can let my web team know.  But if I use
>> the same compile unit, whatever I change, even accidentally, will
>> marshall and unmarshall correctly, the actual user of the API may then
>> run into issues.
>>
> I'm not sure I understand completely, but just in case, it's possible to
> adapt the in/out JSON sequences to the expected ones with the help of
> TransformFeature, but only if the default JSONProvider is used

What I mean is, let's say I have a Book object.  And I accidentally
add "asdf" to the name element of a field.  I would have broken every
single one of the actual clients that called Bookstore.findBook(id),
but if I use either a direct client call or a proxy, the tests would
pass.  Essentially, if you're using the same class file on the client
side and the server side, all you're really doing is testing that
marshall and unmarshall works (the framework.)  Not that your JAXB
mapping or CXF annotation is correct (the actual code that you need to
write.)

While testing the framework is useful and have pointed out some
mapping mistakes to me, I would bet that the majority of programmer
errors lie in the actual code, and not in the framework.

Jeff

>
> Sergey
>
>
>> Jeff

Mime
View raw message