1 22 package org.jboss.test.cmp2.commerce; 23 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import javax.naming.InitialContext ; 27 import junit.framework.TestCase; 28 import net.sourceforge.junitejb.EJBTestCase; 29 30 public class UserLocalTest extends EJBTestCase { 31 32 public UserLocalTest(String name) { 33 super(name); 34 } 35 36 private UserLocalHome getUserLocalHome() { 37 try { 38 InitialContext jndiContext = new InitialContext (); 39 40 return (UserLocalHome) jndiContext.lookup("commerce/UserLocalHome"); 41 } catch(Exception e) { 42 e.printStackTrace(); 43 fail("Exception in getUserLocalHome: " + e.getMessage()); 44 } 45 return null; 46 } 47 48 public void testDeclaredSql() { 49 System.out.println("In testDeclaredSql"); 50 51 System.out.println("getUserLocalHome"); 52 UserLocalHome userLocalHome = getUserLocalHome(); 53 54 try { 55 System.out.println("creatingUsers"); 56 UserLocal main = userLocalHome.create("main"); 57 UserLocal tody1 = userLocalHome.create("tody1"); 58 UserLocal tody2 = userLocalHome.create("tody2"); 59 UserLocal tody3 = userLocalHome.create("tody3"); 60 UserLocal tody4 = userLocalHome.create("tody4"); 61 62 Collection userIds = main.getUserIds(); 63 64 System.out.println("test it"); 65 assertTrue(userIds.size() == 5); 66 Iterator i = userIds.iterator(); 67 assertTrue(i.next().equals("main")); 68 assertTrue(i.next().equals("tody1")); 69 assertTrue(i.next().equals("tody2")); 70 assertTrue(i.next().equals("tody3")); 71 assertTrue(i.next().equals("tody4")); 72 73 System.out.println("done testDeclaredSql"); 74 75 } catch(Exception e) { 76 e.printStackTrace(); 77 fail("Error in testDeclaredSql"); 78 } 79 } 80 81 82 public void setUpEJB() throws Exception { 83 System.out.println("delete all users"); 84 deleteAllUsers(getUserLocalHome()); 85 System.out.println("done delete all users"); 86 } 87 88 public void tearDownEJB() throws Exception { 89 } 90 91 public void deleteAllUsers(UserLocalHome userLocalHome) throws Exception { 92 Iterator currentUsers = userLocalHome.findAll().iterator(); 93 while(currentUsers.hasNext()) { 94 UserLocal user = (UserLocal)currentUsers.next(); 95 user.remove(); 96 } 97 } 98 } 99 100 101 102 | Popular Tags |