users@jersey.java.net

Re: [Jersey] "simple-servlet" sample tests

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 25 Sep 2008 16:03:20 +0200

On Sep 25, 2008, at 3:36 PM, Srinivas Naresh Bhimisetty wrote:

> Paul Sandoz wrote:
>> On Sep 25, 2008, at 8:24 AM, Srinivas Naresh Bhimisetty wrote:
>>
>>> Thanks Paul. I shall remember to check such things from the next
>>> time.
>>>
>>
>> No problem. When testing the simple atom server we may need to use
>> some XPath to extract IDs from atom feeds and entries. When you are
>> ready i can point you to some code using XPath for testing WADL.
> Paul, could you please send the pointers that you mentioned here?
> Next one is "simple-atom-server" :-)

See the following class in the jersey tests:

   com.sun.jersey.impl.wadl.WadlResourceTest

Is uses the XPath API to extract information.

For the case of checking atom IDs you could create an
javax.xml.xpath.XPathExpression that extracts from the InputStream
(wrapped in an InputSource).

Note two things for the atom example:

1) The URI of a newly created atom entry using POST will return a 201
created with the URI of the newly created
     entry in the location header. So you can get the Atom ID from
that URI. You can use UriComponent to parse
     the URI path and get the last path segment. Or use UriTemplate
and match it to extract the ID. You can also
     use a template to build,

    UriBuilder roBuilder = UriBulder.fromUri("<base>/
collection").path("{id}");
    UriBuilder editBuilder = UriBulder.fromUri("<base>/
collection").path("edit").path("{id}");

    String id = ...
    URI editUri = editBuilder.build(id);


2) The entries and feeds are stored on the file system, we probably
need to configure/change the location, to be
      a temporary location that is deleted after all tests have run.

Paul.

>
>>
>> Paul.
>>
>>> -Naresh
>>>
>>> Paul Sandoz wrote:
>>>> Hi Naresh,
>>>>
>>>> I am got a failure when i run the tests:
>>>>
>>>> Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed:
>>>> 5.775 sec <<< FAILURE!
>>>> testResources
>>>> (com
>>>> .sun.jersey.samples.servlet.resources.MasterResourceBeanTest)
>>>> Time elapsed: 5.704 sec <<< FAILURE!
>>>> junit.framework.AssertionFailedError: Expected reponse not seen
>>>> with query param '?rep=2'
>>>> at junit.framework.Assert.fail(Assert.java:47)
>>>> at junit.framework.Assert.assertTrue(Assert.java:20)
>>>> at
>>>> com
>>>> .sun
>>>> .jersey
>>>> .samples
>>>> .servlet
>>>> .resources
>>>> .MasterResourceBeanTest
>>>> .doTestResource3Page(MasterResourceBeanTest.java:200)
>>>> at
>>>> com
>>>> .sun
>>>> .jersey
>>>> .samples
>>>> .servlet
>>>> .resources
>>>> .MasterResourceBeanTest.testResources(MasterResourceBeanTest.java:
>>>> 115)
>>>>
>>>>
>>>> When the query parameter "rep" equals "2" then a form is
>>>> returned. You should be using Form instead of checking the
>>>> encoded value explicitly. I modified the code.
>>>>
>>>> Paul.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>