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.NoSuchFeedException;
027: import com.liferay.portlet.journal.model.JournalFeed;
028:
029: /**
030: * <a href="JournalFeedPersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class JournalFeedPersistenceTest extends BasePersistenceTestCase {
036: protected void setUp() throws Exception {
037: super .setUp();
038:
039: _persistence = (JournalFeedPersistence) BeanLocatorUtil
040: .locate(_TX_IMPL);
041: }
042:
043: public void testCreate() throws Exception {
044: long pk = nextLong();
045:
046: JournalFeed journalFeed = _persistence.create(pk);
047:
048: assertNotNull(journalFeed);
049:
050: assertEquals(journalFeed.getPrimaryKey(), pk);
051: }
052:
053: public void testRemove() throws Exception {
054: JournalFeed newJournalFeed = addJournalFeed();
055:
056: _persistence.remove(newJournalFeed);
057:
058: JournalFeed existingJournalFeed = _persistence
059: .fetchByPrimaryKey(newJournalFeed.getPrimaryKey());
060:
061: assertNull(existingJournalFeed);
062: }
063:
064: public void testUpdateNew() throws Exception {
065: addJournalFeed();
066: }
067:
068: public void testUpdateExisting() throws Exception {
069: long pk = nextLong();
070:
071: JournalFeed newJournalFeed = _persistence.create(pk);
072:
073: newJournalFeed.setUuid(randomString());
074: newJournalFeed.setGroupId(nextLong());
075: newJournalFeed.setCompanyId(nextLong());
076: newJournalFeed.setUserId(nextLong());
077: newJournalFeed.setUserName(randomString());
078: newJournalFeed.setCreateDate(nextDate());
079: newJournalFeed.setModifiedDate(nextDate());
080: newJournalFeed.setFeedId(randomString());
081: newJournalFeed.setName(randomString());
082: newJournalFeed.setDescription(randomString());
083: newJournalFeed.setType(randomString());
084: newJournalFeed.setStructureId(randomString());
085: newJournalFeed.setTemplateId(randomString());
086: newJournalFeed.setRendererTemplateId(randomString());
087: newJournalFeed.setDelta(nextInt());
088: newJournalFeed.setOrderByCol(randomString());
089: newJournalFeed.setOrderByType(randomString());
090: newJournalFeed.setTargetLayoutFriendlyUrl(randomString());
091: newJournalFeed.setTargetPortletId(randomString());
092: newJournalFeed.setContentField(randomString());
093: newJournalFeed.setFeedType(randomString());
094: newJournalFeed.setFeedVersion(nextDouble());
095:
096: _persistence.update(newJournalFeed);
097:
098: JournalFeed existingJournalFeed = _persistence
099: .findByPrimaryKey(newJournalFeed.getPrimaryKey());
100:
101: assertEquals(existingJournalFeed.getUuid(), newJournalFeed
102: .getUuid());
103: assertEquals(existingJournalFeed.getId(), newJournalFeed
104: .getId());
105: assertEquals(existingJournalFeed.getGroupId(), newJournalFeed
106: .getGroupId());
107: assertEquals(existingJournalFeed.getCompanyId(), newJournalFeed
108: .getCompanyId());
109: assertEquals(existingJournalFeed.getUserId(), newJournalFeed
110: .getUserId());
111: assertEquals(existingJournalFeed.getUserName(), newJournalFeed
112: .getUserName());
113: assertEquals(existingJournalFeed.getCreateDate(),
114: newJournalFeed.getCreateDate());
115: assertEquals(existingJournalFeed.getModifiedDate(),
116: newJournalFeed.getModifiedDate());
117: assertEquals(existingJournalFeed.getFeedId(), newJournalFeed
118: .getFeedId());
119: assertEquals(existingJournalFeed.getName(), newJournalFeed
120: .getName());
121: assertEquals(existingJournalFeed.getDescription(),
122: newJournalFeed.getDescription());
123: assertEquals(existingJournalFeed.getType(), newJournalFeed
124: .getType());
125: assertEquals(existingJournalFeed.getStructureId(),
126: newJournalFeed.getStructureId());
127: assertEquals(existingJournalFeed.getTemplateId(),
128: newJournalFeed.getTemplateId());
129: assertEquals(existingJournalFeed.getRendererTemplateId(),
130: newJournalFeed.getRendererTemplateId());
131: assertEquals(existingJournalFeed.getDelta(), newJournalFeed
132: .getDelta());
133: assertEquals(existingJournalFeed.getOrderByCol(),
134: newJournalFeed.getOrderByCol());
135: assertEquals(existingJournalFeed.getOrderByType(),
136: newJournalFeed.getOrderByType());
137: assertEquals(existingJournalFeed.getTargetLayoutFriendlyUrl(),
138: newJournalFeed.getTargetLayoutFriendlyUrl());
139: assertEquals(existingJournalFeed.getTargetPortletId(),
140: newJournalFeed.getTargetPortletId());
141: assertEquals(existingJournalFeed.getContentField(),
142: newJournalFeed.getContentField());
143: assertEquals(existingJournalFeed.getFeedType(), newJournalFeed
144: .getFeedType());
145: assertEquals(existingJournalFeed.getFeedVersion(),
146: newJournalFeed.getFeedVersion());
147: }
148:
149: public void testFindByPrimaryKeyExisting() throws Exception {
150: JournalFeed newJournalFeed = addJournalFeed();
151:
152: JournalFeed existingJournalFeed = _persistence
153: .findByPrimaryKey(newJournalFeed.getPrimaryKey());
154:
155: assertEquals(existingJournalFeed, newJournalFeed);
156: }
157:
158: public void testFindByPrimaryKeyMissing() throws Exception {
159: long pk = nextLong();
160:
161: try {
162: _persistence.findByPrimaryKey(pk);
163:
164: fail("Missing entity did not throw NoSuchFeedException");
165: } catch (NoSuchFeedException nsee) {
166: }
167: }
168:
169: public void testFetchByPrimaryKeyExisting() throws Exception {
170: JournalFeed newJournalFeed = addJournalFeed();
171:
172: JournalFeed existingJournalFeed = _persistence
173: .fetchByPrimaryKey(newJournalFeed.getPrimaryKey());
174:
175: assertEquals(existingJournalFeed, newJournalFeed);
176: }
177:
178: public void testFetchByPrimaryKeyMissing() throws Exception {
179: long pk = nextLong();
180:
181: JournalFeed missingJournalFeed = _persistence
182: .fetchByPrimaryKey(pk);
183:
184: assertNull(missingJournalFeed);
185: }
186:
187: protected JournalFeed addJournalFeed() throws Exception {
188: long pk = nextLong();
189:
190: JournalFeed journalFeed = _persistence.create(pk);
191:
192: journalFeed.setUuid(randomString());
193: journalFeed.setGroupId(nextLong());
194: journalFeed.setCompanyId(nextLong());
195: journalFeed.setUserId(nextLong());
196: journalFeed.setUserName(randomString());
197: journalFeed.setCreateDate(nextDate());
198: journalFeed.setModifiedDate(nextDate());
199: journalFeed.setFeedId(randomString());
200: journalFeed.setName(randomString());
201: journalFeed.setDescription(randomString());
202: journalFeed.setType(randomString());
203: journalFeed.setStructureId(randomString());
204: journalFeed.setTemplateId(randomString());
205: journalFeed.setRendererTemplateId(randomString());
206: journalFeed.setDelta(nextInt());
207: journalFeed.setOrderByCol(randomString());
208: journalFeed.setOrderByType(randomString());
209: journalFeed.setTargetLayoutFriendlyUrl(randomString());
210: journalFeed.setTargetPortletId(randomString());
211: journalFeed.setContentField(randomString());
212: journalFeed.setFeedType(randomString());
213: journalFeed.setFeedVersion(nextDouble());
214:
215: _persistence.update(journalFeed);
216:
217: return journalFeed;
218: }
219:
220: private static final String _TX_IMPL = JournalFeedPersistence.class
221: .getName()
222: + ".transaction";
223: private JournalFeedPersistence _persistence;
224: }
|