Hi David,
It is because you are using the in-memory test container which does
not support the servlet API. You need to use Grizzly so use "jersey-
test-framework-grizzly" instead of "jersey-test-framework-inmemory".
Paul.
On Dec 1, 2010, at 3:52 PM, David Dumon wrote:
> Hello,
>
> I'm beginning with jersey and trying to get freemarker working with
> it using TDD. I want to make a ViewProcessor for my templates, but
> fail to inject the servlet context in the class ...
>
> Here is the class code :
>
> @Provider
> public class myProcessor implements ViewProcessor<Template> {
>
> [...]
>
> @Context
> public ServletContext myContext;
>
> [...]
> }
>
> And here is the test code :
>
> public class myProcessorTest extends JerseyTest {
>
> public static myProcessor mp;
>
> public myProcessorTest() throws Exception{
> super(new WebAppDescriptor.Builder("com.domain").build());
> }
>
> @Test
> public void firstTest(){
> mp = new myProcessor();
> String path = new String("test.ftl");
> Template template = mp.resolve(path);
> assertNotNull(template);
> }
> }
>
> I use maven with dependencies as follow :
>
> <dependencies>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>4.8.2</version>
> <type>jar</type>
> <scope>test</scope>
> </dependency>
> <dependency>
> <groupId>com.sun.jersey</groupId>
> <artifactId>jersey-server</artifactId>
> <version>1.5-SNAPSHOT</version>
> </dependency>
> <dependency>
> <groupId>com.sun.jersey.jersey-test-framework</groupId>
> <artifactId>jersey-test-framework-inmemory</artifactId>
> <version>1.5-SNAPSHOT</version>
> <scope>test</scope>
> </dependency>
> <dependency>
> <groupId>org.freemarker</groupId>
> <artifactId>freemarker</artifactId>
> <version>2.3.16</version>
> </dependency>
> </dependencies>
>
> The problem is that when i run the test, it failed to load the
> context :
> SEVERE: Missing dependency for field: public
> javax.servlet.ServletContext
> com.domain.providers.myProcessor.myContext
>
> I'm a little lost :/
>
> Thanks by advance !