I am trying to run the junit test outside the container and having a problem running it with a jndi datasource specified in the applicationContext file for spring.
In my unit test, I create an application context and include the spring files to use the same jndi data source my application uses. This fails during initalization itself as the jndi datasource is not available outside the j2ee container.
I tried using org.springframework.mock.jndi, this creates a datasource and binds it to the same name specified in the spring context file. I dont know if I should then put that in any other place so that the spring context file can recognize this jndi datasource.
I need to some how get in between that and initialize the datasource before it fails for my unit tests. Any suggestions on how to do the same?
I get the following error:
java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Construc tor.java:274)
at junit.framework.TestSuite.createTest(TestSuite.jav a:131)
at junit.framework.TestSuite.addTestMethod(TestSuite. java:114)
at junit.framework.TestSuite.<init>(TestSuite.java:75 )
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.getTest(RemoteTestRunner.java:360)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:398)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:186)
Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'serverJndiDataSource' defined in class path resource [edu/northwestern/snuper/dao/spring-data.xml]: Initialization of bean failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:318)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:223)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:236)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:159)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:255)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:317)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:80)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:65)
at edu.northwestern.snuper.core.BaseDatabaseTestCase. <clinit>(BaseDatabaseTestCase.java:76)
In my unit test, I create an application context and include the spring files to use the same jndi data source my application uses. This fails during initalization itself as the jndi datasource is not available outside the j2ee container.
I tried using org.springframework.mock.jndi, this creates a datasource and binds it to the same name specified in the spring context file. I dont know if I should then put that in any other place so that the spring context file can recognize this jndi datasource.
I need to some how get in between that and initialize the datasource before it fails for my unit tests. Any suggestions on how to do the same?
I get the following error:
java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Construc tor.java:274)
at junit.framework.TestSuite.createTest(TestSuite.jav a:131)
at junit.framework.TestSuite.addTestMethod(TestSuite. java:114)
at junit.framework.TestSuite.<init>(TestSuite.java:75 )
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.getTest(RemoteTestRunner.java:360)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:398)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:186)
Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'serverJndiDataSource' defined in class path resource [edu/northwestern/snuper/dao/spring-data.xml]: Initialization of bean failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:318)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:223)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:236)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:159)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:255)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:317)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:80)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:65)
at edu.northwestern.snuper.core.BaseDatabaseTestCase. <clinit>(BaseDatabaseTestCase.java:76)
Comment