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