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.NoSuchStatsException;
027: import com.liferay.portlet.ratings.model.RatingsStats;
028:
029: /**
030: * <a href="RatingsStatsPersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class RatingsStatsPersistenceTest extends
036: BasePersistenceTestCase {
037: protected void setUp() throws Exception {
038: super .setUp();
039:
040: _persistence = (RatingsStatsPersistence) BeanLocatorUtil
041: .locate(_TX_IMPL);
042: }
043:
044: public void testCreate() throws Exception {
045: long pk = nextLong();
046:
047: RatingsStats ratingsStats = _persistence.create(pk);
048:
049: assertNotNull(ratingsStats);
050:
051: assertEquals(ratingsStats.getPrimaryKey(), pk);
052: }
053:
054: public void testRemove() throws Exception {
055: RatingsStats newRatingsStats = addRatingsStats();
056:
057: _persistence.remove(newRatingsStats);
058:
059: RatingsStats existingRatingsStats = _persistence
060: .fetchByPrimaryKey(newRatingsStats.getPrimaryKey());
061:
062: assertNull(existingRatingsStats);
063: }
064:
065: public void testUpdateNew() throws Exception {
066: addRatingsStats();
067: }
068:
069: public void testUpdateExisting() throws Exception {
070: long pk = nextLong();
071:
072: RatingsStats newRatingsStats = _persistence.create(pk);
073:
074: newRatingsStats.setClassNameId(nextLong());
075: newRatingsStats.setClassPK(nextLong());
076: newRatingsStats.setTotalEntries(nextInt());
077: newRatingsStats.setTotalScore(nextDouble());
078: newRatingsStats.setAverageScore(nextDouble());
079:
080: _persistence.update(newRatingsStats);
081:
082: RatingsStats existingRatingsStats = _persistence
083: .findByPrimaryKey(newRatingsStats.getPrimaryKey());
084:
085: assertEquals(existingRatingsStats.getStatsId(), newRatingsStats
086: .getStatsId());
087: assertEquals(existingRatingsStats.getClassNameId(),
088: newRatingsStats.getClassNameId());
089: assertEquals(existingRatingsStats.getClassPK(), newRatingsStats
090: .getClassPK());
091: assertEquals(existingRatingsStats.getTotalEntries(),
092: newRatingsStats.getTotalEntries());
093: assertEquals(existingRatingsStats.getTotalScore(),
094: newRatingsStats.getTotalScore());
095: assertEquals(existingRatingsStats.getAverageScore(),
096: newRatingsStats.getAverageScore());
097: }
098:
099: public void testFindByPrimaryKeyExisting() throws Exception {
100: RatingsStats newRatingsStats = addRatingsStats();
101:
102: RatingsStats existingRatingsStats = _persistence
103: .findByPrimaryKey(newRatingsStats.getPrimaryKey());
104:
105: assertEquals(existingRatingsStats, newRatingsStats);
106: }
107:
108: public void testFindByPrimaryKeyMissing() throws Exception {
109: long pk = nextLong();
110:
111: try {
112: _persistence.findByPrimaryKey(pk);
113:
114: fail("Missing entity did not throw NoSuchStatsException");
115: } catch (NoSuchStatsException nsee) {
116: }
117: }
118:
119: public void testFetchByPrimaryKeyExisting() throws Exception {
120: RatingsStats newRatingsStats = addRatingsStats();
121:
122: RatingsStats existingRatingsStats = _persistence
123: .fetchByPrimaryKey(newRatingsStats.getPrimaryKey());
124:
125: assertEquals(existingRatingsStats, newRatingsStats);
126: }
127:
128: public void testFetchByPrimaryKeyMissing() throws Exception {
129: long pk = nextLong();
130:
131: RatingsStats missingRatingsStats = _persistence
132: .fetchByPrimaryKey(pk);
133:
134: assertNull(missingRatingsStats);
135: }
136:
137: protected RatingsStats addRatingsStats() throws Exception {
138: long pk = nextLong();
139:
140: RatingsStats ratingsStats = _persistence.create(pk);
141:
142: ratingsStats.setClassNameId(nextLong());
143: ratingsStats.setClassPK(nextLong());
144: ratingsStats.setTotalEntries(nextInt());
145: ratingsStats.setTotalScore(nextDouble());
146: ratingsStats.setAverageScore(nextDouble());
147:
148: _persistence.update(ratingsStats);
149:
150: return ratingsStats;
151: }
152:
153: private static final String _TX_IMPL = RatingsStatsPersistence.class
154: .getName()
155: + ".transaction";
156: private RatingsStatsPersistence _persistence;
157: }
|