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.NoSuchActivityTrackerException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.ActivityTracker;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="ActivityTrackerPersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class ActivityTrackerPersistenceTest extends
035: BasePersistenceTestCase {
036: protected void setUp() throws Exception {
037: super .setUp();
038:
039: _persistence = (ActivityTrackerPersistence) BeanLocatorUtil
040: .locate(_TX_IMPL);
041: }
042:
043: public void testCreate() throws Exception {
044: long pk = nextLong();
045:
046: ActivityTracker activityTracker = _persistence.create(pk);
047:
048: assertNotNull(activityTracker);
049:
050: assertEquals(activityTracker.getPrimaryKey(), pk);
051: }
052:
053: public void testRemove() throws Exception {
054: ActivityTracker newActivityTracker = addActivityTracker();
055:
056: _persistence.remove(newActivityTracker);
057:
058: ActivityTracker existingActivityTracker = _persistence
059: .fetchByPrimaryKey(newActivityTracker.getPrimaryKey());
060:
061: assertNull(existingActivityTracker);
062: }
063:
064: public void testUpdateNew() throws Exception {
065: addActivityTracker();
066: }
067:
068: public void testUpdateExisting() throws Exception {
069: long pk = nextLong();
070:
071: ActivityTracker newActivityTracker = _persistence.create(pk);
072:
073: newActivityTracker.setGroupId(nextLong());
074: newActivityTracker.setCompanyId(nextLong());
075: newActivityTracker.setUserId(nextLong());
076: newActivityTracker.setUserName(randomString());
077: newActivityTracker.setCreateDate(nextDate());
078: newActivityTracker.setClassNameId(nextLong());
079: newActivityTracker.setClassPK(nextLong());
080: newActivityTracker.setActivity(randomString());
081: newActivityTracker.setExtraData(randomString());
082: newActivityTracker.setReceiverUserId(nextLong());
083: newActivityTracker.setReceiverUserName(randomString());
084:
085: _persistence.update(newActivityTracker);
086:
087: ActivityTracker existingActivityTracker = _persistence
088: .findByPrimaryKey(newActivityTracker.getPrimaryKey());
089:
090: assertEquals(existingActivityTracker.getActivityTrackerId(),
091: newActivityTracker.getActivityTrackerId());
092: assertEquals(existingActivityTracker.getGroupId(),
093: newActivityTracker.getGroupId());
094: assertEquals(existingActivityTracker.getCompanyId(),
095: newActivityTracker.getCompanyId());
096: assertEquals(existingActivityTracker.getUserId(),
097: newActivityTracker.getUserId());
098: assertEquals(existingActivityTracker.getUserName(),
099: newActivityTracker.getUserName());
100: assertEquals(existingActivityTracker.getCreateDate(),
101: newActivityTracker.getCreateDate());
102: assertEquals(existingActivityTracker.getClassNameId(),
103: newActivityTracker.getClassNameId());
104: assertEquals(existingActivityTracker.getClassPK(),
105: newActivityTracker.getClassPK());
106: assertEquals(existingActivityTracker.getActivity(),
107: newActivityTracker.getActivity());
108: assertEquals(existingActivityTracker.getExtraData(),
109: newActivityTracker.getExtraData());
110: assertEquals(existingActivityTracker.getReceiverUserId(),
111: newActivityTracker.getReceiverUserId());
112: assertEquals(existingActivityTracker.getReceiverUserName(),
113: newActivityTracker.getReceiverUserName());
114: }
115:
116: public void testFindByPrimaryKeyExisting() throws Exception {
117: ActivityTracker newActivityTracker = addActivityTracker();
118:
119: ActivityTracker existingActivityTracker = _persistence
120: .findByPrimaryKey(newActivityTracker.getPrimaryKey());
121:
122: assertEquals(existingActivityTracker, newActivityTracker);
123: }
124:
125: public void testFindByPrimaryKeyMissing() throws Exception {
126: long pk = nextLong();
127:
128: try {
129: _persistence.findByPrimaryKey(pk);
130:
131: fail("Missing entity did not throw NoSuchActivityTrackerException");
132: } catch (NoSuchActivityTrackerException nsee) {
133: }
134: }
135:
136: public void testFetchByPrimaryKeyExisting() throws Exception {
137: ActivityTracker newActivityTracker = addActivityTracker();
138:
139: ActivityTracker existingActivityTracker = _persistence
140: .fetchByPrimaryKey(newActivityTracker.getPrimaryKey());
141:
142: assertEquals(existingActivityTracker, newActivityTracker);
143: }
144:
145: public void testFetchByPrimaryKeyMissing() throws Exception {
146: long pk = nextLong();
147:
148: ActivityTracker missingActivityTracker = _persistence
149: .fetchByPrimaryKey(pk);
150:
151: assertNull(missingActivityTracker);
152: }
153:
154: protected ActivityTracker addActivityTracker() throws Exception {
155: long pk = nextLong();
156:
157: ActivityTracker activityTracker = _persistence.create(pk);
158:
159: activityTracker.setGroupId(nextLong());
160: activityTracker.setCompanyId(nextLong());
161: activityTracker.setUserId(nextLong());
162: activityTracker.setUserName(randomString());
163: activityTracker.setCreateDate(nextDate());
164: activityTracker.setClassNameId(nextLong());
165: activityTracker.setClassPK(nextLong());
166: activityTracker.setActivity(randomString());
167: activityTracker.setExtraData(randomString());
168: activityTracker.setReceiverUserId(nextLong());
169: activityTracker.setReceiverUserName(randomString());
170:
171: _persistence.update(activityTracker);
172:
173: return activityTracker;
174: }
175:
176: private static final String _TX_IMPL = ActivityTrackerPersistence.class
177: .getName()
178: + ".transaction";
179: private ActivityTrackerPersistence _persistence;
180: }
|