KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
25 import junit.framework.*;
26 import javax.ejb.*;
27 import javax.naming.*;
28 import javax.rmi.PortableRemoteObject JavaDoc;
29
30 public class UserTest extends TestCase {
31
32    public UserTest(String JavaDoc name) {
33       super(name);
34    }
35
36    private UserHome getUserHome() {
37       try {
38          InitialContext jndiContext = new InitialContext();
39
40          Object JavaDoc ref = jndiContext.lookup("commerce/User");
41          return (UserHome)PortableRemoteObject.narrow (ref, UserHome.class);
42       } catch(Exception JavaDoc e) {
43          fail("Exception in getUserHome: " + e.getMessage());
44       }
45       return null;
46    }
47
48    private CustomerHome getCustomerHome() {
49       try {
50          InitialContext jndiContext = new InitialContext();
51
52          Object JavaDoc ref = jndiContext.lookup("commerce/Customer");
53
54          // Get a reference from this to the Bean's Home interface
55
return (CustomerHome)PortableRemoteObject.narrow(
56                ref, CustomerHome.class);
57       } catch(Exception JavaDoc e) {
58          fail("Exception in getCustomerHome: " + e.getMessage());
59       }
60       return null;
61    }
62
63    public void testUserQueries() throws Exception JavaDoc {
64       UserHome home = getUserHome();
65       home.findAllByUserName("Test User 1");
66    }
67
68    public void testAddCd() {
69    /*
70       try {
71          UserHome userHome = getUserHome();
72
73          String userId = "dain";
74          String userName = "Dain Sundstrom";
75          String email = "dain@daingroup.com";
76
77          User user = userHome.create(userId);
78          user.setUserName(userName);
79          user.setEmail(email);
80          user.setSendSpam(false);
81
82          assertEquals(userId, user.getUserId());
83          assertEquals(userName, user.getUserName());
84          assertEquals(email, user.getEmail());
85          assertEquals(false, user.getSendSpam());
86
87          user = null;
88
89          user = userHome.findByUserName(userName);
90          assertEquals(userId, user.getUserId());
91          assertEquals(userName, user.getUserName());
92          assertEquals(email, user.getEmail());
93          assertEquals(false, user.getSendSpam());
94
95          // test customer -> user relationship
96          CustomerHome customerHome = getCustomerHome();
97          Customer customer = customerHome.create(new Long(random.nextLong()));
98          customer.setName("The Daingroup, LLC.");
99          customer.setUser(user);
100
101          // is the user correct
102          assertTrue(user.isIdentical(customer.getUser()));
103
104          user = customer.getUser();
105          assertEquals(userId, user.getUserId());
106          assertEquals(userName, user.getUserName());
107          assertEquals(email, user.getEmail());
108          assertEquals(false, user.getSendSpam());
109
110          // set cutomer to null and see if it stays null
111          customer.setUser(null);
112          assertNull(customer.getUser());
113
114          // reset user
115          customer.setUser(user);
116
117          // removing user
118          userHome.remove(user.getPrimaryKey());
119
120          try {
121             user = userHome.findByUserName(userName);
122             fail("should throw ObjectNotFoundException");
123          } catch(ObjectNotFoundException e) {
124          }
125
126          // user was deleted so customer's user ref should be null
127          assertNull(customer.getUser());
128
129          customer.remove();
130       } catch(Exception e) {
131          e.printStackTrace();
132          fail("Error in big old method: ");
133       }
134 */

135    }
136    public static Test suite() {
137       return new TestSuite(UserTest.class);
138    }
139 }
140
141
142
143
Popular Tags