The register component injected a DAO. When the DAO extends EntityController, 
when only one test exists, it runs normal;when two tests or above the second 
test will throw exception that entityManager is closed.When the DAO injects the 
EntityManager directly, doesn't extend the EntityController which encapsulate a 
EntityManager, no matter how many tests exist, it runs normal. Why?


  | package com.kdccn.test;
  | 
  | import static org.testng.Assert.*;
  | 
  | import java.util.*;
  | 
  | import org.testng.annotations.*;
  | 
  | import org.jboss.seam.mock.*;
  | 
  | import com.kdccn.util.*;
  | 
  | public class UserTest extends SeamTest {
  | 
  |     @Test
  |     public void testLogin() throws Exception {
  |             new FacesRequest("/user/login.xhtml") {
  |                     @Override
  |                     protected void updateModelValues() {
  |                             setValue("#{identity.username}", "admin");
  |                             setValue("#{identity.password}", "secret");
  |                     }
  | 
  |                     @Override
  |                     protected void invokeApplication() {
  |                             invokeAction("#{identity.login}");
  |                     }
  |             }.run();
  |     }
  | 
  |     @Test
  |     public void testRegister() throws Exception {
  |             new FacesRequest("/user/register.xhtml") {
  |                     @Override
  |                     protected void updateModelValues() {
  |                             setValue("#{newUser.email}", "[EMAIL 
PROTECTED]");
  |                             setValue("#{newUser.qq}", 61304189L);
  |                             setValue("#{newUser.icq}", 259833852L);
  |                             setValue("#{newUser.kugoo}", 318921L);
  |                             setValue("#{newUser.msn}", "[EMAIL PROTECTED]");
  |                             setValue("#{newUser.yahoo}", "[EMAIL 
PROTECTED]");
  |                             setValue("#{newUser.google}", "[EMAIL 
PROTECTED]");
  |                             setValue("#{newUser.alipay}", "[EMAIL 
PROTECTED]");
  |                             setValue("#{newUser.wangwang}", "setokaiba");
  |                             setValue("#{newUser.website}", "www.kdccn.com");
  |                             setValue("#{newUser.question}", "secret");
  |                             setValue("#{newUser.answer}", "secret");
  |                             setValue("#{newUser.place}", "China");
  |                             setValue("#{newUser.phone}", "+8613763335987");
  |                             Calendar calendar = Calendar.getInstance();
  |                             calendar.set(1987, Calendar.DECEMBER, 30);
  |                             setValue("#{newUser.birthday}", 
calendar.getTime());
  |                             setValue("#{newUser.description}", "Nothing");
  |                             setValue("#{newUser.firstname}", "Seto");
  |                             setValue("#{newUser.lastname}", "Kaiba");
  |                             setValue("#{newUser.nickname}", "Seto");
  |                             setValue("#{newUser.username}", "SetoKaiba");
  |                             setValue("#{register.password}", "secret");
  |                             setValue("#{register.confirm}", "secret");
  |                             setValue("#{register.gender}", "Male");
  |                     }
  | 
  |                     @Override
  |                     protected void invokeApplication() {
  |                             invokeAction("#{register.register}");
  |                     }
  | 
  |                     @Override
  |                     protected void renderResponse() {
  |                             assertNotNull(getValue("#{newUser.id}"));
  |                             
assertEquals(getValue("#{newUser.hashedPassword}"), Hash
  |                                             .instance().hash("secret"));
  |                             assertTrue((Boolean) 
getValue("#{s:hasRole('user')}"));
  |                     }
  |             }.run();
  |     }
  | }
  | 

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

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4101583
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to