2 Replies Latest reply on Mar 28, 2010 7:10 AM by mmaia

    Integration test configuration error. Seam 2.2.0GA + Eclipse + TestNG + DBUnitTest

    mmaia

      Hi,


      I'm new to Seam. Using Seam 2.2.0 GA with JBoss 5.1 and MySQL5. I have a straightforward implementation of login routine with Seam. I got my project generated by seam-gem and so far the login implementation is very simple with 2 entitys (User and Role) and an implemented AuthenticatorBean.authenticate method. Follows the code for authenticate method:




      @SuppressWarnings("unchecked")
              public boolean authenticate() {
                      log.info("authenticating {0}", credentials.getUsername());
                      List<User> resultado = entityManager
                                      .createQuery(
                                                      "SELECT u FROM User u WHERE u.email=#{credentials.username} AND u.senha=#{credentials.password}")
                                      .getResultList();
                      if (resultado.size() == 0) {
                              log.info("Autenticacao falhou");
                              return false;
                      } else {
                              user = (User) resultado.get(0);
                              for (Role role : user.getRoles()) {
                                      identity.addRole(role.getNome());
                              }
                              log.info("Usuario autenticado com sucesso");
                              return true;
                      }
              }
      



      Now I need to test this code. Because I'm using a query inside this method I believe(Any thoughts on this?) an integration test with DB simulated data is indicated. With this in mind I did a little studying and got a TestNGClass extending a DBUnitSeamTest:




      public class LoginTest extends  DBUnitSeamTest {
              
              
              @Override
              protected void prepareDBUnitOperations() {
                       beforeTestOperations.add(new DataSetOperation("loginTest.xml"));
              }
              
              @Test
              public void integrationTestAuthenticate() throws Exception
              {
                      new FacesRequest("#{identity.login}")
                      {
                              @Override
                              protected void updateModelValues()throws Exception
                              {
                                      setValue("#{credentials.username}", "maia.marcos@gmail.com");
                                      setValue("#{credentials.password}", "12345678");
                              }
                              
                              @Override
                              protected void invokeApplication()
                              {
                                      assert getValue("#{credentials.username}").equals("maia.marcos@gmail.com");
                                      assert invokeMethod("#{authenticator.authenticate()}").equals(true);
                              }
                              
                              @Override
                              protected void renderResponse()
                              {
                                      User user = (User) getValue("#{user}");
                                      
                                      assert user.getNome().equals("Admin");
                              }
                              
                      }.run();
              }
      }



      I have placed the loginTest.xml in the same package as LoginTest.class with DB data for this test, and it's contents follows:




      <dataset>
         <USER 
            id="1"
            email="maia.marcos@gmail.com"
            nome="Admin" 
            senha="12345678"/>
         
         <USER 
            id="2"
            email="anototudo@gmail.com"
            nome="Anototudo" 
            senha="anototudo"/>
         
         <ROLE
            id="1"
            nome="ADMIN"
            descricao="desc testes role admin" />
         
         <ROLE
            id="2"
            nome="DIETA_CALORIAS"
            descricao="desc testes role dieta_calorias" />
            
            
        <USER_ROLE
            user_id="1"
            role_id="1"/>
            
        <USER_ROLE
            user_id="2"
            role_id="2"/> 
            
      </dataset>



      Also I have configured resources/META-INF/persistent-test.xml (I believe this is used but have no clue how so far), with DB data as follows:


      <?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="anototudo">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/anototudoDatasource</jta-data-source>
            
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="hibernate.default_catalog" value="anototudo"/>
               <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
            </properties>
         </persistence-unit>



      I have also included all required libraries in TestNG run configuration for DB test and also because I'm using java 6 the VM argument is set: -Dsun.lang.ClassLoader.allowArraySyntax(equals)true


      Finally I create a TestNG xml called IntegrationTests.xml configuration file and pointed to it in the run configuration under TestNG eclipse plugin:


        • 1. Re: Integration test configuration error. Seam 2.2.0GA + Eclipse + TestNG + DBUnitTest
          mmaia

          Sorry, have submitted before finish: Follows the IntegrationTests.xml configuration file:



          <?xml version="1.0" encoding="UTF-8"?>
          
          <suite name="AnototudoTest" verbose="2" parallel="false">
                  <test name="LoginTest">
                          <parameter name="datasourceJndiName" value="java:/anototudoDatasource"/>
                          <parameter name="database" value="MYSQL" />
                          <classes>
                                  <class name="br.com.anototudo.test.view.LoginTest" />
                          </classes>
                  </test>
          </suite>



          and finally the error I get when I try to run this test:




          [Parser] Running:
            /home/mmaia/workspaceGalileo/anototudo/src/test/br/com/anototudo/test/view/IntegrationTests.xml
          
          FAILED CONFIGURATION: @BeforeSuite startSeam
          org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):
          
          *** CONTEXTS MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}
          
          persistence.units:jar=test-build.jar,unitName=anototudo
           -> <UNKNOWN>{Described:** UNRESOLVED Demands 'jboss.jca:name=anototudoDatasource,service=DataSourceBinding **}
          
          
          *** CONTEXTS IN ERROR: Name -> Error
          
          <UNKNOWN> -> ** UNRESOLVED Demands 'jboss.jca:name=anototudoDatasource,service=DataSourceBinding **
          
          
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:576)
                  at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:559)
                  at org.jboss.embedded.DeploymentGroup.process(DeploymentGroup.java:128)
                  at org.jboss.embedded.Bootstrap.deployResourceBases(Bootstrap.java:289)
                  at org.jboss.seam.mock.EmbeddedBootstrap.startAndDeployResources(EmbeddedBootstrap.java:15)
                  at org.jboss.seam.mock.AbstractSeamTest.startJbossEmbeddedIfNecessary(AbstractSeamTest.java:1024)
                  at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:915)
                  at org.jboss.seam.mock.SeamTest.startSeam(SeamTest.java:58)
          ... Removed 15 stack frames
          SKIPPED CONFIGURATION: @BeforeClass setBinaryDir
          SKIPPED CONFIGURATION: @BeforeClass setDatabase
          SKIPPED CONFIGURATION: @BeforeClass setDatasourceJndiName
          SKIPPED CONFIGURATION: @BeforeClass setupClass
          SKIPPED CONFIGURATION: @BeforeMethod begin
          SKIPPED CONFIGURATION: @BeforeMethod prepareDataBeforeTest
          SKIPPED CONFIGURATION: @AfterMethod cleanDataAfterTest
          SKIPPED CONFIGURATION: @AfterMethod end
          SKIPPED CONFIGURATION: @AfterClass cleanupClass
          PASSED: integrationTestAuthenticate
          
          ===============================================
              LoginTest
              Tests run: 1, Failures: 0, Skips: 1
              Configuration Failures: 1, Skips: 9
          ===============================================
          
          
          ===============================================
          AnototudoTest
          Total tests run: 1, Failures: 0, Skips: 1
          Configuration Failures: 1, Skips: 10
          ===============================================
          
          [org.testng.internal.PoolService] Shutting down poolservice org.testng.internal.PoolService@9c67db terminated:false



          Any clues? Any suggestions on integration tests with DB data integration?




          []s



          • 2. Re: Integration test configuration error. Seam 2.2.0GA + Eclipse + TestNG + DBUnitTest
            mmaia

            Based on seam examples I have dropped DBUnit test and I'm using a Login test based on Gavin king's example as follows:




            package br.com.anototudo.test.view;
            
            import org.jboss.seam.core.Manager;
            import org.jboss.seam.mock.SeamTest;
            import org.jboss.seam.web.Session;
            import org.testng.annotations.Test;
            
            
            public class LoginTest extends  SeamTest {
                 
                 
                 @Test
                    public void testLoginComponent() throws Exception
                    {
                       new ComponentTest() {
            
                          @Override
                          protected void testComponents() throws Exception
                          {
                             assert getValue("#{identity.loggedIn}").equals(false);
                             setValue("#{identity.username}", "maia.marcos@gmail.com");
                             setValue("#{identity.password}", "12345678");
                             invokeMethod("#{identity.login}");
                             assert getValue("#{user.nome}").equals("Admin");
                             assert getValue("#{user.username}").equals("maia.marcos@gmail.com");
                             assert getValue("#{user.password}").equals("12345678");
                             assert getValue("#{identity.loggedIn}").equals(true);
                             invokeMethod("#{identity.logout}");
                             assert getValue("#{identity.loggedIn}").equals(false);
                             setValue("#{identity.username}", "maia.marcos@gmail.com");
                             setValue("#{identity.password}", "12345678");
                             invokeMethod("#{identity.login}");
                             assert getValue("#{identity.loggedIn}").equals(false);
                          }
                          
                       }.run();
                    }
                    
                    @Test
                    public void testLogin() throws Exception
                    {
                       
                       new FacesRequest() {
                          
                          @Override
                          protected void invokeApplication()
                          {
                             assert !isSessionInvalid();
                             assert getValue("#{identity.loggedIn}").equals(false);
                          }
                          
                       }.run();
                       
                       new FacesRequest() {
            
                          @Override
                          protected void updateModelValues() throws Exception
                          {
                             assert !isSessionInvalid();
                             setValue("#{identity.username}", "maia.marcos@gmail.com");
                             setValue("#{identity.password}", "12345678");
                          }
            
                          @Override
                          protected void invokeApplication()
                          {
                             invokeAction("#{identity.login}");
                          }
            
                          @Override
                          protected void renderResponse()
                          {
                             assert getValue("#{user.name}").equals("Admin");
                             assert getValue("#{user.username}").equals("maia.marcos@gmail.com");
                             assert getValue("#{user.password}").equals("12345678");
                             assert !Manager.instance().isLongRunningConversation();
                             assert getValue("#{identity.loggedIn}").equals(true);
                          }
                          
                       }.run();
                       
                       new FacesRequest() {
            
                          @Override
                          protected void invokeApplication()
                          {
                             assert !isSessionInvalid();
                             assert getValue("#{identity.loggedIn}").equals(true);
                          }
                          
                       }.run();
                       
                       new FacesRequest() {
            
                          @Override
                          protected void invokeApplication()
                          {
                             assert !Manager.instance().isLongRunningConversation();
                             assert !isSessionInvalid();
                             invokeMethod("#{identity.logout}");
                             assert Session.instance().isInvalid();
                          }
            
                          @Override
                          protected void renderResponse()
                          {
                             assert getValue("#{identity.loggedIn}").equals(false);
                             assert Session.instance().isInvalid();
                          }
                          
                       }.run();
                       
                    }
            }



            My persistence-test.xml is configured to use local Mysql:




            <?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="anototudo">
                  <provider>org.hibernate.ejb.HibernatePersistence</provider>
                  <jta-data-source>anototudoDatasource</jta-data-source>
                  
                  <properties>
                     <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                     <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                     <property name="hibernate.show_sql" value="true"/>
                     <property name="hibernate.format_sql" value="true"/>
                     <property name="hibernate.default_catalog" value="anototudo"/>
                     <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                  </properties>
               </persistence-unit>
                
            </persistence>




            I still get the same error from TestNG plugin:



            [Parser] Running:
              /home/mmaia/workspaceGalileo/anototudo/classes/test/br/com/anototudo/test/view/IntegrationTests.xml
            
            FAILED CONFIGURATION: @BeforeSuite startSeam
            org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):
            
            *** CONTEXTS MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}
            
            persistence.units:jar=test-build.jar,unitName=anototudo
             -> <UNKNOWN>{Described:** UNRESOLVED Demands 'jboss.jca:name=anototudoDatasource,service=DataSourceBinding **}
            
            
            *** CONTEXTS IN ERROR: Name -> Error
            
            <UNKNOWN> -> ** UNRESOLVED Demands 'jboss.jca:name=anototudoDatasource,service=DataSourceBinding **
            
            
                 at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:576)
                 at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:559)
                 at org.jboss.embedded.DeploymentGroup.process(DeploymentGroup.java:128)
                 at org.jboss.embedded.Bootstrap.deployResourceBases(Bootstrap.java:289)
                 at org.jboss.seam.mock.EmbeddedBootstrap.startAndDeployResources(EmbeddedBootstrap.java:15)
                 at org.jboss.seam.mock.AbstractSeamTest.startJbossEmbeddedIfNecessary(AbstractSeamTest.java:1024)
                 at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:915)
                 at org.jboss.seam.mock.SeamTest.startSeam(SeamTest.java:58)
            ... Removed 15 stack frames
            SKIPPED CONFIGURATION: @BeforeClass setupClass
            SKIPPED CONFIGURATION: @BeforeMethod begin
            SKIPPED CONFIGURATION: @AfterMethod end
            SKIPPED CONFIGURATION: @BeforeMethod begin
            SKIPPED CONFIGURATION: @AfterMethod end
            SKIPPED CONFIGURATION: @AfterClass cleanupClass
            PASSED: testLogin
            PASSED: testLoginComponent
            
            ===============================================
                LoginTest
                Tests run: 2, Failures: 0, Skips: 2
                Configuration Failures: 1, Skips: 6
            ===============================================
            
            
            ===============================================
            AnototudoTest
            Total tests run: 2, Failures: 0, Skips: 2
            Configuration Failures: 1, Skips: 7
            ===============================================
            
            [org.testng.internal.PoolService] Shutting down poolservice org.testng.internal.PoolService@818737 terminated:false




            any help will be appreciated? I'm stuck with integration tests here. :(