Hi Tarjei,
What you present in your email is very similar to the testing
framework, for both embedded and in-memory. Below is an example of
such a test, reusing the unit test framework. The Jersey client API is
used to make in-memory requests/responses. Other tests utilize an
embedded server like Grizzly. You can also look at the sample, some of
which have tests.
Naresh is working on making the testing framework an API that others
can use. I think we should try and include and in-memory approach as
well.
Paul.
[1]
http://download.java.net/maven/2/com/sun/jersey/samples/helloworld/1.0/helloworld-1.0-project.zip
public class HttpMethodsTest extends AbstractResourceTester {
public HttpMethodsTest(String testName) {
super(testName);
}
@Path("/")
static public class Resource {
@HEAD
public void headMe() {
}
@GET
public String getMe() {
return "getMe";
}
@PUT
public String putMe(String s) {
assertEquals("putMe", s);
return "putMe";
}
@POST
public String postMe(String s) {
assertEquals("postMe", s);
return "postMe";
}
@DELETE
public String deleteMe() {
return "deleteMe";
}
}
public void testMethod() {
initiateWebApplication(Resource.class);
WebResource r = resource("/");
r.head();
assertEquals("getMe", r.get(String.class));
assertEquals("putMe", r.put(String.class, "putMe"));
assertEquals("postMe", r.post(String.class, "postMe"));
assertEquals("deleteMe", r.delete(String.class));
}
}
On Nov 12, 2008, at 4:16 PM, tarjei wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Paul Sandoz wrote:
>>
>> On Nov 12, 2008, at 11:46 AM, tarjei wrote:
>>
>> hi, is it possible to create UriBuilder in tests or do I have to use
>> EasyMock?
>>
>>
>>> It is possible to create a UrBuilder by doing:
>>
>>> UriBuilder.fromUri(...)
>>
>>> or using other static methods.
>>
>>> But i suspect you mean UriInfo as in the title.
>>
>>> The only way to create a Jersey-based instance is to deploy the
>>> tests
>>> using an embedded server. Quite a lot of the functional tests use an
>>> in-memory-based server, but still that is not the same as
>>> instantiating
>>> the resource classes yourself. So it is necessary to use something
>>> like
>>> EasyMock. If you have any ideas about how Jersey can make it
>>> easier in
>>> this respect let me know.
>
> Well, I don't know the Jersey internals, but I have often wished for a
> simple application test class. Something like:
>
> TestApp = new JerseyTest("http://baseuri/");
>
> TestApp.addService(new MyService());
>
> Response r = TestApp.GET("Http://baseuri/myservice/id/4", ..);
>
> Response r = TestApp.POST("Http://baseuri/myservice/id/4",
> "<?xml version="1.0" .. ", ..);
>
> This would make it possible to verify most of the annotations in a
> service without using some kind of webtest tool.
>
> I would guess that most of this infrastructure exists in the
> functional
> tests.
>
> A simpler approach would be to have versions of the injectable
> contexts
> that one can instantiate in unittests.
>
>
> kind regards,
> Tarjei
>
>
>>
>>> Paul.
>>
>>
>> Regards,
>> Tarjei
>>>
> -
> ---------------------------------------------------------------------
> 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
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFJGvNMYVRKCnSvzfIRAp7NAJ0eLvkG/dSha1c5dgZkA4T0PTqr+ACffHDU
> 6WYJwRC3npAvOwBpCXDv8vA=
> =CLz6
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>