Bonjour,
J'essaye d'écrire un test unitaire pour un webservice. Le webservice fonctionne correctement lorsque mon serveur d'application tourne. Seulement je veux que mon test unitaire puisse tourner sans avoir besoin d'exécuter le serveur d'application.
Le problème est que je tombe systématiquement sur cette erreur à l'exécution de mon test JUnit :
Voici mon fichier hibernate.cfg.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 junit.framework.AssertionFailedError: Exception in constructor: testExcecute (org.hibernate.HibernateException: Could not find datasource at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56) at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124) at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56) at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292) at com.bouygtel.renouvium.communrenouvium.util.hibernate.InitHibernate.initSessionFactory(InitHibernate.java:55) at com.bouygtel.renouvium.controleur.servicetechnique.avenant.GenererAvenantPortTypeImplTest.<init>(GenererAvenantPortTypeImplTest.java:26) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at junit.framework.TestSuite.createTest(TestSuite.java:131) at junit.framework.TestSuite.addTestMethod(TestSuite.java:114) at junit.framework.TestSuite.<init>(TestSuite.java:75) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:102) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:59) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445) 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: 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 javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247) at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284) at javax.naming.InitialContext.lookup(InitialContext.java:351) at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52) ... 21 more ) 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.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.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) 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)
Il semblerait en fait que mon fichier hibernate.cfg.xml n'est pas pris en compte que je tombe sur la même exception même si le fichier hibernate est absent.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 <hibernate-configuration> <session-factory> <property name="hibernate.connection.url">jdbc:bea:oracle://xxx:1521:XXX</property> <property name="hibernate.connection.driver_class">weblogic.jdbc.oracle.OracleDriver</property> <property name="hibernate.connection.username">xxx</property> <property name="hibernate.connection.password">xxx</property> <property name="transaction.manager_lookup_class"> org.hibernate.transaction.WeblogicTransactionManagerLookup </property> <property name="dialect">org.hibernate.dialect.OracleDialect</property> <property name="current_session_context_class">thread</property> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <property name="hibernate.show_sql">false</property> [...] </session-factory> </hibernate-configuration>
Partager