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.blogs.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.blogs.NoSuchStatsUserException;
027: import com.liferay.portlet.blogs.model.BlogsStatsUser;
028:
029: /**
030: * <a href="BlogsStatsUserPersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class BlogsStatsUserPersistenceTest extends
036: BasePersistenceTestCase {
037: protected void setUp() throws Exception {
038: super .setUp();
039:
040: _persistence = (BlogsStatsUserPersistence) BeanLocatorUtil
041: .locate(_TX_IMPL);
042: }
043:
044: public void testCreate() throws Exception {
045: long pk = nextLong();
046:
047: BlogsStatsUser blogsStatsUser = _persistence.create(pk);
048:
049: assertNotNull(blogsStatsUser);
050:
051: assertEquals(blogsStatsUser.getPrimaryKey(), pk);
052: }
053:
054: public void testRemove() throws Exception {
055: BlogsStatsUser newBlogsStatsUser = addBlogsStatsUser();
056:
057: _persistence.remove(newBlogsStatsUser);
058:
059: BlogsStatsUser existingBlogsStatsUser = _persistence
060: .fetchByPrimaryKey(newBlogsStatsUser.getPrimaryKey());
061:
062: assertNull(existingBlogsStatsUser);
063: }
064:
065: public void testUpdateNew() throws Exception {
066: addBlogsStatsUser();
067: }
068:
069: public void testUpdateExisting() throws Exception {
070: long pk = nextLong();
071:
072: BlogsStatsUser newBlogsStatsUser = _persistence.create(pk);
073:
074: newBlogsStatsUser.setGroupId(nextLong());
075: newBlogsStatsUser.setCompanyId(nextLong());
076: newBlogsStatsUser.setUserId(nextLong());
077: newBlogsStatsUser.setEntryCount(nextInt());
078: newBlogsStatsUser.setLastPostDate(nextDate());
079: newBlogsStatsUser.setRatingsTotalEntries(nextInt());
080: newBlogsStatsUser.setRatingsTotalScore(nextDouble());
081: newBlogsStatsUser.setRatingsAverageScore(nextDouble());
082:
083: _persistence.update(newBlogsStatsUser);
084:
085: BlogsStatsUser existingBlogsStatsUser = _persistence
086: .findByPrimaryKey(newBlogsStatsUser.getPrimaryKey());
087:
088: assertEquals(existingBlogsStatsUser.getStatsUserId(),
089: newBlogsStatsUser.getStatsUserId());
090: assertEquals(existingBlogsStatsUser.getGroupId(),
091: newBlogsStatsUser.getGroupId());
092: assertEquals(existingBlogsStatsUser.getCompanyId(),
093: newBlogsStatsUser.getCompanyId());
094: assertEquals(existingBlogsStatsUser.getUserId(),
095: newBlogsStatsUser.getUserId());
096: assertEquals(existingBlogsStatsUser.getEntryCount(),
097: newBlogsStatsUser.getEntryCount());
098: assertEquals(existingBlogsStatsUser.getLastPostDate(),
099: newBlogsStatsUser.getLastPostDate());
100: assertEquals(existingBlogsStatsUser.getRatingsTotalEntries(),
101: newBlogsStatsUser.getRatingsTotalEntries());
102: assertEquals(existingBlogsStatsUser.getRatingsTotalScore(),
103: newBlogsStatsUser.getRatingsTotalScore());
104: assertEquals(existingBlogsStatsUser.getRatingsAverageScore(),
105: newBlogsStatsUser.getRatingsAverageScore());
106: }
107:
108: public void testFindByPrimaryKeyExisting() throws Exception {
109: BlogsStatsUser newBlogsStatsUser = addBlogsStatsUser();
110:
111: BlogsStatsUser existingBlogsStatsUser = _persistence
112: .findByPrimaryKey(newBlogsStatsUser.getPrimaryKey());
113:
114: assertEquals(existingBlogsStatsUser, newBlogsStatsUser);
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 NoSuchStatsUserException");
124: } catch (NoSuchStatsUserException nsee) {
125: }
126: }
127:
128: public void testFetchByPrimaryKeyExisting() throws Exception {
129: BlogsStatsUser newBlogsStatsUser = addBlogsStatsUser();
130:
131: BlogsStatsUser existingBlogsStatsUser = _persistence
132: .fetchByPrimaryKey(newBlogsStatsUser.getPrimaryKey());
133:
134: assertEquals(existingBlogsStatsUser, newBlogsStatsUser);
135: }
136:
137: public void testFetchByPrimaryKeyMissing() throws Exception {
138: long pk = nextLong();
139:
140: BlogsStatsUser missingBlogsStatsUser = _persistence
141: .fetchByPrimaryKey(pk);
142:
143: assertNull(missingBlogsStatsUser);
144: }
145:
146: protected BlogsStatsUser addBlogsStatsUser() throws Exception {
147: long pk = nextLong();
148:
149: BlogsStatsUser blogsStatsUser = _persistence.create(pk);
150:
151: blogsStatsUser.setGroupId(nextLong());
152: blogsStatsUser.setCompanyId(nextLong());
153: blogsStatsUser.setUserId(nextLong());
154: blogsStatsUser.setEntryCount(nextInt());
155: blogsStatsUser.setLastPostDate(nextDate());
156: blogsStatsUser.setRatingsTotalEntries(nextInt());
157: blogsStatsUser.setRatingsTotalScore(nextDouble());
158: blogsStatsUser.setRatingsAverageScore(nextDouble());
159:
160: _persistence.update(blogsStatsUser);
161:
162: return blogsStatsUser;
163: }
164:
165: private static final String _TX_IMPL = BlogsStatsUserPersistence.class
166: .getName()
167: + ".transaction";
168: private BlogsStatsUserPersistence _persistence;
169: }
|