0 Replies Latest reply on Feb 1, 2007 10:44 AM by Nicola Ben

    doubts with embedded-ejb testNGs

    Nicola Ben Novice

      Hi!
      I still have problems running a testNG, after reading docs, forum and wiki. So I bother you with my questions, sorry :)

      I just created with seam-gen (seam1.1.5) a project with a reversed from postgres db class (User.java)

      Included libs are the ones seam-gen includes.

      In my classpath (following the instruction from booking example) I have:


      src
      resources
      test
      embedded-ejb/conf


      In test folder I have the following test:

      import [...]
      public class UserTest extends SeamTest {
      
       @Test
       public void testUser() throws Exception
       {
       EntityManager em = entityManagerFactory.createEntityManager();
       em.getTransaction().begin();
      
       User user = new User();
       user.setName("AAAA");
      
       em.close();
       }
      
       private EntityManagerFactory entityManagerFactory;
      
       public EntityManagerFactory getEntityManagerFactory()
       {
       return entityManagerFactory;
       }
      
       @Configuration(beforeTestClass=true)
       public void init()
       {
       entityManagerFactory = Persistence.createEntityManagerFactory("myprojectEntityManagerFactory");
       }
      
       @Configuration(afterTestClass=true)
       public void destroy()
       {
       entityManagerFactory.close();
       }
      }
      
      



      My persistence-test.xml is:

      <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="myproject">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/myprojectTestDatasource</jta-data-source>
       <properties>
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/myprojectEntityManagerFactory"/>
       </properties>
       </persistence-unit>
      
      </persistence>
      


      And embedded-jboss-beans.xml is
      <?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="Naming" class="org.jnp.server.SingletonNamingServer"/>
      
       <bean name="InitialContextProperties" class="java.util.Hashtable">
       <constructor>
       <parameter class="java.util.Map">
       <map keyClass="java.lang.String" valueClass="java.lang.String">
       <entry>
       <key>java.naming.factory.initial</key>
       <value>org.jnp.interfaces.LocalOnlyContextFactory</value>
       </entry>
       <entry>
       <key>java.naming.factory.url.pkgs</key>
       <value>org.jboss.naming:org.jnp.interfaces</value>
       </entry>
       </map>
       </parameter>
       </constructor>
       </bean>
      
       <bean name="java:comp/Initializer" class="org.jboss.ejb3.embedded.JavaCompInitializer">
       <property name="jndiProperties"><inject bean="InitialContextProperties"/></property>
       </bean>
      
       <bean name="XidFactory" class="org.jboss.tm.XidFactoryImpl"/>
      
       <bean name="XidFactoryMBean" class="org.jboss.ejb3.embedded.XidFactoryMBean">
       <constructor>
       <parameter class="org.jboss.tm.XidFactoryBase">
       <inject bean="XidFactory"/>
       </parameter>
       </constructor>
       </bean>
      
       <bean name="TransactionManagerInitializer" class="org.jboss.tm.TransactionManagerInitializer">
       <property name="xidFactory"><inject bean="XidFactory"/></property>
       <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
       </bean>
      
       <bean name="UserTransaction" class="org.jboss.ejb3.embedded.UserTransactionImpl">
       <demand>TransactionManagerInitializer</demand>
       </bean>
      
       <bean name="UserTransactionBinding" class="org.jboss.ejb3.embedded.JndiBinder">
       <property name="jndiProperties"><inject bean="InitialContextProperties"/></property>
       <property name="target"><inject bean="UserTransaction"/></property>
       <property name="bindTo">UserTransaction</property>
       <property name="serializable">false</property>
       </bean>
      
      
       <bean name="TransactionManager" class="java.lang.Object">
       <constructor factoryMethod="getTransactionManager">
       <factory bean="TransactionManagerInitializer"/>
       </constructor>
       </bean>
       <bean name="CachedConnectionManager" class="org.jboss.resource.connectionmanager.CachedConnectionManagerReference">
       <property name="transactionManager"><inject bean="TransactionManager"/></property>
       </bean>
      
       <!--
       <bean class="org.jboss.jdbc.HypersonicDatabase"
       name="jboss:service=Hypersonic,database=localDB">
       <property name="database">localDB</property>
       <property name="inProcessMode">true</property>
       <property name="dbDataDir">.</property>
       </bean>
       -->
      
       <bean name="DefaultDSBootstrap" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
       <property name="driverClass">org.hsqldb.jdbcDriver</property>
       <property name="connectionURL">jdbc:hsqldb:.</property>
       <!-- <property name="connectionURL">jdbc:hsqldb:./hypersonic/localDB</property> -->
       <property name="userName">sa</property>
       <property name="jndiName">java:/DefaultDS</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="DefaultDS" class="java.lang.Object">
       <constructor factoryMethod="getDatasource">
       <factory bean="DefaultDSBootstrap"/>
       </constructor>
       </bean>
      
      
      </deployment>
      


      WEB-INF/Components.xml is:
      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
       xmlns:core="http://jboss.com/products/seam/core"
       xmlns:drools="http://jboss.com/products/seam/drools"
       xmlns:security="http://jboss.com/products/seam/security"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation=
       "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-1.1.xsd
       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-1.1.xsd
       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-1.1.xsd
       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-1.1.xsd">
      
       <core:init debug="true" jndi-pattern="@jndiPattern@"/>
      
       <core:manager concurrent-request-timeout="500"
       conversation-timeout="120000"
       conversation-id-parameter="cid"
       conversation-is-long-running-parameter="clr"/>
      
       <core:pages no-conversation-view-id="/home.xhtml"/>
      
       <core:managed-persistence-context name="entityManager"
       persistence-unit-jndi-name="java:/myprojectEntityManagerFactory"/>
      
       <core:ejb installed="@embeddedEjb@"/>
      
       <drools:rule-base name="securityRules">
       <drools:rule-files><value>/security.drl</value></drools:rule-files>
       </drools:rule-base>
      
       <security:identity authenticate-method="#{authenticator.authenticate}"/>
      
      </components>
      



      When I run my test I get the following:

      ===============================================
      myproject
      Total tests run: 0, Failures: 0, Skips: 0
      ===============================================

      org.testng.TestNGException:
      Cannot find class in classpath: UserTest
      at org.testng.xml.XmlClass.getSupportClass(XmlClass.java:45)
      at org.testng.internal.Utils.xmlClassesToClasses(Utils.java:82)
      at org.testng.TestRunner.initMethods(TestRunner.java:252)
      at org.testng.TestRunner.init(TestRunner.java:198)
      at org.testng.TestRunner.init(TestRunner.java:168)
      at org.testng.TestRunner.<init>(TestRunner.java:135)
      at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:102)
      at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:152)
      at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:457)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:212)
      at org.testng.SuiteRunner.run(SuiteRunner.java:168)
      at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:987)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:951)
      at org.testng.TestNG.run(TestNG.java:719)
      at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:122)




      My doubts are:

      1) In UserTest.java is it correct to refer to myprojectEntityManagerFactory (mentioned in persistence.xml and components.xml) ?
      entityManagerFactory = Persistence.createEntityManagerFactory("myprojectEntityManagerFactory");


      2) embedded-jboss-beans.xml has a DefaultDS that uses hsqldb.....do I have to modify it to postgres datasource? or HSQLDB is used during tests independently by any other database I use ?

      3) Why do I obtain a "Cannot find class in classpath" error when my java file is in the classpath?

      Thank you in advance,
      Nico