dcsimg
Spring-JUnit4 context file not found
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alberthoven_Kilmister
Posted On:   Thursday, July 31, 2008 06:59 AM

I'm trying to run a test but I'm receiving an exception. Like you can see (see code bellow), it's a very simple test: access to DB MySQL and get one element (if exists). DAO component is taken from context. The problem raises loading the context: althought xml context file is located at same path that test, system can't find tha file. I have tryed to run the same code (SVN synchronized) in other 2 PCs, and it runs ok. I don't know where could be the problem (Spring configuration, environ variables, library imports, etc.). Any idea? Thanks! --------------------- Test code ---------------------    More>>

I'm trying to run a test but I'm receiving an exception.


Like you can see (see code bellow), it's a very simple test: access to DB MySQL and get one element (if exists).


DAO component is taken from context. The problem raises loading the context: althought xml context file is located at same path that test, system can't find tha file.


I have tryed to run the same code (SVN synchronized) in other 2 PCs, and it runs ok.


I don't know where could be the problem (Spring configuration, environ variables, library imports, etc.).


Any idea?


Thanks!




--------------------- Test code ---------------------

			
				
package com.dixired.feedfetcher.dao;

import static org.junit.Assert.assertNotNull;

import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;

import com.dixired.feedfetcher.model.Channel;

@ContextConfiguration(locations={"DAOChannelTest-context.xml"})
public class DAOChannelTest extends
AbstractTransactionalJUnit4SpringContextTests {

@Autowired
private DAOChannelGeneric daoChannel = null;

@Test
public void testLoadChannel() throws DAOException {
List channels = daoChannel.loadAll();
System.out.print(channels.size());
assertNotNull(channels);
Channel channel = daoChannel.get(1);
assertNotNull(channel);
}
}


------------------- End test code -------------------




--------------------- Trace ---------------------

			
				
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:203)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:93)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:130)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [com/dixired/feedfetcher/dao/DAOChannelTest-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [com/dixired/feedfetcher/dao/DAOChannelTest-context.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:349)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:81)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:42)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:173)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:199)
... 16 more
Caused by: java.io.FileNotFoundException: class path resource [com/dixired/feedfetcher/dao/DAOChannelTest-context.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:142)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
... 25 more


--------------------- End trace ---------------------    <<Less
About | Sitemap | Contact