java - Testing a Spring WebListener -


i have class annotated @weblistener, extending servletcontextlistener class i'm testing relies on having executed. when test manually (i.e. running in tomcat) works, within junit test @weblistener class never executed. i'm assuming need add configuration execute, i'm not sure what. or need run manually in the test?

edit: here's basics of class

@weblistener public class mylistener implements servletcontextlistener {    @override   public void contextinitialized(servletcontextevent event) {     // retrieve spring application context     servletcontext servletcontext = event.getservletcontext();     springcontext = webapplicationcontextutils.getwebapplicationcontext(servletcontext);     ...   }   ... } 

i've added test class:

@before public void mockinit() {     mockservletcontext mockcontext = new mockservletcontext();     new mylistener().contextinitialized(new servletcontextevent(mockcontext)); } 

but springcontext variable in contextinitialized null.

assuming using mockmvc tests, can register filter with

mockmvcbuilders.webappcontextsetup(webappcontext).addfilter(yourfilter, urlpatterns); 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -