On 3/9/12 8:55 PM, Ludwig Magnusson wrote:
> Hi!
> I am having some trouble with setting up my first test case for
> jersey. The problem is that post/get paramaters I want to use in my
> tests. None of the parameters are included in the HttpServlerRequest
> on the receiving side. Everything else works such as post/get, content
> types and the different paths.
> I use the grizzly server for my tests.
> My test class extends JerseyTest and this is the code for my test that
> sends the post:
> WebResource webResource = resource().path("/mypath");
> webResource.queryParam(“foo”, "bar");
> String responseMsg = webResource.post(String.class);
> I have also tried:
> WebResource webResource = resource().path("/mypath");
> Form form = new Form();
> form.add(“foo”, “bar”);
> String responseMsg = webResource.post(String.class, form)
> Is there something worng with my tests?
most likely yes.
Can you please post the code where you're trying to access query params?
hint: it should look similarly to this:
@Path("mypath")
public class MyResource {
...
@POST
public String post(@QueryParam("foo") String foo) {
return "received query param foo = \"" + foo + "\"";
}
}
See "Extracting Request Parameters" chapter in our user guide:
http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e247
Pavel
> /Ludwig