01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
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 org.jboss.test.util.ejb.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
41: .lookup("commerce/UserLocalHome");
42: } catch (Exception e) {
43: e.printStackTrace();
44: fail("Exception in getUserLocalHome: " + e.getMessage());
45: }
46: return null;
47: }
48:
49: public void testDeclaredSql() {
50: System.out.println("In testDeclaredSql");
51:
52: System.out.println("getUserLocalHome");
53: UserLocalHome userLocalHome = getUserLocalHome();
54:
55: try {
56: System.out.println("creatingUsers");
57: UserLocal main = userLocalHome.create("main");
58: UserLocal tody1 = userLocalHome.create("tody1");
59: UserLocal tody2 = userLocalHome.create("tody2");
60: UserLocal tody3 = userLocalHome.create("tody3");
61: UserLocal tody4 = userLocalHome.create("tody4");
62:
63: Collection userIds = main.getUserIds();
64:
65: System.out.println("test it");
66: assertTrue(userIds.size() == 5);
67: Iterator i = userIds.iterator();
68: assertTrue(i.next().equals("main"));
69: assertTrue(i.next().equals("tody1"));
70: assertTrue(i.next().equals("tody2"));
71: assertTrue(i.next().equals("tody3"));
72: assertTrue(i.next().equals("tody4"));
73:
74: System.out.println("done testDeclaredSql");
75:
76: } catch (Exception e) {
77: e.printStackTrace();
78: fail("Error in testDeclaredSql");
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)
92: throws Exception {
93: Iterator currentUsers = userLocalHome.findAll().iterator();
94: while (currentUsers.hasNext()) {
95: UserLocal user = (UserLocal) currentUsers.next();
96: user.remove();
97: }
98: }
99: }
|