[jboss-user] [JBoss Seam] - Re: How do I test simple SLSBs?

mzeijen do-not-reply at jboss.com
Wed Aug 30 18:09:05 EDT 2006


I am also pretty new to this stuff, but here is some info to probably can help you. I got it working in eclipse.

I think that If you want use TestNG to test your stuff in a Seam/EJB3 environment  then you must write the tests as in the registration example:


  | 
  | package org.jboss.seam.example.registration.test;
  | 
  | import org.jboss.seam.Component;
  | import org.jboss.seam.example.registration.Register;
  | import org.jboss.seam.example.registration.User;
  | import org.jboss.seam.mock.SeamTest;
  | import org.testng.annotations.Test;
  | 
  | public class RegisterTest extends SeamTest
  | {
  |    
  |    @Test
  |    public void testLogin() throws Exception
  |    {
  |             
  |       new Script() {
  | 
  |          @Override
  |          protected void updateModelValues() throws Exception
  |          {
  |             User user = (User) Component.getInstance("user", true);
  |             assert user!=null;
  |             user.setUsername("1ovthafew");
  |             user.setPassword("secret");
  |             user.setName("Gavin King");
  |          }
  | 
  |          @Override
  |          protected void invokeApplication()
  |          {
  |             Register register = (Register) Component.getInstance("register", true);
  |             String outcome = register.register();
  |             assert "/registered.jsp".equals( outcome );
  |          }
  | 
  |          @Override
  |          protected void renderResponse()
  |          {
  |             User user = (User) Component.getInstance("user", false);
  |             assert user!=null;
  |             assert user.getName().equals("Gavin King");
  |             assert user.getUsername().equals("1ovthafew");
  |             assert user.getPassword().equals("secret");
  |          }
  |          
  |       }.run();
  |       
  |    }
  |    
  | }
  | 
  | 

Take a special look at the class override of new Script() { ... }. It simulates a complete request loop. 

You must make sure that you configured your TestNG for an Embedded Seam application because it needs to run with the JBoss micro container.

The extra configuration files you need are:
- default.persistence.properties
- ejb3-interceptors-aop.xml
- embedded-jboss-beans.xml
- jndi.properties
- log4j.xml

In your components.xml will probably look something like this:


  | 
  | <components>
  | 
  |     <component name="org.jboss.seam.core.init">
  |     	<property name="debug">true</property>
  |         <property name="myFacesLifecycleBug">@myFacesLifecycleBug@</property>
  |         <property name="jndiPattern">@jndiPattern@</property>
  |     </component>
  |     
  |     <!-- 120 second conversation timeout -->
  |     <component name="org.jboss.seam.core.manager">
  |         <property name="conversationTimeout">120000</property>
  |     </component>
  |     
  |     <component class="org.jboss.seam.core.Ejb" installed="@embeddedEjb@"/>
  | 
  | </components>
  | 
  | 

Use the components.properties file to set the following properties of the component.xml (those tags with @):


  | 
  | myFacesLifecycleBug : false
  | embeddedEjb : true
  | jndiPattern : #{ejbName}/local
  | 
  | 

I eclipse I have a seperate folder for all those embedded configuration. I add it to the classpath when I run TestNG.

Good luck

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3968487#3968487

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3968487



More information about the jboss-user mailing list