PDA

View Full Version : Spring 1.1.2 - MockServletContext.getResourcePaths broken


mraible
Nov 21st, 2004, 09:29 PM
I have the following in a TestCase's setUp() method. It works fine in 1.1.1:


// initialize Spring
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_ PARAM,
"/WEB-INF/applicationContext*.xml");
ServletContextListener contextListener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(sc);
contextListener.contextInitialized(event);


However, in 1.1.2 it results in the following error:


[junit] java.lang.UnsupportedOperationException: getResourcePaths
[junit] at org.springframework.mock.web.MockServletContext.ge tResourcePaths(MockServletContext.java:128)
[junit] at org.springframework.web.context.support.ServletCon textResourcePatternResolver.doRetrieveMatchingServ letContextResources(ServletContextResourcePatternR esolver.java:100)
[junit] at org.springframework.web.context.support.ServletCon textResourcePatternResolver.doFindPathMatchingFile Resources(ServletContextResourcePatternResolver.ja va:79)
[junit] at org.springframework.core.io.support.PathMatchingRe sourcePatternResolver.findPathMatchingFileResource s(PathMatchingResourcePatternResolver.java:192)
[junit] at org.springframework.core.io.support.PathMatchingRe sourcePatternResolver.getResources(PathMatchingRes ourcePatternResolver.java:145)
[junit] at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:142)

Juergen Hoeller
Nov 22nd, 2004, 09:29 AM
Thanks for spotting this, Matt!

This is caused by a refinement in pattern matching within web applications, namely matching via the ServletContext itself rather than via resolution as files (which works in unexpanded WARs too).

Unfortunately, MockServletContext has not provided an implementation of "getResourcePaths" yet. I've just added such an implementation; will commit it promptly.

Please give a current snapshot a try!

Juergen

mraible
Nov 29th, 2004, 12:12 PM
Works great - thanks Juergen.

Matt