11 Replies Latest reply on Feb 10, 2008 2:30 AM by hubaghdadi

    Error while testing using external database

    hubaghdadi

      Hi.
      I'm trying to write tests for my Seam application.
      This application uses PostgreSQL database not HSQL.
      Here are my configurations:
      ArmadaBookStore-ds.xml:

      <datasources>
       <local-tx-datasource>
       <jndi-name>ArmadaSeamProjectDatasource</jndi-name>
       <connection-url>jdbc:postgresql:ArmadaBookStore</connection-url>
       <driver-class>org.postgresql.Driver</driver-class>
       <user-name>puser</user-name>
       <password>ppaswd</password>
       </local-tx-datasource>
      </datasources>
      

      and hibernate.cfg.xml:
      <hibernate-configuration>
       <session-factory name="java:/ArmadaBookStore">
       <property name="connection.url">jdbc:postgresql:ArmadaBookStore</property>
       <property name="connection.username">puser</property>
       <property name="connection.password">ppaswd</property>
       <property name="connection.driver_class">org.postgresql.Driver</property>
       <property name="show_sql">true</property>
       <property name="connection.datasource">ArmadaSeamProjectDatasource</property>
       <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
       <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
       <property name="transaction.flush_before_completion">true</property>
       <property name="connection.release_mode">after_statement</property>
       <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
       <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
      <!-- mappings -->
       </session-factory>
      </hibernate-configuration>
      

      Running the integration test, I got:
      Could not find datasource
      
      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 org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:918)
      at org.jboss.seam.persistence.HibernateSessionFactory.createSessionFactory(HibernateSessionFactory.java:165)
      at org.jboss.seam.persistence.HibernateSessionFactory.startup(HibernateSessionFactory.java:79)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
      at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
      at org.jboss.seam.Component.callComponentMethod(Component.java:2074)
      at org.jboss.seam.Component.callCreateMethod(Component.java:1997)
      at org.jboss.seam.Component.newInstance(Component.java:1968)
      at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
      at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
      at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:95)
      at org.jboss.seam.init.Initialization.init(Initialization.java:555)
      at org.jboss.seam.mock.BaseSeamTest.init(BaseSeamTest.java:939)
      at org.jboss.seam.mock.SeamTest.init(SeamTest.java:42)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:604)
      at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:394)
      at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
      at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:79)
      at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:165)
      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:103)
      at org.testng.TestRunner.runWorkers(TestRunner.java:678)
      at org.testng.TestRunner.privateRun(TestRunner.java:624)
      at org.testng.TestRunner.run(TestRunner.java:495)
      at org.testng.SuiteRunner.runTest(SuiteRunner.java:300)
      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:295)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:275)
      at org.testng.SuiteRunner.run(SuiteRunner.java:190)
      at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:792)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:765)
      at org.testng.TestNG.run(TestNG.java:699)
      at org.testng.TestNG.privateMain(TestNG.java:824)
      at org.testng.TestNG.main(TestNG.java:802)
      1 lines not shown
      Caused by ArmadaSeamProjectDatasource not bound
      

      I copied ArmadaBookStore-ds.xml to bootstrap/deploy dir, but I got the same exception.
      Any ideas?
      Thanks.

        • 1. Re: Error while testing using external database
          pmuir

          Post the whole log.

          • 2. Re: Error while testing using external database
            hubaghdadi

             

            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 org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:918)
             at org.jboss.seam.persistence.HibernateSessionFactory.createSessionFactory(HibernateSessionFactory.java:165)
             at org.jboss.seam.persistence.HibernateSessionFactory.startup(HibernateSessionFactory.java:79)
             at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
             at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
             at org.jboss.seam.Component.callComponentMethod(Component.java:2074)
             at org.jboss.seam.Component.callCreateMethod(Component.java:1997)
             at org.jboss.seam.Component.newInstance(Component.java:1968)
             at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
             at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
             at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:95)
             at org.jboss.seam.init.Initialization.init(Initialization.java:555)
             at org.jboss.seam.mock.BaseSeamTest.init(BaseSeamTest.java:939)
             at org.jboss.seam.mock.SeamTest.init(SeamTest.java:42)
            Caused by: javax.naming.NameNotFoundException: ArmadaSeamProjectDatasource not bound
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:542)
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:550)
             at org.jnp.server.NamingServer.getObject(NamingServer.java:556)
             at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:669)
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
             at javax.naming.InitialContext.lookup(InitialContext.java:392)
             at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
             ... 46 more
            ... Removed 26 stack frames
            Click to show all stack frames
            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 org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:918)
             at org.jboss.seam.persistence.HibernateSessionFactory.createSessionFactory(HibernateSessionFactory.java:165)
             at org.jboss.seam.persistence.HibernateSessionFactory.startup(HibernateSessionFactory.java:79)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
             at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
             at org.jboss.seam.Component.callComponentMethod(Component.java:2074)
             at org.jboss.seam.Component.callCreateMethod(Component.java:1997)
             at org.jboss.seam.Component.newInstance(Component.java:1968)
             at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
             at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
             at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:95)
             at org.jboss.seam.init.Initialization.init(Initialization.java:555)
             at org.jboss.seam.mock.BaseSeamTest.init(BaseSeamTest.java:939)
             at org.jboss.seam.mock.SeamTest.init(SeamTest.java:42)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:604)
             at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:394)
             at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
             at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:79)
             at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:165)
             at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:103)
             at org.testng.TestRunner.runWorkers(TestRunner.java:678)
             at org.testng.TestRunner.privateRun(TestRunner.java:624)
             at org.testng.TestRunner.run(TestRunner.java:495)
             at org.testng.SuiteRunner.runTest(SuiteRunner.java:300)
             at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:295)
             at org.testng.SuiteRunner.privateRun(SuiteRunner.java:275)
             at org.testng.SuiteRunner.run(SuiteRunner.java:190)
             at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:792)
             at org.testng.TestNG.runSuitesLocally(TestNG.java:765)
             at org.testng.TestNG.run(TestNG.java:699)
             at org.testng.TestNG.privateMain(TestNG.java:824)
             at org.testng.TestNG.main(TestNG.java:802)
            Caused by: javax.naming.NameNotFoundException: ArmadaSeamProjectDatasource not bound
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:542)
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:550)
             at org.jnp.server.NamingServer.getObject(NamingServer.java:556)
             at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:669)
             at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
             at javax.naming.InitialContext.lookup(InitialContext.java:392)
             at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
             ... 46 more
            

            Thank you Sir.

            • 3. Re: Error while testing using external database
              pmuir

              Ok, you need to turn logging up then. I need to see the container and Seam start up.

              • 4. Re: Error while testing using external database
                yilmaz_

                ArmadaBookStore-ds.xml must be in
                JBOSS_HOME/server/default/deploy/
                folder
                default | all | minimal
                depends on your config.

                • 5. Re: Error while testing using external database
                  hubaghdadi

                  I'm writing integration tests with JBoss Embedded container, not JBoss AS is involved...
                  I can't reach my laptop right now, I will post the whole log tomorrow...
                  Thanks you all.

                  • 6. Re: Error while testing using external database
                    hubaghdadi

                     

                    test:
                     [testng]
                    [Parser] Running:
                    
                    [testng] /media/sda4/Projects/ArmadaSeamProject/test-build/NGTest.xml
                     [testng]
                     [testng] WARN 04-02 17:12:10,995 (UnifiedLoaderRepository3.java:addClassLoader:713) -Tried to add non-URLClassLoader. Ignored
                     [testng] WARN 04-02 17:12:12,935 (TxControl.java:<clinit>:302) -[com.arjuna.ats.arjuna.coordinator.TxControl_1] - Name of XA node not defined. Using 7f000101:ed97:47a79bcc:0
                     [testng] WARN 04-02 17:12:15,051 (AspectManagerService.java:baseAop:228) -Could not find base-aspects.xml file in the resources of sun.misc.Launcher$AppClassLoader@17182c1
                     [testng] WARN 04-02 17:12:17,722 (SecurityMetadataStore.java:checkDefaultSuckerPassword:311) -WARNING! POTENTIAL SECURITY RISK. It has been detected that the MessageSucker component which sucks messages from one node to another has not had its password changed from the installation default. Please see the JBoss Messaging user guide for instructions on how to do this.
                     [testng] WARN 04-02 17:12:17,977 (ConnectionFactoryJNDIMapper.java:registerConnectionFactory:155) -supportsFailover attribute is true on connection factory: jboss.messaging.connectionfactory:service=ClusteredConnectionFactory but post office is non clustered. So connection factory will *not* support failover
                     [testng] WARN 04-02 17:12:17,978 (ConnectionFactoryJNDIMapper.java:registerConnectionFactory:161) -supportsLoadBalancing attribute is true on connection factory: jboss.messaging.connectionfactory:service=ClusteredConnectionFactory but post office is non clustered. So connection factory will *not* support load balancing
                     [testng] FAILED CONFIGURATION: @BeforeClass init
                     [testng] org.hibernate.HibernateException: Could not find datasource
                     [testng] at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
                     [testng] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
                     [testng] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
                     [testng] at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
                     [testng] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
                     [testng] at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
                     [testng] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
                     [testng] at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:918)
                     [testng] at org.jboss.seam.persistence.HibernateSessionFactory.createSessionFactory(HibernateSessionFactory.java:165)
                     [testng] at org.jboss.seam.persistence.HibernateSessionFactory.startup(HibernateSessionFactory.java:79)
                     [testng] at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
                     [testng] at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
                     [testng] at org.jboss.seam.Component.callComponentMethod(Component.java:2074)
                     [testng] at org.jboss.seam.Component.callCreateMethod(Component.java:1997)
                     [testng] at org.jboss.seam.Component.newInstance(Component.java:1968)
                     [testng] at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
                     [testng] at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
                     [testng] at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:95)
                     [testng] at org.jboss.seam.init.Initialization.init(Initialization.java:555)
                     [testng] at org.jboss.seam.mock.BaseSeamTest.init(BaseSeamTest.java:939)
                     [testng] at org.jboss.seam.mock.SeamTest.init(SeamTest.java:42)
                     [testng] Caused by: javax.naming.NameNotFoundException: ArmadaSeamProjectDatasource not bound
                     [testng] at org.jnp.server.NamingServer.getBinding(NamingServer.java:542)
                     [testng] at org.jnp.server.NamingServer.getBinding(NamingServer.java:550)
                     [testng] at org.jnp.server.NamingServer.getObject(NamingServer.java:556)
                     [testng] at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
                     [testng] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:669)
                     [testng] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
                     [testng] at javax.naming.InitialContext.lookup(InitialContext.java:392)
                     [testng] at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
                     [testng] ... 46 more
                     [testng] ... Removed 26 stack frames
                     [testng] SKIPPED CONFIGURATION: @BeforeMethod begin
                    
                    [testng] SKIPPED CONFIGURATION: @AfterMethod end
                    
                    [testng] SKIPPED CONFIGURATION: @AfterClass cleanup
                    
                    [testng] SKIPPED: listNewTitlesTest
                    
                    [testng]
                    
                    [testng] ===============================================
                    
                    [testng] ArmadaBookStore
                     [testng] Tests run: 1, Failures: 0, Skips: 1
                    
                    [testng] Configuration Failures: 1, Skips: 3
                    
                    [testng] ===============================================
                    
                    [testng]
                    
                    [testng]
                    
                    [testng] ===============================================
                    
                    [testng] ArmadaBookStore
                     [testng] Total tests run: 1, Failures: 0, Skips: 1
                    
                    [testng] Configuration Failures: 1, Skips: 3
                    
                    [testng] ===============================================
                    
                    [testng]
                    



                    My environment is:
                    JBoss AS 4.2
                    JDK 6
                    Seam GA 2.0.0
                    It is worth noting that I configured unit tests to run on JDK as your weblog indicates (regarding JAXB 2.1)
                    Thanks.


                    • 7. Re: Error while testing using external database
                      pmuir

                      As I said, turn logging up to info for both org.jboss.seam and org.jboss and post the log.

                      • 8. Re: Error while testing using external database
                        hubaghdadi

                        Hey Sir,
                        Would you please telling me in which file should I turn the logging up to info?
                        Appreciate your time and your kind help.

                        • 9. Re: Error while testing using external database
                          nickarls

                          In JBoss AS it's in .\server\default\conf\jboss-log4j.xml

                          • 10. Re: Error while testing using external database
                            hubaghdadi

                            Since I'm trying to run integration test, no JBoss AS is evolved, just JBoss Embedded container, right?
                            So, which file to adjust in my case?
                            Thank you.

                            • 11. Re: Error while testing using external database
                              hubaghdadi

                              Hi
                              It works now!!
                              In hibernate.cfg.xml, I changed:

                              <property name="connection.datasource">ArmadaSeamProjectDatasource</property>
                              

                              to:
                              <property name="connection.datasource">java:/ArmadaSeamProjectDatasource</property>
                              

                              And for injected Seam-managed hibernate sessions, names should be the same in components.xml and Java code, for example:
                              <persistence:managed-hibernate-session name="hibernateSession" auto-create="true"/>
                              
                              @In
                              private Session hibernateSession;
                              

                              Thank you all and special thanks for Mr. Pete.Muir, you showed an exceptional patience. :)