java - Stripes framework unit testing: MockServletContext giving NullPointerException -


edit: can ignore of have written below:

i getting null value of context when following in testng code:

 public void setupnontrivialobjects() {      testfixture.context = new mockservletcontext("test");      } 

am supposed more make mockservletcontext object not null?


original: learning use stripes framework testng.

i following example here (but adapting own code): http://www.stripesframework.org/display/stripes/unit+testing under heading approach 2

i have test:

public class seedsearchactionbeantest { @test public void seedsearchtest() throws exception {     // setup 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 sure is.

public class testfixture {  private static mockservletcontext context;  @beforesuite  public void setupnontrivialobjects() {      testfixture.context = new mockservletcontext("test");           // add stripes filter      map<string,string> filterparams = new hashmap<string,string>();      filterparams.put("actionresolver.packages", "net.sourceforge.stripes");      context.addfilter(stripesfilter.class, "stripesfilter", filterparams);      // add stripes dispatcher      context.setservlet(dispatcherservlet.class, "stripesdispatcher", null);  }   public static mockservletcontext getservletcontext() {      return testfixture.context;      } } 

i error

failed: seedsearchtest java.lang.nullpointerexception @ net.sourceforge.stripes.mock.mockroundtrip.geturlbindingstub(mockroundtrip.java:384) @ net.sourceforge.stripes.mock.mockroundtrip.<init>(mockroundtrip.java:96) @ net.sourceforge.stripes.mock.mockroundtrip.<init>(mockroundtrip.java:82) @ sempedia.tests.action.seedsearchactionbeantest.seedsearchtest(seedsearchactionbeantest.java:17) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)

i guess line mockservletcontext ctx = testfixture.getservletcontext(); not working, wondering if there missing, particularly, there have in web.xml?

the mistake line:

 filterparams.put("actionresolver.packages", "net.sourceforge.stripes");`  

this should (in case):

filterparams.put("actionresolver.packages", "action"); 

essentially setting package name actionbeans found. seems obvious once know it.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -