1 Reply Latest reply on Aug 21, 2007 5:36 PM by Peter Haraszti

    Embedded EJB Testing Woes

    Mike Kohout Newbie

      I'm trying to use the embedded EJB container for testing a seam 2.0 seam-gen based app but am having problems.


      I've got a datasource set up as so:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
       xmlns="urn:jboss:bean-deployer">
      
       <bean name="ICTRCoreDatasourceBootstrap"
       class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
       <property name="driverClass">com.mysql.jdbc.Driver</property>
       <property name="connectionURL">jdbc:mysql://de01.gcrc.umn.edu/mwkohout_ictrcore</property>
       <property name="userName">mwkohout</property>
       <property name="password">password</property>
       <property name="jndiName">java:/ICTRCoreDatasource</property>
       <property name="minSize">0</property>
       <property name="maxSize">10</property>
       <property name="blockingTimeout">1000</property>
       <property name="idleTimeout">100000</property>
       <property name="transactionManager">
       <inject bean="TransactionManager"/>
       </property>
       <property name="cachedConnectionManager">
       <inject bean="CachedConnectionManager"/>
       </property>
       <property name="initialContextProperties">
       <inject bean="InitialContextProperties"/>
       </property>
       </bean>
      
       <bean name="ICTRCoreDatasource" class="java.lang.Object">
       <constructor factoryMethod="getDatasource">
       <factory bean="ICTRCoreDatasourceBootstrap"/>
       </constructor>
       </bean>
      
      </deployment>
      

      It's living in test-build/META-INF/

      and I've got a PU set up like so:
      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for dev profile -->
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
       version="1.0">
      
       <persistence-unit name="ICTRCore">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/ICTRCoreDatasource</jta-data-source>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="update"/>
       <property name="hibernate.cache.use_query_cache" value="true"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/ICTRCoreEntityManagerFactory"/>
       </properties>
       </persistence-unit>
      
      </persistence>
      

      It lives in the test-build/META-INF dir as well.

      But I'm getting this error:
      INFO 21-08 13:46:47,955 [org.hibernate.cfg.annotations.EntityBinder.bindTable():340] Bind entity edu.umn.ictr.authentication.Role on table Role
      INFO 21-08 13:46:47,999 [org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass():581] Mapping collection: edu.umn.ictr.IRBInterface.IrbStudy.studyActions -> STUDY_ACTION
      INFO 21-08 13:46:48,000 [org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass():581] Mapping collection: edu.umn.ictr.IRBInterface.IrbStudy.studyFundings -> STUDY_FUNDING
      INFO 21-08 13:46:48,000 [org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass():581] Mapping collection: edu.umn.ictr.IRBInterface.IrbStudy.studyTitles -> STUDY_TITLE
      INFO 21-08 13:46:48,003 [org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass():581] Mapping collection: edu.umn.ictr.IRBInterface.IrbStudy.studyPersons -> STUDY_PERSONNEL
      INFO 21-08 13:46:48,120 [org.hibernate.util.NamingHelper.getInitialContext():26] JNDI InitialContext properties:{}
      FATAL 21-08 13:46:48,141 [org.hibernate.connection.DatasourceConnectionProvider.configure():55] Could not find datasource: java:/ICTRCoreDatasource
      javax.naming.NameNotFoundException: ICTRCoreDatasource 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:628)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:590)
       at javax.naming.InitialContext.lookup(InitialContext.java:392)
       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:2006)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1289)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:691)
       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
       at edu.umn.ictr.core.test.entity.UserTest.init(UserTest.java:52)
       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)
      
      ===============================================
      Suite1
      Total tests run: 1, Failures: 0, Skips: 1
      Configuration Failures: 2, Skips: 2
      ===============================================
      


      What am I missing? Is there any obvious errors I'm making?

      thanks
      Mike Kohout




        • 1. Re: Embedded EJB Testing Woes
          Peter Haraszti Newbie

          Hi Mike

          your problem is that you are missing a JDBC data source bound in JNDI as "java:/ICTRCoreDatasource"

          You will need a data source definition XML file (*-ds.xml) defined and deployed in to $JBOSS_SERVER/server//deploy directory.

          The following is an example:

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE datasources
           PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
           "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
          <datasources>
           <local-tx-datasource>
           <jndi-name>ICTRCoreDatasource</jndi-name>
           <connection-url>
           jdbc:mysql://de01.gcrc.umn.edu/mwkohout_ictrcore
           </connection-url>
           <driver-class>com.mysql.jdbc.Driver</driver-class>
           <transaction-isolation>
           TRANSACTION_READ_COMMITTED
           </transaction-isolation>
           <user-name>mwkohout</user-name>
           <password>password</password>
           <min-pool-size>10</min-pool-size>
           <max-pool-size>10</max-pool-size>
           <exception-sorter-class-name>
           org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
           </exception-sorter-class-name>
           <metadata>
           <type-mapping>mySQL</type-mapping>
           </metadata>
           </local-tx-datasource>
          </datasources>
          


          As far as I know, with JBoss Seam 2.0.0.BETA1 and AS 4.2.0.GA, you no longer need the jboss-beans.xml file. My application does certainly work without one (both in TestNG/Embedded and real deployments).

          Hope this helps.

          Regards:
          Peter