001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.persistence;
022:
023: import com.liferay.portal.NoSuchUserException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.User;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="UserPersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class UserPersistenceTest extends BasePersistenceTestCase {
035: protected void setUp() throws Exception {
036: super .setUp();
037:
038: _persistence = (UserPersistence) BeanLocatorUtil
039: .locate(_TX_IMPL);
040: }
041:
042: public void testCreate() throws Exception {
043: long pk = nextLong();
044:
045: User user = _persistence.create(pk);
046:
047: assertNotNull(user);
048:
049: assertEquals(user.getPrimaryKey(), pk);
050: }
051:
052: public void testRemove() throws Exception {
053: User newUser = addUser();
054:
055: _persistence.remove(newUser);
056:
057: User existingUser = _persistence.fetchByPrimaryKey(newUser
058: .getPrimaryKey());
059:
060: assertNull(existingUser);
061: }
062:
063: public void testUpdateNew() throws Exception {
064: addUser();
065: }
066:
067: public void testUpdateExisting() throws Exception {
068: long pk = nextLong();
069:
070: User newUser = _persistence.create(pk);
071:
072: newUser.setUuid(randomString());
073: newUser.setCompanyId(nextLong());
074: newUser.setCreateDate(nextDate());
075: newUser.setModifiedDate(nextDate());
076: newUser.setDefaultUser(randomBoolean());
077: newUser.setContactId(nextLong());
078: newUser.setPassword(randomString());
079: newUser.setPasswordEncrypted(randomBoolean());
080: newUser.setPasswordReset(randomBoolean());
081: newUser.setPasswordModifiedDate(nextDate());
082: newUser.setGraceLoginCount(nextInt());
083: newUser.setScreenName(randomString());
084: newUser.setEmailAddress(randomString());
085: newUser.setPortraitId(nextLong());
086: newUser.setLanguageId(randomString());
087: newUser.setTimeZoneId(randomString());
088: newUser.setGreeting(randomString());
089: newUser.setComments(randomString());
090: newUser.setLoginDate(nextDate());
091: newUser.setLoginIP(randomString());
092: newUser.setLastLoginDate(nextDate());
093: newUser.setLastLoginIP(randomString());
094: newUser.setLastFailedLoginDate(nextDate());
095: newUser.setFailedLoginAttempts(nextInt());
096: newUser.setLockout(randomBoolean());
097: newUser.setLockoutDate(nextDate());
098: newUser.setAgreedToTermsOfUse(randomBoolean());
099: newUser.setActive(randomBoolean());
100:
101: _persistence.update(newUser);
102:
103: User existingUser = _persistence.findByPrimaryKey(newUser
104: .getPrimaryKey());
105:
106: assertEquals(existingUser.getUuid(), newUser.getUuid());
107: assertEquals(existingUser.getUserId(), newUser.getUserId());
108: assertEquals(existingUser.getCompanyId(), newUser
109: .getCompanyId());
110: assertEquals(existingUser.getCreateDate(), newUser
111: .getCreateDate());
112: assertEquals(existingUser.getModifiedDate(), newUser
113: .getModifiedDate());
114: assertEquals(existingUser.getDefaultUser(), newUser
115: .getDefaultUser());
116: assertEquals(existingUser.getContactId(), newUser
117: .getContactId());
118: assertEquals(existingUser.getPassword(), newUser.getPassword());
119: assertEquals(existingUser.getPasswordEncrypted(), newUser
120: .getPasswordEncrypted());
121: assertEquals(existingUser.getPasswordReset(), newUser
122: .getPasswordReset());
123: assertEquals(existingUser.getPasswordModifiedDate(), newUser
124: .getPasswordModifiedDate());
125: assertEquals(existingUser.getGraceLoginCount(), newUser
126: .getGraceLoginCount());
127: assertEquals(existingUser.getScreenName(), newUser
128: .getScreenName());
129: assertEquals(existingUser.getEmailAddress(), newUser
130: .getEmailAddress());
131: assertEquals(existingUser.getPortraitId(), newUser
132: .getPortraitId());
133: assertEquals(existingUser.getLanguageId(), newUser
134: .getLanguageId());
135: assertEquals(existingUser.getTimeZoneId(), newUser
136: .getTimeZoneId());
137: assertEquals(existingUser.getGreeting(), newUser.getGreeting());
138: assertEquals(existingUser.getComments(), newUser.getComments());
139: assertEquals(existingUser.getLoginDate(), newUser
140: .getLoginDate());
141: assertEquals(existingUser.getLoginIP(), newUser.getLoginIP());
142: assertEquals(existingUser.getLastLoginDate(), newUser
143: .getLastLoginDate());
144: assertEquals(existingUser.getLastLoginIP(), newUser
145: .getLastLoginIP());
146: assertEquals(existingUser.getLastFailedLoginDate(), newUser
147: .getLastFailedLoginDate());
148: assertEquals(existingUser.getFailedLoginAttempts(), newUser
149: .getFailedLoginAttempts());
150: assertEquals(existingUser.getLockout(), newUser.getLockout());
151: assertEquals(existingUser.getLockoutDate(), newUser
152: .getLockoutDate());
153: assertEquals(existingUser.getAgreedToTermsOfUse(), newUser
154: .getAgreedToTermsOfUse());
155: assertEquals(existingUser.getActive(), newUser.getActive());
156: }
157:
158: public void testFindByPrimaryKeyExisting() throws Exception {
159: User newUser = addUser();
160:
161: User existingUser = _persistence.findByPrimaryKey(newUser
162: .getPrimaryKey());
163:
164: assertEquals(existingUser, newUser);
165: }
166:
167: public void testFindByPrimaryKeyMissing() throws Exception {
168: long pk = nextLong();
169:
170: try {
171: _persistence.findByPrimaryKey(pk);
172:
173: fail("Missing entity did not throw NoSuchUserException");
174: } catch (NoSuchUserException nsee) {
175: }
176: }
177:
178: public void testFetchByPrimaryKeyExisting() throws Exception {
179: User newUser = addUser();
180:
181: User existingUser = _persistence.fetchByPrimaryKey(newUser
182: .getPrimaryKey());
183:
184: assertEquals(existingUser, newUser);
185: }
186:
187: public void testFetchByPrimaryKeyMissing() throws Exception {
188: long pk = nextLong();
189:
190: User missingUser = _persistence.fetchByPrimaryKey(pk);
191:
192: assertNull(missingUser);
193: }
194:
195: protected User addUser() throws Exception {
196: long pk = nextLong();
197:
198: User user = _persistence.create(pk);
199:
200: user.setUuid(randomString());
201: user.setCompanyId(nextLong());
202: user.setCreateDate(nextDate());
203: user.setModifiedDate(nextDate());
204: user.setDefaultUser(randomBoolean());
205: user.setContactId(nextLong());
206: user.setPassword(randomString());
207: user.setPasswordEncrypted(randomBoolean());
208: user.setPasswordReset(randomBoolean());
209: user.setPasswordModifiedDate(nextDate());
210: user.setGraceLoginCount(nextInt());
211: user.setScreenName(randomString());
212: user.setEmailAddress(randomString());
213: user.setPortraitId(nextLong());
214: user.setLanguageId(randomString());
215: user.setTimeZoneId(randomString());
216: user.setGreeting(randomString());
217: user.setComments(randomString());
218: user.setLoginDate(nextDate());
219: user.setLoginIP(randomString());
220: user.setLastLoginDate(nextDate());
221: user.setLastLoginIP(randomString());
222: user.setLastFailedLoginDate(nextDate());
223: user.setFailedLoginAttempts(nextInt());
224: user.setLockout(randomBoolean());
225: user.setLockoutDate(nextDate());
226: user.setAgreedToTermsOfUse(randomBoolean());
227: user.setActive(randomBoolean());
228:
229: _persistence.update(user);
230:
231: return user;
232: }
233:
234: private static final String _TX_IMPL = UserPersistence.class
235: .getName()
236: + ".transaction";
237: private UserPersistence _persistence;
238: }
|