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.NoSuchPasswordPolicyException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.PasswordPolicy;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="PasswordPolicyPersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class PasswordPolicyPersistenceTest extends
035: BasePersistenceTestCase {
036: protected void setUp() throws Exception {
037: super .setUp();
038:
039: _persistence = (PasswordPolicyPersistence) BeanLocatorUtil
040: .locate(_TX_IMPL);
041: }
042:
043: public void testCreate() throws Exception {
044: long pk = nextLong();
045:
046: PasswordPolicy passwordPolicy = _persistence.create(pk);
047:
048: assertNotNull(passwordPolicy);
049:
050: assertEquals(passwordPolicy.getPrimaryKey(), pk);
051: }
052:
053: public void testRemove() throws Exception {
054: PasswordPolicy newPasswordPolicy = addPasswordPolicy();
055:
056: _persistence.remove(newPasswordPolicy);
057:
058: PasswordPolicy existingPasswordPolicy = _persistence
059: .fetchByPrimaryKey(newPasswordPolicy.getPrimaryKey());
060:
061: assertNull(existingPasswordPolicy);
062: }
063:
064: public void testUpdateNew() throws Exception {
065: addPasswordPolicy();
066: }
067:
068: public void testUpdateExisting() throws Exception {
069: long pk = nextLong();
070:
071: PasswordPolicy newPasswordPolicy = _persistence.create(pk);
072:
073: newPasswordPolicy.setCompanyId(nextLong());
074: newPasswordPolicy.setUserId(nextLong());
075: newPasswordPolicy.setUserName(randomString());
076: newPasswordPolicy.setCreateDate(nextDate());
077: newPasswordPolicy.setModifiedDate(nextDate());
078: newPasswordPolicy.setDefaultPolicy(randomBoolean());
079: newPasswordPolicy.setName(randomString());
080: newPasswordPolicy.setDescription(randomString());
081: newPasswordPolicy.setChangeable(randomBoolean());
082: newPasswordPolicy.setChangeRequired(randomBoolean());
083: newPasswordPolicy.setMinAge(nextLong());
084: newPasswordPolicy.setCheckSyntax(randomBoolean());
085: newPasswordPolicy.setAllowDictionaryWords(randomBoolean());
086: newPasswordPolicy.setMinLength(nextInt());
087: newPasswordPolicy.setHistory(randomBoolean());
088: newPasswordPolicy.setHistoryCount(nextInt());
089: newPasswordPolicy.setExpireable(randomBoolean());
090: newPasswordPolicy.setMaxAge(nextLong());
091: newPasswordPolicy.setWarningTime(nextLong());
092: newPasswordPolicy.setGraceLimit(nextInt());
093: newPasswordPolicy.setLockout(randomBoolean());
094: newPasswordPolicy.setMaxFailure(nextInt());
095: newPasswordPolicy.setLockoutDuration(nextLong());
096: newPasswordPolicy.setRequireUnlock(randomBoolean());
097: newPasswordPolicy.setResetFailureCount(nextLong());
098:
099: _persistence.update(newPasswordPolicy);
100:
101: PasswordPolicy existingPasswordPolicy = _persistence
102: .findByPrimaryKey(newPasswordPolicy.getPrimaryKey());
103:
104: assertEquals(existingPasswordPolicy.getPasswordPolicyId(),
105: newPasswordPolicy.getPasswordPolicyId());
106: assertEquals(existingPasswordPolicy.getCompanyId(),
107: newPasswordPolicy.getCompanyId());
108: assertEquals(existingPasswordPolicy.getUserId(),
109: newPasswordPolicy.getUserId());
110: assertEquals(existingPasswordPolicy.getUserName(),
111: newPasswordPolicy.getUserName());
112: assertEquals(existingPasswordPolicy.getCreateDate(),
113: newPasswordPolicy.getCreateDate());
114: assertEquals(existingPasswordPolicy.getModifiedDate(),
115: newPasswordPolicy.getModifiedDate());
116: assertEquals(existingPasswordPolicy.getDefaultPolicy(),
117: newPasswordPolicy.getDefaultPolicy());
118: assertEquals(existingPasswordPolicy.getName(),
119: newPasswordPolicy.getName());
120: assertEquals(existingPasswordPolicy.getDescription(),
121: newPasswordPolicy.getDescription());
122: assertEquals(existingPasswordPolicy.getChangeable(),
123: newPasswordPolicy.getChangeable());
124: assertEquals(existingPasswordPolicy.getChangeRequired(),
125: newPasswordPolicy.getChangeRequired());
126: assertEquals(existingPasswordPolicy.getMinAge(),
127: newPasswordPolicy.getMinAge());
128: assertEquals(existingPasswordPolicy.getCheckSyntax(),
129: newPasswordPolicy.getCheckSyntax());
130: assertEquals(existingPasswordPolicy.getAllowDictionaryWords(),
131: newPasswordPolicy.getAllowDictionaryWords());
132: assertEquals(existingPasswordPolicy.getMinLength(),
133: newPasswordPolicy.getMinLength());
134: assertEquals(existingPasswordPolicy.getHistory(),
135: newPasswordPolicy.getHistory());
136: assertEquals(existingPasswordPolicy.getHistoryCount(),
137: newPasswordPolicy.getHistoryCount());
138: assertEquals(existingPasswordPolicy.getExpireable(),
139: newPasswordPolicy.getExpireable());
140: assertEquals(existingPasswordPolicy.getMaxAge(),
141: newPasswordPolicy.getMaxAge());
142: assertEquals(existingPasswordPolicy.getWarningTime(),
143: newPasswordPolicy.getWarningTime());
144: assertEquals(existingPasswordPolicy.getGraceLimit(),
145: newPasswordPolicy.getGraceLimit());
146: assertEquals(existingPasswordPolicy.getLockout(),
147: newPasswordPolicy.getLockout());
148: assertEquals(existingPasswordPolicy.getMaxFailure(),
149: newPasswordPolicy.getMaxFailure());
150: assertEquals(existingPasswordPolicy.getLockoutDuration(),
151: newPasswordPolicy.getLockoutDuration());
152: assertEquals(existingPasswordPolicy.getRequireUnlock(),
153: newPasswordPolicy.getRequireUnlock());
154: assertEquals(existingPasswordPolicy.getResetFailureCount(),
155: newPasswordPolicy.getResetFailureCount());
156: }
157:
158: public void testFindByPrimaryKeyExisting() throws Exception {
159: PasswordPolicy newPasswordPolicy = addPasswordPolicy();
160:
161: PasswordPolicy existingPasswordPolicy = _persistence
162: .findByPrimaryKey(newPasswordPolicy.getPrimaryKey());
163:
164: assertEquals(existingPasswordPolicy, newPasswordPolicy);
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 NoSuchPasswordPolicyException");
174: } catch (NoSuchPasswordPolicyException nsee) {
175: }
176: }
177:
178: public void testFetchByPrimaryKeyExisting() throws Exception {
179: PasswordPolicy newPasswordPolicy = addPasswordPolicy();
180:
181: PasswordPolicy existingPasswordPolicy = _persistence
182: .fetchByPrimaryKey(newPasswordPolicy.getPrimaryKey());
183:
184: assertEquals(existingPasswordPolicy, newPasswordPolicy);
185: }
186:
187: public void testFetchByPrimaryKeyMissing() throws Exception {
188: long pk = nextLong();
189:
190: PasswordPolicy missingPasswordPolicy = _persistence
191: .fetchByPrimaryKey(pk);
192:
193: assertNull(missingPasswordPolicy);
194: }
195:
196: protected PasswordPolicy addPasswordPolicy() throws Exception {
197: long pk = nextLong();
198:
199: PasswordPolicy passwordPolicy = _persistence.create(pk);
200:
201: passwordPolicy.setCompanyId(nextLong());
202: passwordPolicy.setUserId(nextLong());
203: passwordPolicy.setUserName(randomString());
204: passwordPolicy.setCreateDate(nextDate());
205: passwordPolicy.setModifiedDate(nextDate());
206: passwordPolicy.setDefaultPolicy(randomBoolean());
207: passwordPolicy.setName(randomString());
208: passwordPolicy.setDescription(randomString());
209: passwordPolicy.setChangeable(randomBoolean());
210: passwordPolicy.setChangeRequired(randomBoolean());
211: passwordPolicy.setMinAge(nextLong());
212: passwordPolicy.setCheckSyntax(randomBoolean());
213: passwordPolicy.setAllowDictionaryWords(randomBoolean());
214: passwordPolicy.setMinLength(nextInt());
215: passwordPolicy.setHistory(randomBoolean());
216: passwordPolicy.setHistoryCount(nextInt());
217: passwordPolicy.setExpireable(randomBoolean());
218: passwordPolicy.setMaxAge(nextLong());
219: passwordPolicy.setWarningTime(nextLong());
220: passwordPolicy.setGraceLimit(nextInt());
221: passwordPolicy.setLockout(randomBoolean());
222: passwordPolicy.setMaxFailure(nextInt());
223: passwordPolicy.setLockoutDuration(nextLong());
224: passwordPolicy.setRequireUnlock(randomBoolean());
225: passwordPolicy.setResetFailureCount(nextLong());
226:
227: _persistence.update(passwordPolicy);
228:
229: return passwordPolicy;
230: }
231:
232: private static final String _TX_IMPL = PasswordPolicyPersistence.class
233: .getName()
234: + ".transaction";
235: private PasswordPolicyPersistence _persistence;
236: }
|