users@jersey.java.net

Re: [Jersey] Problem using the JerseyTest class

From: Naresh <Srinivas.Bhimisetty_at_Sun.COM>
Date: Tue, 14 Jul 2009 18:21:27 +0530

Hi Tarjei,

    for the applications which use the Spring framework, currently you
have to pass the spring context loader listener class and the
applicationContext config location explicitly.

Please modify your constructor as follows and see if it helps:
===================================================================
public SourceResourceJerseyTest() throws Exception {
        super();
        Map<String, String> contextParams = new HashMap<String, String>();
        contextParams.put("contextConfigLocation",
"classpath:applicationContext-HSQLdb.xml");
        ApplicationDescriptor appDescriptor = new ApplicationDescriptor()
                .setContextPath(your-context-path)
                .setRootResourcePackageName(your-root-resource-package-name)
                
.setServletClass(com.sun.jersey.spi.spring.container.servlet.SpringServlet.class)
                
.setContextListenerClassName("org.springframework.web.context.ContextLoaderListener")
                .setContextParams(contextParams);
        super.setupTestEnvironment(appDescriptor);
}
======================================================================

   Also, you might want to refer the spring-annotations sample [1] to
see how the JerseyTest class has been used for a spring app.

[1]
http://download.java.net/maven/2/com/sun/jersey/samples/spring-annotations/1.1.1-ea-SNAPSHOT/spring-annotations-1.1.1-ea-SNAPSHOT-project.zip

Hope this helps,
Naresh

tarjei wrote:
> Hi, I'm trying to use the JerseyTest class with a resource that
> contains some spring loaded resources.
>
> I set up the class like this:
>
> @TestExecutionListeners( {
> DependencyInjectionTestExecutionListener.class })
> @ContextConfiguration(locations = { "/applicationContext-HSQLdb.xml" })
> @RunWith(SpringJUnit4ClassRunner.class)
> public class SourceResourceJerseyTest extends JerseyTest {
>
> public SourceResourceJerseyTest() throws Exception {
> super("my.path.");
> }
>
>
> }
>
>
> My problem starts in my testmethod where both webResource and
> jerseyClient are null.
>
> Jersey reports that if finds and loads the resourceclasses, but that
> somehow they are not created.
>
> When I run the tests with Grizzly I get:
>
> Jul 14, 2009 2:26:25 PM
> com.sun.jersey.test.framework.impl.container.grizzly.web.GrizzlyWebContainer
> start
> INFO: Starting grizzly...
> Jul 14, 2009 2:26:25 PM
> com.sun.grizzly.http.servlet.ServletContextImpl initListeners WARNING:
> Unable to load listener: null
>
>
>
> Jul 14, 2009 2:24:29 PM com.sun.jersey.api.core.PackagesResourceConfig
> init
> INFO: Scanning for root resource and provider classes in the packages:
> ...
> Jul 14, 2009 2:24:29 PM com.sun.jersey.api.core.PackagesResourceConfig
> init
> INFO: Root resource classes found:
> ...
> Jul 14, 2009 2:24:29 PM com.sun.jersey.api.core.PackagesResourceConfig
> init
> INFO: Provider classes found:
> Jul 14, 2009 2:24:29 PM
> com.sun.jersey.server.impl.application.WebApplicationImpl initiate
> INFO: Initiating Jersey application, version 'Jersey: 1.1.0-ea
> 04/30/2009 05:54 PM'
> Jul 14, 2009 2:24:30 PM
> com.sun.jersey.server.impl.application.WebApplicationImpl
> newResourceClass
> WARNING: A sub-resource method, public java.util.List
> my.path.web.SourceResource.list(java.lang.String,boolean,long,int),
> with URI template, "", is treated as a resource method
> Jul 14, 2009 2:24:30 PM
> com.sun.jersey.server.impl.application.WebApplicationImpl
> newResourceClass
> WARNING: A sub-resource method, public my.path.web.SourceView
> my-path.web.SourceResource.create(my.path.web.SourceView), with URI
> template, "/", is treated as a resource method
>
>
> Any tips to what I'm doing wrong?
>
> Kind regards,
> Tarjei
>