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.journal.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.journal.NoSuchArticleException;
027: import com.liferay.portlet.journal.model.JournalArticle;
028:
029: /**
030: * <a href="JournalArticlePersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class JournalArticlePersistenceTest extends
036: BasePersistenceTestCase {
037: protected void setUp() throws Exception {
038: super .setUp();
039:
040: _persistence = (JournalArticlePersistence) BeanLocatorUtil
041: .locate(_TX_IMPL);
042: }
043:
044: public void testCreate() throws Exception {
045: long pk = nextLong();
046:
047: JournalArticle journalArticle = _persistence.create(pk);
048:
049: assertNotNull(journalArticle);
050:
051: assertEquals(journalArticle.getPrimaryKey(), pk);
052: }
053:
054: public void testRemove() throws Exception {
055: JournalArticle newJournalArticle = addJournalArticle();
056:
057: _persistence.remove(newJournalArticle);
058:
059: JournalArticle existingJournalArticle = _persistence
060: .fetchByPrimaryKey(newJournalArticle.getPrimaryKey());
061:
062: assertNull(existingJournalArticle);
063: }
064:
065: public void testUpdateNew() throws Exception {
066: addJournalArticle();
067: }
068:
069: public void testUpdateExisting() throws Exception {
070: long pk = nextLong();
071:
072: JournalArticle newJournalArticle = _persistence.create(pk);
073:
074: newJournalArticle.setUuid(randomString());
075: newJournalArticle.setResourcePrimKey(nextLong());
076: newJournalArticle.setGroupId(nextLong());
077: newJournalArticle.setCompanyId(nextLong());
078: newJournalArticle.setUserId(nextLong());
079: newJournalArticle.setUserName(randomString());
080: newJournalArticle.setCreateDate(nextDate());
081: newJournalArticle.setModifiedDate(nextDate());
082: newJournalArticle.setArticleId(randomString());
083: newJournalArticle.setVersion(nextDouble());
084: newJournalArticle.setTitle(randomString());
085: newJournalArticle.setDescription(randomString());
086: newJournalArticle.setContent(randomString());
087: newJournalArticle.setType(randomString());
088: newJournalArticle.setStructureId(randomString());
089: newJournalArticle.setTemplateId(randomString());
090: newJournalArticle.setDisplayDate(nextDate());
091: newJournalArticle.setApproved(randomBoolean());
092: newJournalArticle.setApprovedByUserId(nextLong());
093: newJournalArticle.setApprovedByUserName(randomString());
094: newJournalArticle.setApprovedDate(nextDate());
095: newJournalArticle.setExpired(randomBoolean());
096: newJournalArticle.setExpirationDate(nextDate());
097: newJournalArticle.setReviewDate(nextDate());
098: newJournalArticle.setIndexable(randomBoolean());
099: newJournalArticle.setSmallImage(randomBoolean());
100: newJournalArticle.setSmallImageId(nextLong());
101: newJournalArticle.setSmallImageURL(randomString());
102:
103: _persistence.update(newJournalArticle);
104:
105: JournalArticle existingJournalArticle = _persistence
106: .findByPrimaryKey(newJournalArticle.getPrimaryKey());
107:
108: assertEquals(existingJournalArticle.getUuid(),
109: newJournalArticle.getUuid());
110: assertEquals(existingJournalArticle.getId(), newJournalArticle
111: .getId());
112: assertEquals(existingJournalArticle.getResourcePrimKey(),
113: newJournalArticle.getResourcePrimKey());
114: assertEquals(existingJournalArticle.getGroupId(),
115: newJournalArticle.getGroupId());
116: assertEquals(existingJournalArticle.getCompanyId(),
117: newJournalArticle.getCompanyId());
118: assertEquals(existingJournalArticle.getUserId(),
119: newJournalArticle.getUserId());
120: assertEquals(existingJournalArticle.getUserName(),
121: newJournalArticle.getUserName());
122: assertEquals(existingJournalArticle.getCreateDate(),
123: newJournalArticle.getCreateDate());
124: assertEquals(existingJournalArticle.getModifiedDate(),
125: newJournalArticle.getModifiedDate());
126: assertEquals(existingJournalArticle.getArticleId(),
127: newJournalArticle.getArticleId());
128: assertEquals(existingJournalArticle.getVersion(),
129: newJournalArticle.getVersion());
130: assertEquals(existingJournalArticle.getTitle(),
131: newJournalArticle.getTitle());
132: assertEquals(existingJournalArticle.getDescription(),
133: newJournalArticle.getDescription());
134: assertEquals(existingJournalArticle.getContent(),
135: newJournalArticle.getContent());
136: assertEquals(existingJournalArticle.getType(),
137: newJournalArticle.getType());
138: assertEquals(existingJournalArticle.getStructureId(),
139: newJournalArticle.getStructureId());
140: assertEquals(existingJournalArticle.getTemplateId(),
141: newJournalArticle.getTemplateId());
142: assertEquals(existingJournalArticle.getDisplayDate(),
143: newJournalArticle.getDisplayDate());
144: assertEquals(existingJournalArticle.getApproved(),
145: newJournalArticle.getApproved());
146: assertEquals(existingJournalArticle.getApprovedByUserId(),
147: newJournalArticle.getApprovedByUserId());
148: assertEquals(existingJournalArticle.getApprovedByUserName(),
149: newJournalArticle.getApprovedByUserName());
150: assertEquals(existingJournalArticle.getApprovedDate(),
151: newJournalArticle.getApprovedDate());
152: assertEquals(existingJournalArticle.getExpired(),
153: newJournalArticle.getExpired());
154: assertEquals(existingJournalArticle.getExpirationDate(),
155: newJournalArticle.getExpirationDate());
156: assertEquals(existingJournalArticle.getReviewDate(),
157: newJournalArticle.getReviewDate());
158: assertEquals(existingJournalArticle.getIndexable(),
159: newJournalArticle.getIndexable());
160: assertEquals(existingJournalArticle.getSmallImage(),
161: newJournalArticle.getSmallImage());
162: assertEquals(existingJournalArticle.getSmallImageId(),
163: newJournalArticle.getSmallImageId());
164: assertEquals(existingJournalArticle.getSmallImageURL(),
165: newJournalArticle.getSmallImageURL());
166: }
167:
168: public void testFindByPrimaryKeyExisting() throws Exception {
169: JournalArticle newJournalArticle = addJournalArticle();
170:
171: JournalArticle existingJournalArticle = _persistence
172: .findByPrimaryKey(newJournalArticle.getPrimaryKey());
173:
174: assertEquals(existingJournalArticle, newJournalArticle);
175: }
176:
177: public void testFindByPrimaryKeyMissing() throws Exception {
178: long pk = nextLong();
179:
180: try {
181: _persistence.findByPrimaryKey(pk);
182:
183: fail("Missing entity did not throw NoSuchArticleException");
184: } catch (NoSuchArticleException nsee) {
185: }
186: }
187:
188: public void testFetchByPrimaryKeyExisting() throws Exception {
189: JournalArticle newJournalArticle = addJournalArticle();
190:
191: JournalArticle existingJournalArticle = _persistence
192: .fetchByPrimaryKey(newJournalArticle.getPrimaryKey());
193:
194: assertEquals(existingJournalArticle, newJournalArticle);
195: }
196:
197: public void testFetchByPrimaryKeyMissing() throws Exception {
198: long pk = nextLong();
199:
200: JournalArticle missingJournalArticle = _persistence
201: .fetchByPrimaryKey(pk);
202:
203: assertNull(missingJournalArticle);
204: }
205:
206: protected JournalArticle addJournalArticle() throws Exception {
207: long pk = nextLong();
208:
209: JournalArticle journalArticle = _persistence.create(pk);
210:
211: journalArticle.setUuid(randomString());
212: journalArticle.setResourcePrimKey(nextLong());
213: journalArticle.setGroupId(nextLong());
214: journalArticle.setCompanyId(nextLong());
215: journalArticle.setUserId(nextLong());
216: journalArticle.setUserName(randomString());
217: journalArticle.setCreateDate(nextDate());
218: journalArticle.setModifiedDate(nextDate());
219: journalArticle.setArticleId(randomString());
220: journalArticle.setVersion(nextDouble());
221: journalArticle.setTitle(randomString());
222: journalArticle.setDescription(randomString());
223: journalArticle.setContent(randomString());
224: journalArticle.setType(randomString());
225: journalArticle.setStructureId(randomString());
226: journalArticle.setTemplateId(randomString());
227: journalArticle.setDisplayDate(nextDate());
228: journalArticle.setApproved(randomBoolean());
229: journalArticle.setApprovedByUserId(nextLong());
230: journalArticle.setApprovedByUserName(randomString());
231: journalArticle.setApprovedDate(nextDate());
232: journalArticle.setExpired(randomBoolean());
233: journalArticle.setExpirationDate(nextDate());
234: journalArticle.setReviewDate(nextDate());
235: journalArticle.setIndexable(randomBoolean());
236: journalArticle.setSmallImage(randomBoolean());
237: journalArticle.setSmallImageId(nextLong());
238: journalArticle.setSmallImageURL(randomString());
239:
240: _persistence.update(journalArticle);
241:
242: return journalArticle;
243: }
244:
245: private static final String _TX_IMPL = JournalArticlePersistence.class
246: .getName()
247: + ".transaction";
248: private JournalArticlePersistence _persistence;
249: }
|