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