1 Reply Latest reply on May 15, 2007 6:55 PM by Sheldon s

    Can't make SEAM unit test work

    Sheldon s Newbie

      I followed the example at http://docs.jboss.com/seam/1.2.1.GA/reference/en/html/testing.html#d0e15875 to unit test my own bean but I get:

      SEVERE: Could not find datasource: java:/n2TestDatasource
      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

      Here is my persisten.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for tests -->
      <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="n2">
      org.hibernate.ejb.HibernatePersistence
      <jta-data-source>java:/n2TestDatasource</jta-data-source>










      </persistence-unit>


      Here is my code to get EntityManagerFactory in the test:

      @BeforeClass
      public void init()
      {
      emf = Persistence.createEntityManagerFactory("n2");
      }

      I thought it would be a POJO test like the example said, why was I getting an initial context exception? Thanks.

        • 1. Re: Can't make SEAM unit test work
          Sheldon s Newbie

          Post the persistent.xml again:

          <?xml version="1.0" encoding="UTF-8"?>
          <!-- Persistence deployment descriptor for tests -->
          <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="n2">
           <provider>org.hibernate.ejb.HibernatePersistence</provider>
           <jta-data-source>java:/n2TestDatasource</jta-data-source>
           <properties>
           <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
           <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:/n2EntityManagerFactory"/>
           <property name="hibernate.default_catalog" value="n2test"/>
           <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
           <property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/>
           <property name="hibernate.search.default.indexBase" value="C:\temp\testLuceneIndex"/>
           </properties>
           </persistence-unit>
          
          </persistence>