facebook

Junit unable to locaate Spring Context file?

  1. MyEclipse IDE
  2.  > 
  3. Maven for MyEclipse (Maven4MyEclipse)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #291649 Reply

    muddu_shafi
    Member

    I am running some JUnit test on my code developed using MyEclipse Maven.

    I have a Project structure where java files are written under src/test/java and the configuration files are written under src/test/conf?

    What might be the cause of error? and How I should solve it?

    Code:

    public class ErpProxyServicesTest extends TestCase {
        private static final boolean ejbTest = false;
    
        private IErpProxyServices services;
    
        public ErpProxyServicesTest(String arg0) throws LoginException {
        super(arg0);
            
        ClassPathXmlApplicationContext ac;
            
        ac = new ClassPathXmlApplicationContext("erpProxyServicesTestAppContext.xml");
        this.services = (IErpProxyServices)ac.getBean("erpServices");
            
        }
    
        protected void setUp() throws Exception {
            super.setUp();
        }
    
        protected void tearDown() throws Exception {
            super.tearDown();
        }
        
        public void testSpringConfig() {
            System.out.println ("Class: " + this.services);
    //        assertTrue (this.services instanceof ErpProxyServices);
        }
    }

    Error description(stack Trace):-
    Quote:

    junit.framework.AssertionFailedError: Exception in constructor: testSpringConfig (org.springframework.beans.factory.BeanDefinitionS toreException: IOException parsing XML document from class path resource [erpProxyServicesTestAppContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [erpProxyServicesTestAppContext.xml] cannot be opened because it does not exist
    Caused by: java.io.FileNotFoundException: class path resource [erpProxyServicesTestAppContext.xml] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getI nputStream(ClassPathResource.java:137)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:351)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:334)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:126)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:142)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:168)
    at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:113)
    at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:79)
    at org.springframework.context.support.AbstractRefres hableApplicationContext.refreshBeanFactory(Abstrac tRefreshableApplicationContext.java:94)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:294)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:92)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:77)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:68)
    at org.atcc.erpproxy.services.ErpProxyServicesTest.<i nit>(ErpProxyServicesTest.java:65)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at junit.framework.TestSuite.createTest(TestSuite.jav a:135)
    at junit.framework.TestSuite.addTestMethod(TestSuite. java:114)
    at junit.framework.TestSuite.<init>(TestSuite.java:75 )
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit 3TestLoader.getTest(JUnit3TestLoader.java:102)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit 3TestLoader.loadTests(JUnit3TestLoader.java:59)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:445)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)
    )
    at junit.framework.Assert.fail(Assert.java:47)
    at junit.framework.TestSuite$1.runTest(TestSuite.java :263)
    at junit.framework.TestCase.runBare(TestCase.java:127 )
    at junit.framework.TestResult$1.protect(TestResult.ja va: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:2 08)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit 3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)

    Do I have to change any settings for maven in MyEclipse?
    why is eclipse and Junit not able to locate the file?

    #291656 Reply

    muddu_shafi
    Member

    Please respond, with a detailed answer?

    #291680 Reply

    muddu_shafi
    Member

    Please respond, I been trying to fix this bug from two days, unable to get any result.

    I have tried various combinations such as
    new ClassPathXmlApplicationContext(“erpProxyServicesTestAppContext.xml”); //this line displays the error.
    new ClassPathXmlApplicationContext(“conf/erpProxyServicesTestAppContext.xml”);
    new ClassPathXmlApplicationContext(“/erpProxyServicesTestAppContext.xml”);
    new ClassPathXmlApplicationContext(“src/test/conf/erpProxyServicesTestAppContext.xml”);
    new ClassPathXmlApplicationContext(“erpProxy/src/test/conf/erpProxyServicesTestAppContext.xml”);
    new ClassPathXmlApplicationContext(“/erpProxy/src/test/conf/erpProxyServicesTestAppContext.xml”);

    I have my configuration files in
    erpProxy
    |-src/test/java //Here I placed Junit test files
    |-src/test/conf // Here I placed config files like erpProxyServicesTestAppContext.xml

    #291742 Reply

    cherngje
    Member

    src/test/conf is not maven’s default resource directory. You should either modify your pom to point resource directory to src/test/conf or move all your configuration files under src/test/resources/conf.

    Everything under src/main/resources is real resources. Everything under src/test/resources is for testing. You will also need to make sure that “Source” under your project’s Java Build Path include all the “resource” folders as your project’s sources (and point to the correct output folder). I always create src/main/resources and src/test/resources as source folder under Eclipse/MyEclipse. That way I can always test JUnit or run application without the need of using maven.

    Good luck

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Junit unable to locaate Spring Context file?

You must be logged in to post in the forum log in