Question

EDIT: You can ignore most of what I have written below:

I am getting a null value of context when I do the following in some TestNG code:

 public void setupNonTrivialObjects() {
     TestFixture.context = new MockServletContext("test");
     }

Am I supposed to do something more to make a MockServletContext object that is not null?


ORIGINAL: I am learning to use the Stripes Framework with TestNG.

I am following the example here (but adapting it to my own code): http://www.stripesframework.org/display/stripes/Unit+Testing under the heading Approach 2

I have this test:

public class SeedSearchActionBeanTest {
@Test
public void seedSearchTest() throws Exception {
    // Setup the servlet engine
    MockServletContext ctx = TestFixture.getServletContext();

    MockRoundtrip trip = new MockRoundtrip(ctx, SeedSearchActionBean.class);
    trip.setParameter("input", "sdfs");
    trip.execute();

    SeedSearchActionBean bean = trip.getActionBean(SeedSearchActionBean.class);
    Assert.assertEquals(bean.getInput(),"sdfs");
    Assert.assertEquals(trip.getDestination(), "/results.jsp");
    }
}

This "TestFixture" not really sure what that is.

public class TestFixture {
 private static MockServletContext context;
 @BeforeSuite
 public void setupNonTrivialObjects() {
     TestFixture.context = new MockServletContext("test"); 
         // Add the Stripes Filter
     Map<String,String> filterParams = new HashMap<String,String>();
     filterParams.put("ActionResolver.Packages", "net.sourceforge.stripes");
     context.addFilter(StripesFilter.class, "StripesFilter", filterParams);
     // Add the Stripes Dispatcher
     context.setServlet(DispatcherServlet.class, "StripesDispatcher", null);
 }

 public static MockServletContext getServletContext() {
     return TestFixture.context;
     }
}

I get this error

FAILED: seedSearchTest java.lang.NullPointerException at net.sourceforge.stripes.mock.MockRoundtrip.getUrlBindingStub(MockRoundtrip.java:384) at net.sourceforge.stripes.mock.MockRoundtrip.<init>(MockRoundtrip.java:96) at net.sourceforge.stripes.mock.MockRoundtrip.<init>(MockRoundtrip.java:82) at sempedia.tests.action.SeedSearchActionBeanTest.seedSearchTest(SeedSearchActionBeanTest.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

I guess this line MockServletContext ctx = TestFixture.getServletContext(); is not working, I am wondering if there is something I am missing, particularly, is there something I have to do in the web.xml?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top