users@jersey.java.net

Override Spring Beans in JerseyTest

From: Colin Vipurs <zodiaczx6_at_gmail.com>
Date: Thu, 23 Sep 2010 16:12:17 +0100

I'm trying to write some integration tests and override a bean in
order to provide a mock implementation for the life of the test. I'm
using Jersey 1.4, Spring 3.0.4 and making use of the JerseyTest, which
looks something like this:

public class MyRestServicesIntegrationTest extends JerseyTest {
        public MyRestServicesIntegrationTest() {
                super(new WebAppDescriptor.Builder("com.mycompany.rest")
                        .contextPath("/mycompany")
                        .contextParam("contextConfigLocation",
"classpath:applicationContext.xml,MyRestServicesIntegrationTest-context.xml")
                        .servletClass(SpringServlet.class)
                        .contextListenerClass(ContextLoaderListener.class)
                        .requestListenerClass(RequestContextListener.class)
                        .build());
        }
        
        @Test
        public void presentDataReturnsCorrectJson() throws Exception {
                WebResource r = resource().path("myresource/2");
                String string = r.get(String.class);
                assertThat(string, equalTo("<my expected json>"));
        }
}

I've overriden a bean in my test context file which works fine, but
it's a bean I want access to in my test to seed it with some data, am
I missing something very obvious here as I can't find anyway of doing
this. If not, am I going about my tests in the wrong way?

-- 
Maybe she awoke to see the roommate's boyfriend swinging from the
chandelier wearing a boar's head.
Something which you, I, and everyone else would call "Tuesday", of course.