9 Replies Latest reply on Apr 1, 2008 2:47 PM by borner.bradley.orner.comcast.net

    Unittests using SeamTest

    jwi.jwi.informationsdesign.de

      1) generating a new project using seam-gen
      2) generating new action seam-gen new-action
      3) running the generated Test for new action


      ... this works ok.


      Now, in a real-life project, I try to create an test-environment identical to what is generated by seam-gen.
      Examining the classpath used for the testng-anttask in the generated build.xml, this amounts to something like this:


      conf/...
      data/...
      deploy/...
      deployers/...
      tmp/
      META-INF/...
      WEB-INF/...
      security.drl
      jndi.properties
      commons-logging.properties
      log4j.xml


      This basically resembles the bootstrap directory of the generated project.


      Although having the datasource named vcDatasource deployed to /deploy,
      I get:


      FATAL [org.hibernate.connection.DatasourceConnectionProvider] Could not find datasource: java:/vcDatasource
      java.lang.RuntimeException: PROVIDER_URL not provided in jndi.properties.  Automatic discovery not implemented yet.
              at org.jboss.naming.JBossRemotingContextFactory.getInitialContext(JBossRemotingContextFactory.java:158)
              at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
              at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
              at javax.naming.InitialContext.init(InitialContext.java:223)
              at javax.naming.InitialContext.<init>(InitialContext.java:175)
              at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
              at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
              at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
              at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
              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:915)
              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
              at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
              at de.informationsdesign.verbundcockpit.model.QueryTest.testPagedQuery(QueryTest.java:18)
              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:585)
              at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
              at org.testng.internal.Invoker.invokeMethod(Invoker.java:473)
              at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:567)
              at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:834)
              at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
              at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
              at org.testng.TestRunner.runWorkers(TestRunner.java:689)
              at org.testng.TestRunner.privateRun(TestRunner.java:566)
              at org.testng.TestRunner.run(TestRunner.java:466)
              at org.testng.SuiteRunner.runTest(SuiteRunner.java:301)
              at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:296)
              at org.testng.SuiteRunner.privateRun(SuiteRunner.java:276)
              at org.testng.SuiteRunner.run(SuiteRunner.java:191)
              at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:808)
              at org.testng.TestNG.runSuitesLocally(TestNG.java:776)
              at org.testng.TestNG.run(TestNG.java:701)
              at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
              at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)
              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:585)
              at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
      javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not find datasource
              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:737)
              at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
              at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
              at de.informationsdesign.verbundcockpit.model.QueryTest.testPagedQuery(QueryTest.java:18)
              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:585)
              at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
              at org.testng.internal.Invoker.invokeMethod(Invoker.java:473)
              at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:567)
              at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:834)
              at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
              at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
              at org.testng.TestRunner.runWorkers(TestRunner.java:689)
              at org.testng.TestRunner.privateRun(TestRunner.java:566)
              at org.testng.TestRunner.run(TestRunner.java:466)
              at org.testng.SuiteRunner.runTest(SuiteRunner.java:301)
              at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:296)
              at org.testng.SuiteRunner.privateRun(SuiteRunner.java:276)
              at org.testng.SuiteRunner.run(SuiteRunner.java:191)
              at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:808)
              at org.testng.TestNG.runSuitesLocally(TestNG.java:776)
              at org.testng.TestNG.run(TestNG.java:701)
              at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
              at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)
              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:585)
              at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
      Caused by: 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.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
              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:915)
              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
              ... 31 more
      Caused by: java.lang.RuntimeException: PROVIDER_URL not provided in jndi.properties.  Automatic discovery not implemented yet.
              at org.jboss.naming.JBossRemotingContextFactory.getInitialContext(JBossRemotingContextFactory.java:158)
              at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
              at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
              at javax.naming.InitialContext.init(InitialContext.java:223)
              at javax.naming.InitialContext.<init>(InitialContext.java:175)
              at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
              at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
              ... 38 more

        • 1. Re: Unittests using SeamTest
          nickarls

          Tried putting


          java.naming.provider.url=jnp://localhost:1099

          in jndi.properties?

          • 2. Re: Unittests using SeamTest
            jwi.jwi.informationsdesign.de

            that line gets rid of


            java.lang.RuntimeException: PROVIDER_URL not provided in jndi.properties. Automatic discovery not implemented yet.


            But why can a seam-gen generated project live without that property ??


            The datasource can't still be found, even if I try using java:/DefaultDS (deploy/hsqldb-ds.xml)


            Is there some documentation about SeamTest environment setup ?


            Thx

            • 3. Re: Unittests using SeamTest
              damianharvey.damianharvey.gmail.com

              If you're using Seam-Gen, have you run the buildtest ant task? It creates a datasource.


              Cheers,


              Damian.

              • 4. Re: Unittests using SeamTest
                jwi.jwi.informationsdesign.de

                I can't see where this builds a datasource...?
                Seam-gen uses DefaultDS


                     <target name="buildtest" depends="compiletest,copytestclasses" description="Build the tests">
                          <copy todir="${test.dir}">
                               <fileset dir="${basedir}/resources">
                                    <exclude name="META-INF/persistence*.xml"/>
                                    <exclude name="import*.sql"/>
                                    <exclude name="${project.name}-*-ds.xml"/>
                               </fileset>
                          </copy>
                          <copy tofile="${test.dir}/META-INF/persistence.xml"
                                file="${basedir}/resources/META-INF/persistence-test.xml"
                                overwrite="true"/>
                          <copy tofile="${test.dir}/import.sql"
                                file="${basedir}/resources/import-test.sql"
                                overwrite="true"/>
                          <copy todir="${test.dir}" flatten="true">
                               <fileset dir="${src.test.dir}">
                                    <include name="**/*Test.xml"/>
                               </fileset>
                          </copy>
                     </target>

                • 5. Re: Unittests using SeamTest
                  jwi.jwi.informationsdesign.de

                  sorry about the bad code-formatting... new to this wiki

                  • 6. Re: Unittests using SeamTest
                    damianharvey.damianharvey.gmail.com

                    Sorry. It's the persistence.xml that it copies from your persistence-test.xml. I have added a local DS to that for my unit testing eg:


                    <persistence-unit name="dsLocal" transaction-type="RESOURCE_LOCAL">
                      <properties>
                          <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                          <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
                          <property name="hibernate.connection.username" value="xxx"/>
                          <property name="hibernate.connection.password" value="xxx"/>
                          <property name="hibernate.connection.url" value="jdbc:mysql://localhost:8889/xxxx"/>
                          <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider"/>
                          <property name="hibernate.cache.use_second_level_cache" value="true"/>
                          <property name="hibernate.cache.use_query_cache" value="true"/>
                          <property name="hibernate.query.jpaql_strict_compliance" value="false"/>
                      </properties>
                    </persistence-unit>     
                    


                    Cheers,


                    Damian.

                    • 7. Re: Unittests using SeamTest
                      jwi.jwi.informationsdesign.de

                      this is mine.. but I don't know what is wrong with it



                      "     <persistence-unit name="MyPersistenceUnit">
                                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                                <jta-data-source>java:/DefaultDS</jta-data-source>
                                <properties>
                                     <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
                                     <property name="hibernate.hbm2ddl.auto" value="create"/>
                                     <property name="hibernate.show_sql" value="true"/>
                                     <property name="hibernate.format_sql" value="true"/>
                                     <property name="jboss.entity.manager.factory.jndi.name" value="java:/myEntityManagerFactory"/>
                                </properties>
                           </persistence-unit>
                      "


                      • 8. Re: Unittests using SeamTest
                        jwi.jwi.informationsdesign.de

                        BTW.. this is what seam-gen generates too.

                        • 9. Re: Unittests using SeamTest
                          borner.bradley.orner.comcast.net

                          FWIW, I get the same error using eclipse/jbosstools trying to do a simple unit test (using testng, but I saw it with junit as well).  I get the error:



                          java.lang.RuntimeException: PROVIDER_URL not provided in jndi.properties.  Automatic discovery not implemented yet.
                               at org.jboss.naming.JBossRemotingContextFactory.getInitialContext(JBossRemotingContextFactory.java:158)
                          ...
                          




                          when I explicitly provide the jdbc connection properties in the persistence.xml and comment out the JNDI approach ala:


                          <persistence-unit name="rides">
                            <!-- hibernate as persistence provider -->
                           <provider>org.hibernate.ejb.HibernatePersistence</provider>
                           <!-- use jta-data-source for JNDI registration of datasource
                                otherwise, use jdbc properties     -->
                          <!-- 
                            <jta-data-source>java:/ridesDatasource</jta-data-source>
                          -->
                           <properties>
                             <property name="hibernate.dialect"
                               value="org.hibernate.dialect.MySQL5Dialect" />
                             <property name="hibernate.hbm2ddl.auto" value="update" />               <property name="hibernate.show_sql" value="true" />
                             <property name="hibernate.format_sql" value="true" />
                             <property name="jboss.entity.manager.factory.jndi.name"               value="java:/ridesEntityManagerFactory" />
                             <!-- JDBC properties: use if JNDI is not being used -->
                             <property name="hibernate.connection.driver_class"     
                               value="com.mysql.jdbc.Driver" />
                             <property name="hibernate.connection.url"
                               value="jdbc:mysql://localhost:3306/thedatabase" />
                             <property name="hibernate.connection.username" value="root" />        <property name="hibernate.connection.password"
                               value="thepassword" />
                           </properties>
                          </persistence-unit>
                          



                          When I try using the JNDI approach:


                            <jta-data-source>java:/ridesDatasource</jta-data-source>
                            ...
                            (jndi properties commented out)
                          



                          I get the could not find datasource error:


                          javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not find datasource
                          



                          I am really stuck, any help would be great. I'm very close to punting seam and going with spring. I'll give it a few more days, but it's been really exasperating trying to just get a simple protoype actually working (which I've been unable make happen). There is nothing more frustrating than following tutorials and examples only to have them just plain not work. I've seen several forum threads with similar problems that have gone unanswered (or maybe they were figured out, but the thread didn't get the benefit of the solution).


                          Desperately seeking help, as I'd really like to make seam work for me.


                          Thanks,
                          Brad