Pavel,
Thanks for your response. Your test case works for me as well. When I was trimming down the code excerpts to include in my original email, I changed what was originally a constructor into a regular method call.
But it was in fact in a constructor that I was trying to access the init-params from ServletConfig. Am I right to understand that this is not possible? I seem to recall having read that the context injection was available to constructors, so I didn't think more of it at the time.
I worked around this by using a @PostConstruct method where I grabbed the init-params I needed for object construction. Would this be the recommended way to get at the init-params for object construction?
Thanks,
Eddie
On 17 May 2010, at 10:09 AM, Pavel Bucek wrote:
>
> Hello Edwin,
>
> this is strange, it works for me. I created minimal testcase and submitted it as GrizzlyWebInjectionTest test into jersey-test-framework-grizzly and it passes [1]. Does it work for you too?
>
> Regards,
> Pavel
>
> [1] https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/jersey-test-framework/jersey-test-framework-grizzly/src/test/java/com/sun/jersey/test/framework/impl/container/grizzlyweb/GrizzlyWebInjectionTest.java?rev=3677&view=markup
>
>
> On 5/16/10 4:15 AM, Edwin Shin wrote:
>> 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
>> ---------------------------------------------------------------------
>> 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
>