Code:
package no.uib.ii.dpg.dpe.controllers;
import junit.framework.TestCase;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.support.XmlWebApplicationContext;
public class BaseControllerTest extends TestCase {
XmlWebApplicationContext ctx;
PresentationController controller;
/* Sets up the preconditions for all tests */
protected void setUp() throws Exception {
super.setUp();
String[] paths = {"/meta/master-servlet.xml"};
ctx = new XmlWebApplicationContext();
ctx.setConfigLocations(paths);
ctx.setServletContext(new MockServletContext(""));
ctx.refresh();
}
public void testTest() throws Exception {
assertTrue(1==1);
}
}
Running this test (via Eclipse) gives me this error:
Code:
INFO - Couldn't open InputStream for class path resource [meta/master-servlet.xml]
java.io.FileNotFoundException: class path resource [meta/master-servlet.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:127)
at org.springframework.mock.web.MockServletContext.getResourceAsStream(MockServletContext.java:167)
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:94)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:144)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:99)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:115)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:83)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:87)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:262)
at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134)
at no.uib.ii.dpg.dpe.controllers.BaseControllerTest.setUp(BaseControllerTest.java:22)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
In cleartext: the file does not exist. My catalogue structure looks like this:
Code:
Project
|-classes
|-src
|-tests
|-meta
|-lib
etc. The master-servlet.xml file resides in "/meta". The test resides in "/test/[package structure]".
Any ideas? I'm out of them.