users@jersey.java.net

Testing with init-params

From: Edwin Shin <eddie_at_fedora-commons.org>
Date: Sun, 16 May 2010 04:15:36 +0200

Hello,

I'm having some trouble accessing init-params I've set in a test case.

In the test case constructor, I've set the init-params as follows:

  public FooTest() {
    super(new WebAppDescriptor.Builder("com.example.foo")
      .contextPath("foo")
      .initParam("foo", "quux").build());
  }

and then, within the actual class under test:

  @Context ServletConfig sc;
  public void doSomething() {
    assert sc != null;
    System.out.println(sc.getInitParam("foo"));
  }

However, I get a NullPointerException on the last statement above. Same result with either jersey-test-framework-grizzly and jersey-test-framework-inmemory.

I gathered from Paul's response here (https://jersey.dev.java.net/servlets/ReadMsg?list=users&msgNo=9234) that I should be able to do this. Any pointers as to what I might be doing wrong here?

Thanks in advance,
Eddie