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.NoSuchMessageException;
027: import com.liferay.portlet.messageboards.model.MBMessage;
028:
029: /**
030: * <a href="MBMessagePersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class MBMessagePersistenceTest extends BasePersistenceTestCase {
036: protected void setUp() throws Exception {
037: super .setUp();
038:
039: _persistence = (MBMessagePersistence) BeanLocatorUtil
040: .locate(_TX_IMPL);
041: }
042:
043: public void testCreate() throws Exception {
044: long pk = nextLong();
045:
046: MBMessage mbMessage = _persistence.create(pk);
047:
048: assertNotNull(mbMessage);
049:
050: assertEquals(mbMessage.getPrimaryKey(), pk);
051: }
052:
053: public void testRemove() throws Exception {
054: MBMessage newMBMessage = addMBMessage();
055:
056: _persistence.remove(newMBMessage);
057:
058: MBMessage existingMBMessage = _persistence
059: .fetchByPrimaryKey(newMBMessage.getPrimaryKey());
060:
061: assertNull(existingMBMessage);
062: }
063:
064: public void testUpdateNew() throws Exception {
065: addMBMessage();
066: }
067:
068: public void testUpdateExisting() throws Exception {
069: long pk = nextLong();
070:
071: MBMessage newMBMessage = _persistence.create(pk);
072:
073: newMBMessage.setUuid(randomString());
074: newMBMessage.setCompanyId(nextLong());
075: newMBMessage.setUserId(nextLong());
076: newMBMessage.setUserName(randomString());
077: newMBMessage.setCreateDate(nextDate());
078: newMBMessage.setModifiedDate(nextDate());
079: newMBMessage.setCategoryId(nextLong());
080: newMBMessage.setThreadId(nextLong());
081: newMBMessage.setParentMessageId(nextLong());
082: newMBMessage.setSubject(randomString());
083: newMBMessage.setBody(randomString());
084: newMBMessage.setAttachments(randomBoolean());
085: newMBMessage.setAnonymous(randomBoolean());
086:
087: _persistence.update(newMBMessage);
088:
089: MBMessage existingMBMessage = _persistence
090: .findByPrimaryKey(newMBMessage.getPrimaryKey());
091:
092: assertEquals(existingMBMessage.getUuid(), newMBMessage
093: .getUuid());
094: assertEquals(existingMBMessage.getMessageId(), newMBMessage
095: .getMessageId());
096: assertEquals(existingMBMessage.getCompanyId(), newMBMessage
097: .getCompanyId());
098: assertEquals(existingMBMessage.getUserId(), newMBMessage
099: .getUserId());
100: assertEquals(existingMBMessage.getUserName(), newMBMessage
101: .getUserName());
102: assertEquals(existingMBMessage.getCreateDate(), newMBMessage
103: .getCreateDate());
104: assertEquals(existingMBMessage.getModifiedDate(), newMBMessage
105: .getModifiedDate());
106: assertEquals(existingMBMessage.getCategoryId(), newMBMessage
107: .getCategoryId());
108: assertEquals(existingMBMessage.getThreadId(), newMBMessage
109: .getThreadId());
110: assertEquals(existingMBMessage.getParentMessageId(),
111: newMBMessage.getParentMessageId());
112: assertEquals(existingMBMessage.getSubject(), newMBMessage
113: .getSubject());
114: assertEquals(existingMBMessage.getBody(), newMBMessage
115: .getBody());
116: assertEquals(existingMBMessage.getAttachments(), newMBMessage
117: .getAttachments());
118: assertEquals(existingMBMessage.getAnonymous(), newMBMessage
119: .getAnonymous());
120: }
121:
122: public void testFindByPrimaryKeyExisting() throws Exception {
123: MBMessage newMBMessage = addMBMessage();
124:
125: MBMessage existingMBMessage = _persistence
126: .findByPrimaryKey(newMBMessage.getPrimaryKey());
127:
128: assertEquals(existingMBMessage, newMBMessage);
129: }
130:
131: public void testFindByPrimaryKeyMissing() throws Exception {
132: long pk = nextLong();
133:
134: try {
135: _persistence.findByPrimaryKey(pk);
136:
137: fail("Missing entity did not throw NoSuchMessageException");
138: } catch (NoSuchMessageException nsee) {
139: }
140: }
141:
142: public void testFetchByPrimaryKeyExisting() throws Exception {
143: MBMessage newMBMessage = addMBMessage();
144:
145: MBMessage existingMBMessage = _persistence
146: .fetchByPrimaryKey(newMBMessage.getPrimaryKey());
147:
148: assertEquals(existingMBMessage, newMBMessage);
149: }
150:
151: public void testFetchByPrimaryKeyMissing() throws Exception {
152: long pk = nextLong();
153:
154: MBMessage missingMBMessage = _persistence.fetchByPrimaryKey(pk);
155:
156: assertNull(missingMBMessage);
157: }
158:
159: protected MBMessage addMBMessage() throws Exception {
160: long pk = nextLong();
161:
162: MBMessage mbMessage = _persistence.create(pk);
163:
164: mbMessage.setUuid(randomString());
165: mbMessage.setCompanyId(nextLong());
166: mbMessage.setUserId(nextLong());
167: mbMessage.setUserName(randomString());
168: mbMessage.setCreateDate(nextDate());
169: mbMessage.setModifiedDate(nextDate());
170: mbMessage.setCategoryId(nextLong());
171: mbMessage.setThreadId(nextLong());
172: mbMessage.setParentMessageId(nextLong());
173: mbMessage.setSubject(randomString());
174: mbMessage.setBody(randomString());
175: mbMessage.setAttachments(randomBoolean());
176: mbMessage.setAnonymous(randomBoolean());
177:
178: _persistence.update(mbMessage);
179:
180: return mbMessage;
181: }
182:
183: private static final String _TX_IMPL = MBMessagePersistence.class
184: .getName()
185: + ".transaction";
186: private MBMessagePersistence _persistence;
187: }
|