5 Replies Latest reply on Mar 5, 2009 8:09 PM by scott duke

    First Testng using Seam

    scott duke Novice

      I started a new project from scratch wanting to incorporate testng. I started with a simple registration action. The registration works, but I am having problems getting the testng to work. When I run my xml, this is what I am getting.



      [Parser] Running:
        C:\Projects\artwork\src\test\com\artwork\test\RegisterActionTest.xml
      
      WARN  [org.jboss.seam.security.permission.PersistentPermissionResolver] no permission store available - please install a PermissionStore with the name 'org.jboss.seam.security.jpaPermissionStore' if persistent permissions are required.
      FAILED: registerValidUzer
      java.lang.AssertionError: java.lang.NullPointerException
           at org.jboss.seam.mock.AbstractSeamTest$Request.onException(AbstractSeamTest.java:455)
           at org.jboss.seam.mock.AbstractSeamTest$Request$2.doFilter(AbstractSeamTest.java:504)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.jboss.seam.mock.AbstractSeamTest$Request.run(AbstractSeamTest.java:491)
           at com.artwork.test.RegisterUzerTest.registerValidUzer(RegisterUzerTest.java:52)
      Caused by: java.lang.NullPointerException
           at com.artwork.test.RegisterUzerTest$1.updateModelValues(RegisterUzerTest.java:24)
           at org.jboss.seam.mock.AbstractSeamTest$Request.updateModelValuesPhase(AbstractSeamTest.java:670)
           at org.jboss.seam.mock.AbstractSeamTest$Request.emulateJsfLifecycle(AbstractSeamTest.java:592)
           at org.jboss.seam.mock.AbstractSeamTest$Request.access$300(AbstractSeamTest.java:177)
           at org.jboss.seam.mock.AbstractSeamTest$Request$2.doFilter(AbstractSeamTest.java:497)
           ... 36 more
      ... Removed 22 stack frames
      
      ===============================================
          RegisterAction Test
          Tests run: 1, Failures: 1, Skips: 0
      ===============================================
      
      
      ===============================================
      RegisterAction Tests
      Total tests run: 1, Failures: 1, Skips: 0
      ===============================================
      



      The RegisterUzerTest.java


      package com.artwork.test;
      
      import java.util.List;
      
      import javax.faces.application.FacesMessage;
      
      import org.jboss.seam.Component;
      import org.jboss.seam.core.Init;
      import org.jboss.seam.mock.SeamTest;
      import org.testng.annotations.Test;
      
      import com.artwork.entity.Uzer;
      
      public class RegisterUzerTest extends SeamTest {
          
          @Test(groups = {"level.integration", "speed.slow"})
          public void registerValidUzer() throws Exception {
                
              new FacesRequest("/register.xhtml") {
      
                  @Override
                  protected void updateModelValues() {
                          Uzer uzer = (Uzer) Component.getInstance("newUzer");
                          uzer.setName("Pan, Peter");   (**** ERROR is on this line ****)
                          uzer.setUzername("iamart");
                          uzer.setEmail("iamart@artwork.com");
                          setValue("#{passwordBean.password}", "iloveart");
                          setValue("#{passwordBean.confirm}", "iloveart");
                  }
                  
                  @Override
                  protected void invokeApplication() {
                          // FIXME: I want to verify that the event is thrown, but not call the events
                          Init.instance().getObserverMethods("uzerRegistered").clear();
                      invokeAction("#{registerAction.register}");
                          assert "success".equals(getOutcome());
                          // verify we persisted
                          assert (Boolean) getValue("#{newUzer.id != null}");
                          // verify quiet login
                          assert (Boolean) getValue("#{identity.loggedIn}");
                          assert (Boolean) getValue("#{s:hasRole('uzer')}");
                  }
      
                  @Override
                  protected void renderResponse() throws Exception {
                      List<FacesMessage> messages = (List<FacesMessage>) getValue("#{facesMessages.currentMessages}");
                      assert messages.size() == 1;
                          assert messages.get(0).getSeverity().equals(FacesMessage.SEVERITY_INFO);
                          // NOTE: be i18n sensitive
                          assert messages.get(0).getSummary().contains("Pan, Peter");
                  }
              }.run();
          }
      }
      



      components.xml looks like:


      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
                  xmlns:core="http://jboss.com/products/seam/core"
                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:drools="http://jboss.com/products/seam/drools"
                  xmlns:bpm="http://jboss.com/products/seam/bpm"
                  xmlns:security="http://jboss.com/products/seam/security"
                  xmlns:mail="http://jboss.com/products/seam/mail"
                  xmlns:auth="http://artwork.com/components/auth"
                  xmlns:web="http://jboss.com/products/seam/web"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation=
                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                       http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.1.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
      
         <core:init debug="@debug@" jndi-pattern="@jndiPattern@"/>
      
         <core:manager concurrent-request-timeout="500"
                       conversation-timeout="120000"
                       conversation-id-parameter="cid"
                       parent-conversation-id-parameter="pid"/>
      
         <web:hot-deploy-filter url-pattern="*.seam"/>
      
         <persistence:managed-persistence-context name="entityManager"
                                           auto-create="true"
                            persistence-unit-jndi-name="java:/artworkEntityManagerFactory"/>
      
         <drools:rule-base name="securityRules">
            <drools:rule-files>
               <value>/security.drl</value>
            </drools:rule-files>
         </drools:rule-base>
      
         <security:rule-based-permission-resolver security-rules="#{securityRules}"/>
      
         <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
      
         <event type="org.jboss.seam.security.notLoggedIn">
            <action execute="#{redirect.captureCurrentView}"/>
         </event>
         <event type="org.jboss.seam.security.loginSuccessful">
            <action execute="#{redirect.returnToCapturedView}"/>
         </event>
      
         <mail:mail-session host="localhost" port="2525" username="test" password="test" />
      
         <!-- For use with jBPM pageflow or process management -->
         <!--
         <bpm:jbpm>
            <bpm:process-definitions></bpm:process-definitions>
            <bpm:pageflow-definitions></bpm:pageflow-definitions>
         </bpm:jbpm>
         -->
         
         <!-- ===== Artwork component definitions and configurations ===== -->
      
         <import>com.artwork.auth</import>
         
         <!-- newUzer | generic-style component *definition* -->
         <component name="newUzer" class="com.artwork.entity.Uzer" scope="event"/>
            
         <!-- passwordBean | namespace-style component *definition* -->
         <auth:password-bean name="passwordBean" scope="event"/>
          
         <!-- passwordManager | namespace-style component *configuration* (attribute variant) -->
         <auth:password-manager digest-algorithm="SHA-1" charset="UTF-8"/>
         
      
      </components>
      
      



      Would someone please tell me what I am doing wrong?


      Thanks,
      Scott