001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cmp2.commerce;
023:
024: import java.util.*;
025: import junit.framework.*;
026: import javax.ejb.*;
027: import javax.naming.*;
028: import javax.rmi.PortableRemoteObject;
029:
030: public class UserTest extends TestCase {
031:
032: public UserTest(String name) {
033: super (name);
034: }
035:
036: private UserHome getUserHome() {
037: try {
038: InitialContext jndiContext = new InitialContext();
039:
040: Object ref = jndiContext.lookup("commerce/User");
041: return (UserHome) PortableRemoteObject.narrow(ref,
042: UserHome.class);
043: } catch (Exception e) {
044: fail("Exception in getUserHome: " + e.getMessage());
045: }
046: return null;
047: }
048:
049: private CustomerHome getCustomerHome() {
050: try {
051: InitialContext jndiContext = new InitialContext();
052:
053: Object ref = jndiContext.lookup("commerce/Customer");
054:
055: // Get a reference from this to the Bean's Home interface
056: return (CustomerHome) PortableRemoteObject.narrow(ref,
057: CustomerHome.class);
058: } catch (Exception e) {
059: fail("Exception in getCustomerHome: " + e.getMessage());
060: }
061: return null;
062: }
063:
064: public void testUserQueries() throws Exception {
065: UserHome home = getUserHome();
066: home.findAllByUserName("Test User 1");
067: }
068:
069: public void testAddCd() {
070: /*
071: try {
072: UserHome userHome = getUserHome();
073:
074: String userId = "dain";
075: String userName = "Dain Sundstrom";
076: String email = "dain@daingroup.com";
077:
078: User user = userHome.create(userId);
079: user.setUserName(userName);
080: user.setEmail(email);
081: user.setSendSpam(false);
082:
083: assertEquals(userId, user.getUserId());
084: assertEquals(userName, user.getUserName());
085: assertEquals(email, user.getEmail());
086: assertEquals(false, user.getSendSpam());
087:
088: user = null;
089:
090: user = userHome.findByUserName(userName);
091: assertEquals(userId, user.getUserId());
092: assertEquals(userName, user.getUserName());
093: assertEquals(email, user.getEmail());
094: assertEquals(false, user.getSendSpam());
095:
096: // test customer -> user relationship
097: CustomerHome customerHome = getCustomerHome();
098: Customer customer = customerHome.create(new Long(random.nextLong()));
099: customer.setName("The Daingroup, LLC.");
100: customer.setUser(user);
101:
102: // is the user correct
103: assertTrue(user.isIdentical(customer.getUser()));
104:
105: user = customer.getUser();
106: assertEquals(userId, user.getUserId());
107: assertEquals(userName, user.getUserName());
108: assertEquals(email, user.getEmail());
109: assertEquals(false, user.getSendSpam());
110:
111: // set cutomer to null and see if it stays null
112: customer.setUser(null);
113: assertNull(customer.getUser());
114:
115: // reset user
116: customer.setUser(user);
117:
118: // removing user
119: userHome.remove(user.getPrimaryKey());
120:
121: try {
122: user = userHome.findByUserName(userName);
123: fail("should throw ObjectNotFoundException");
124: } catch(ObjectNotFoundException e) {
125: }
126:
127: // user was deleted so customer's user ref should be null
128: assertNull(customer.getUser());
129:
130: customer.remove();
131: } catch(Exception e) {
132: e.printStackTrace();
133: fail("Error in big old method: ");
134: }
135: */
136: }
137:
138: public static Test suite() {
139: return new TestSuite(UserTest.class);
140: }
141: }
|