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.NoSuchPasswordTrackerException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.PasswordTracker;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="PasswordTrackerPersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class PasswordTrackerPersistenceTest extends
035: BasePersistenceTestCase {
036: protected void setUp() throws Exception {
037: super .setUp();
038:
039: _persistence = (PasswordTrackerPersistence) BeanLocatorUtil
040: .locate(_TX_IMPL);
041: }
042:
043: public void testCreate() throws Exception {
044: long pk = nextLong();
045:
046: PasswordTracker passwordTracker = _persistence.create(pk);
047:
048: assertNotNull(passwordTracker);
049:
050: assertEquals(passwordTracker.getPrimaryKey(), pk);
051: }
052:
053: public void testRemove() throws Exception {
054: PasswordTracker newPasswordTracker = addPasswordTracker();
055:
056: _persistence.remove(newPasswordTracker);
057:
058: PasswordTracker existingPasswordTracker = _persistence
059: .fetchByPrimaryKey(newPasswordTracker.getPrimaryKey());
060:
061: assertNull(existingPasswordTracker);
062: }
063:
064: public void testUpdateNew() throws Exception {
065: addPasswordTracker();
066: }
067:
068: public void testUpdateExisting() throws Exception {
069: long pk = nextLong();
070:
071: PasswordTracker newPasswordTracker = _persistence.create(pk);
072:
073: newPasswordTracker.setUserId(nextLong());
074: newPasswordTracker.setCreateDate(nextDate());
075: newPasswordTracker.setPassword(randomString());
076:
077: _persistence.update(newPasswordTracker);
078:
079: PasswordTracker existingPasswordTracker = _persistence
080: .findByPrimaryKey(newPasswordTracker.getPrimaryKey());
081:
082: assertEquals(existingPasswordTracker.getPasswordTrackerId(),
083: newPasswordTracker.getPasswordTrackerId());
084: assertEquals(existingPasswordTracker.getUserId(),
085: newPasswordTracker.getUserId());
086: assertEquals(existingPasswordTracker.getCreateDate(),
087: newPasswordTracker.getCreateDate());
088: assertEquals(existingPasswordTracker.getPassword(),
089: newPasswordTracker.getPassword());
090: }
091:
092: public void testFindByPrimaryKeyExisting() throws Exception {
093: PasswordTracker newPasswordTracker = addPasswordTracker();
094:
095: PasswordTracker existingPasswordTracker = _persistence
096: .findByPrimaryKey(newPasswordTracker.getPrimaryKey());
097:
098: assertEquals(existingPasswordTracker, newPasswordTracker);
099: }
100:
101: public void testFindByPrimaryKeyMissing() throws Exception {
102: long pk = nextLong();
103:
104: try {
105: _persistence.findByPrimaryKey(pk);
106:
107: fail("Missing entity did not throw NoSuchPasswordTrackerException");
108: } catch (NoSuchPasswordTrackerException nsee) {
109: }
110: }
111:
112: public void testFetchByPrimaryKeyExisting() throws Exception {
113: PasswordTracker newPasswordTracker = addPasswordTracker();
114:
115: PasswordTracker existingPasswordTracker = _persistence
116: .fetchByPrimaryKey(newPasswordTracker.getPrimaryKey());
117:
118: assertEquals(existingPasswordTracker, newPasswordTracker);
119: }
120:
121: public void testFetchByPrimaryKeyMissing() throws Exception {
122: long pk = nextLong();
123:
124: PasswordTracker missingPasswordTracker = _persistence
125: .fetchByPrimaryKey(pk);
126:
127: assertNull(missingPasswordTracker);
128: }
129:
130: protected PasswordTracker addPasswordTracker() throws Exception {
131: long pk = nextLong();
132:
133: PasswordTracker passwordTracker = _persistence.create(pk);
134:
135: passwordTracker.setUserId(nextLong());
136: passwordTracker.setCreateDate(nextDate());
137: passwordTracker.setPassword(randomString());
138:
139: _persistence.update(passwordTracker);
140:
141: return passwordTracker;
142: }
143:
144: private static final String _TX_IMPL = PasswordTrackerPersistence.class
145: .getName()
146: + ".transaction";
147: private PasswordTrackerPersistence _persistence;
148: }
|