4 Replies Latest reply on Feb 14, 2008 3:17 PM by maykellff

    Seam and testing fail. TestNG

    maykellff

      Hi all, i'am following the book "Begining JBoss Seam. From novice to Profesional" like a helper to introduce my self in Seam. Now i've transformed a simple jsf application into a Seam-EJB3 application, everything works well but the tests. I'am using Red Hat Developer Studio, it comes with the TestNG plugin, i try to use TestNG to run a test i wrotte but always i get the same error.

      Can it be something related to the package structure i have? Maybe TestNG most have some specific package structure in order to look for the resources it need to run the tests.

      Any help will be very appreciated.

      This is the error i get:


      [Parser] Running:
      D:\workspaceRHDS\jsfTest\temp-testng-customsuite.xml

      log4j:WARN No appenders could be found for logger (org.hibernate.ejb.Version).
      log4j:WARN Please initialize the log4j system properly.
      FAILED CONFIGURATION: @BeforeClass init
      javax.persistence.PersistenceException: No Persistence provider for EntityManager named jsfTest
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
      at pruebas.ExpedienteFacadeTest.init(ExpedienteFacadeTest.java:47)
      ... Removed 22 stack frames
      SKIPPED CONFIGURATION: @AfterClass destroy
      SKIPPED: testBuscarExpediente

      ===============================================
      pruebas.ExpedienteFacadeTest
      Tests run: 1, Failures: 0, Skips: 1
      Configuration Failures: 1, Skips: 1
      ===============================================


      ===============================================
      jsfTest
      Total tests run: 1, Failures: 0, Skips: 1
      Configuration Failures: 1, Skips: 1
      ===============================================


      I don't know what is happening, i've tried every posible solution but without results. It seens like it doesn't found the persistence.xml.

      This is my persistence.xml:

      <?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="jsfTest">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/jsfTestDatasource</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:/jsfTestEntityManagerFactory"/>

      </properties>
      </persistence-unit>

      </persistence>



      This is my components.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <components>
      <component name="org.jboss.seam.core.init">
      <property name="debug">true</property>
      <property name="myFacesLifecycleBug">true</property>
      <property name="jndiPattern">jsfTest/#{ejbName}/local</property>
      </component>

      <managed-persistence-context name="em" auto-create="true" persistence-unit-jndi-name="java:/jsfTestEntityManagerFactory"/>

      <component name="exampleExpediente" class="com.domain.Expediente"/>

      <entity-query name="queryExpedientes" ejbql="select e from Expediente e"/>

      <persistence:managed-persistence-context name="em"
      auto-create="true"
      entity-manager-factory="#{emf}"/>

      <persistence:entity-manager-factory name="emf"
      persistence-unit-name="jsfTest"/>

      </components>



      This is my test class:

      package pruebas;

      import javax.persistence.EntityManager;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.Persistence;

      import org.jboss.seam.annotations.In;
      import org.testng.annotations.Configuration;
      import org.testng.annotations.Test;

      import com.domain.Expediente;
      import com.domain.nomenclador.NTipoAcusado;
      import com.facade.ExpedienteFacade;
      import com.facade.impl.ExpedienteFacadeImpl;



      public class ExpedienteFacadeTest {

      @In
      EntityManagerFactory emf;

      @Test
      public void testBuscarExpediente()
      {
      EntityManager em = emf.createEntityManager();
      em.getTransaction().begin();

      NTipoAcusado ta = new NTipoAcusado();
      ta.setId_tipoacusado(1);ta.setValor("Acusado Libre");

      Expediente exp = new Expediente();
      exp.setTipoAcusado(ta);

      ExpedienteFacadeImpl ef = new ExpedienteFacadeImpl();
      ef.setEm(em);ef.setExpediente(exp);

      String strResult = ef.buscarExpediente();
      assert "some".equals(strResult);
      em.getTransaction().rollback();
      em.close();
      }

      @Configuration(beforeTestClass=true)
      public void init()
      {
      emf = Persistence.createEntityManagerFactory("jsfTest");
      }

      @Configuration(afterTestClass=true)
      public void destroy()
      {
      emf.close();
      }
      }




        • 1. Re: Seam and testing fail. TestNG
          pmuir

          Try using an integration test. This use of the Java SE in a unit test is one I don't like.

          • 2. Re: Seam and testing fail. TestNG
            maykellff

             

            "pete.muir@jboss.org" wrote:
            Try using an integration test. This use of the Java SE in a unit test is one I don't like.


            The integration test rise me the following error:

            FAILED: testBuscarExpediente
            java.lang.NoClassDefFoundError: com/sun/el/ExpressionFactoryImpl
            at org.jboss.seam.util.UnifiedELValueBinding.<init>(UnifiedELValueBinding.java:18)
            at org.jboss.seam.mock.MockApplication.createValueBinding(MockApplication.java:272)
            at org.jboss.seam.jsf.SeamApplication11.createValueBinding(SeamApplication11.java:116)
            at org.jboss.seam.mock.SeamTest$Request.setValue(SeamTest.java:374)
            at pruebas.ExpedienteFacadeIntegrationTest$1.updateModelValues(ExpedienteFacadeIntegrationTest.java:28)
            at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:476)
            at pruebas.ExpedienteFacadeIntegrationTest.testBuscarExpediente(ExpedienteFacadeIntegrationTest.java:46)
            ... Removed 22 stack frames


            This is the code of the integration test:

            package pruebas;

            import org.jboss.seam.mock.SeamTest;
            import org.testng.annotations.Test;

            public class ExpedienteFacadeIntegrationTest extends SeamTest
            {

            @Test
            public void testBuscarExpediente()throws Exception
            {
            new FacesRequest() {

            /*
            @Override
            protected void processValidations() throws Exception
            {
            validateValue("#{house.address}", "123 Main Street");
            validateValue("#{house.city}", "Columbus");
            validateValue("#{house.state}", "OH");
            assert !isValidationFailure();
            }

            */
            @Override
            protected void updateModelValues() throws Exception
            {
            setValue("#{expediente.nroExpediente}", "123");
            setValue("#{expediente.tipoAcusado}", "Acusado Libre");
            //setValue("#{expediente.fechaTurnado}", "Jan 1, 2008");
            }

            @Override
            protected void invokeApplication()
            {
            assert invokeMethod("#{expedienteFacade.buscarExpediente}").equals("success");
            }

            @Override
            protected void renderResponse()
            {
            assert getValue("#{expedienteFacade.expedientesEncontrados.size}").equals(7);
            //assert getValue("#{house.city}").equals("Columbus");
            //assert getValue("#{house.state}").equals("OH");
            }
            }.run();
            }
            }


            • 3. Re: Seam and testing fail. TestNG
              pmuir

              Seam 1.2? How did you set up the integration test?

              • 4. Re: Seam and testing fail. TestNG
                maykellff

                 

                "pete.muir@jboss.org" wrote:
                Seam 1.2? How did you set up the integration test?

                Hi, i don't understand what you mean,

                most i to make any configuration before run a TestNG integration test in a Sean project?
                Can you present me with an example.?

                Thank you very much for your help.