KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > commerce > UserLocalTest


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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 JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
27 import junit.framework.TestCase;
28 import net.sourceforge.junitejb.EJBTestCase;
29
30 public class UserLocalTest extends EJBTestCase {
31
32    public UserLocalTest(String JavaDoc name) {
33       super(name);
34    }
35
36    private UserLocalHome getUserLocalHome() {
37       try {
38          InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
39
40          return (UserLocalHome) jndiContext.lookup("commerce/UserLocalHome");
41       } catch(Exception JavaDoc 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 JavaDoc userIds = main.getUserIds();
63
64          System.out.println("test it");
65          assertTrue(userIds.size() == 5);
66          Iterator JavaDoc 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 JavaDoc e) {
76          e.printStackTrace();
77          fail("Error in testDeclaredSql");
78       }
79    }
80    
81
82    public void setUpEJB() throws Exception JavaDoc {
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 JavaDoc {
89    }
90    
91    public void deleteAllUsers(UserLocalHome userLocalHome) throws Exception JavaDoc {
92       Iterator JavaDoc 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