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