5 Replies Latest reply on Mar 13, 2007 11:13 AM by knuwu

    Testing Authentication with TestNG

      I'm trying to test the authentication with TestNG inside Eclipse with the TestNG -Plugin.

      The test class looks like that:

      package test.seam.services.security.test;
      
      import org.jboss.seam.mock.SeamTest;
      import org.testng.annotations.Test;
      
      public class UserSearchTest extends SeamTest {
      
       @Test
       public void testSearch() throws Exception {
       new FacesRequest() {
      
       @Override
       protected void updateModelValues() throws Exception {
       setValue("#{identity.username}", "tsggora1");
       setValue("#{identity.password}", "test");
       }
      
       @Override
       protected void invokeApplication() {
       assert invokeMethod("#{identity.login}").equals("success");
       }
      
       }.run();
       }
      
      }
      


      All worked fine, the embedded ejb container is started up, hsqldb database is initialised, schema is imported, import script is done....

      until it comes to execute the FacesRequest. I get this error message:

      16:32:21,600 INFO [SchemaExport] Running hbm2ddl schema export
      16:32:21,600 INFO [SchemaExport] exporting generated schema to database
      16:32:21,616 INFO [SchemaExport] Executing import script: /import.sql
      16:32:21,616 INFO [SchemaExport] schema export complete
      16:32:21,632 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
      16:32:21,850 INFO [MCKernelAbstraction] installing bean: jboss.j2ee:jar=test-build,name=UserSearchBean,service=EJB3 with dependencies:
      16:32:21,850 INFO [MCKernelAbstraction] AbstractDependencyMetaData@1f9f0f2{dependency=persistence.units:jar=test-build.jar,unitName=aldebaran}
      16:32:22,132 INFO [EJBContainer] STARTED EJB: test.seam.modules.base.security.UserSearchBean ejbName: UserSearchBean
      16:32:22,163 INFO [MCKernelAbstraction] installing bean: jboss.j2ee:jar=jboss-seam,name=Dispatcher,service=EJB3 with dependencies:
      16:32:22,178 INFO [EJBContainer] STARTED EJB: org.jboss.seam.core.Dispatcher ejbName: Dispatcher
      16:32:22,194 INFO [MCKernelAbstraction] installing bean: jboss.j2ee:jar=jboss-seam,name=TransactionListener,service=EJB3 with dependencies:
      16:32:22,210 INFO [EJBContainer] STARTED EJB: org.jboss.seam.core.TransactionListener ejbName: TransactionListener
      16:32:22,210 INFO [Lifecycle] starting up: org.jboss.seam.multipartConfig
      16:32:22,225 INFO [Initialization] done initializing Seam
      16:32:22,272 INFO [Pages] reading pages.xml
      16:32:23,350 INFO [Ejb] stopping the embedded EJB container
      16:32:23,350 INFO [SessionFactoryImpl] closing
      16:32:23,350 INFO [SchemaExport] Running hbm2ddl schema export
      16:32:23,350 INFO [SchemaExport] exporting generated schema to database
      16:32:23,350 INFO [SchemaExport] schema export complete
      FAILED: testSearch
      java.lang.NullPointerException
       at org.jboss.seam.core.Selector.getCookieValue(Selector.java:59)
       at org.jboss.seam.security.Identity.initCredentialsFromCookie(Identity.java:91)
       at org.jboss.seam.security.Identity.create(Identity.java:85)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:102)
       at org.jboss.seam.Component.callComponentMethod(Component.java:1835)
       at org.jboss.seam.Component.callCreateMethod(Component.java:1783)
       at org.jboss.seam.Component.newInstance(Component.java:1772)
       at org.jboss.seam.Component.getInstance(Component.java:1669)
       at org.jboss.seam.Component.getInstance(Component.java:1636)
       at org.jboss.seam.Namespace.get(Namespace.java:42)
       at javax.el.MapELResolver.getValue(MapELResolver.java:157)
       at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:135)
       at com.sun.el.parser.AstValue.getValue(AstValue.java:117)
       at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)
       at org.jboss.seam.util.UnifiedELValueBinding.getValue(UnifiedELValueBinding.java:34)
       at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:53)
       at org.jboss.seam.Component.getInstanceFromFactory(Component.java:1710)
       at org.jboss.seam.Component.getInstance(Component.java:1659)
       at org.jboss.seam.Component.getInstance(Component.java:1636)
       at org.jboss.seam.Component.getInstance(Component.java:1630)
       at org.jboss.seam.jsf.SeamELResolver.getValue(SeamELResolver.java:49)
       at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:135)
       at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:65)
       at com.sun.el.parser.AstValue.getTarget(AstValue.java:62)
       at com.sun.el.parser.AstValue.setValue(AstValue.java:132)
       at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:255)
       at org.jboss.seam.util.UnifiedELValueBinding.setValue(UnifiedELValueBinding.java:44)
       at org.jboss.seam.mock.SeamTest$Request.setValue(SeamTest.java:363)
       at test.seam.services.security.test.UserSearchTest$1.updateModelValues(UserSearchTest.java:14)
       at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:465)
       at test.seam.services.security.test.UserSearchTest.testSearch(UserSearchTest.java:23)
      ... Removed 25 stack frames
      
      ===============================================
       UserSearch Test
       Tests run: 1, Failures: 1, Skips: 0
      ===============================================
      
      
      ===============================================
      UserSearch Tests
      Total tests run: 1, Failures: 1, Skips: 0
      ===============================================
      
      


      What's wrong?