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