0 Replies Latest reply on Nov 4, 2007 9:13 AM by Seto Kaiba

    Test problem with EntityController, waiting online for answe

    Seto Kaiba Expert

      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}", "kaibaseto@gmail.com");
       setValue("#{newUser.qq}", 61304189L);
       setValue("#{newUser.icq}", 259833852L);
       setValue("#{newUser.kugoo}", 318921L);
       setValue("#{newUser.msn}", "realsetokaiba@msn.com");
       setValue("#{newUser.yahoo}", "realsetokaiba@yahoo.com.cn");
       setValue("#{newUser.google}", "kaibaseto@gmail.com");
       setValue("#{newUser.alipay}", "kaibaseto@gmail.com");
       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();
       }
      }