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.NoSuchTemplateException;
027: import com.liferay.portlet.journal.model.JournalTemplate;
028:
029: /**
030: * <a href="JournalTemplatePersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class JournalTemplatePersistenceTest extends
036: BasePersistenceTestCase {
037: protected void setUp() throws Exception {
038: super .setUp();
039:
040: _persistence = (JournalTemplatePersistence) BeanLocatorUtil
041: .locate(_TX_IMPL);
042: }
043:
044: public void testCreate() throws Exception {
045: long pk = nextLong();
046:
047: JournalTemplate journalTemplate = _persistence.create(pk);
048:
049: assertNotNull(journalTemplate);
050:
051: assertEquals(journalTemplate.getPrimaryKey(), pk);
052: }
053:
054: public void testRemove() throws Exception {
055: JournalTemplate newJournalTemplate = addJournalTemplate();
056:
057: _persistence.remove(newJournalTemplate);
058:
059: JournalTemplate existingJournalTemplate = _persistence
060: .fetchByPrimaryKey(newJournalTemplate.getPrimaryKey());
061:
062: assertNull(existingJournalTemplate);
063: }
064:
065: public void testUpdateNew() throws Exception {
066: addJournalTemplate();
067: }
068:
069: public void testUpdateExisting() throws Exception {
070: long pk = nextLong();
071:
072: JournalTemplate newJournalTemplate = _persistence.create(pk);
073:
074: newJournalTemplate.setUuid(randomString());
075: newJournalTemplate.setGroupId(nextLong());
076: newJournalTemplate.setCompanyId(nextLong());
077: newJournalTemplate.setUserId(nextLong());
078: newJournalTemplate.setUserName(randomString());
079: newJournalTemplate.setCreateDate(nextDate());
080: newJournalTemplate.setModifiedDate(nextDate());
081: newJournalTemplate.setTemplateId(randomString());
082: newJournalTemplate.setStructureId(randomString());
083: newJournalTemplate.setName(randomString());
084: newJournalTemplate.setDescription(randomString());
085: newJournalTemplate.setXsl(randomString());
086: newJournalTemplate.setLangType(randomString());
087: newJournalTemplate.setCacheable(randomBoolean());
088: newJournalTemplate.setSmallImage(randomBoolean());
089: newJournalTemplate.setSmallImageId(nextLong());
090: newJournalTemplate.setSmallImageURL(randomString());
091:
092: _persistence.update(newJournalTemplate);
093:
094: JournalTemplate existingJournalTemplate = _persistence
095: .findByPrimaryKey(newJournalTemplate.getPrimaryKey());
096:
097: assertEquals(existingJournalTemplate.getUuid(),
098: newJournalTemplate.getUuid());
099: assertEquals(existingJournalTemplate.getId(),
100: newJournalTemplate.getId());
101: assertEquals(existingJournalTemplate.getGroupId(),
102: newJournalTemplate.getGroupId());
103: assertEquals(existingJournalTemplate.getCompanyId(),
104: newJournalTemplate.getCompanyId());
105: assertEquals(existingJournalTemplate.getUserId(),
106: newJournalTemplate.getUserId());
107: assertEquals(existingJournalTemplate.getUserName(),
108: newJournalTemplate.getUserName());
109: assertEquals(existingJournalTemplate.getCreateDate(),
110: newJournalTemplate.getCreateDate());
111: assertEquals(existingJournalTemplate.getModifiedDate(),
112: newJournalTemplate.getModifiedDate());
113: assertEquals(existingJournalTemplate.getTemplateId(),
114: newJournalTemplate.getTemplateId());
115: assertEquals(existingJournalTemplate.getStructureId(),
116: newJournalTemplate.getStructureId());
117: assertEquals(existingJournalTemplate.getName(),
118: newJournalTemplate.getName());
119: assertEquals(existingJournalTemplate.getDescription(),
120: newJournalTemplate.getDescription());
121: assertEquals(existingJournalTemplate.getXsl(),
122: newJournalTemplate.getXsl());
123: assertEquals(existingJournalTemplate.getLangType(),
124: newJournalTemplate.getLangType());
125: assertEquals(existingJournalTemplate.getCacheable(),
126: newJournalTemplate.getCacheable());
127: assertEquals(existingJournalTemplate.getSmallImage(),
128: newJournalTemplate.getSmallImage());
129: assertEquals(existingJournalTemplate.getSmallImageId(),
130: newJournalTemplate.getSmallImageId());
131: assertEquals(existingJournalTemplate.getSmallImageURL(),
132: newJournalTemplate.getSmallImageURL());
133: }
134:
135: public void testFindByPrimaryKeyExisting() throws Exception {
136: JournalTemplate newJournalTemplate = addJournalTemplate();
137:
138: JournalTemplate existingJournalTemplate = _persistence
139: .findByPrimaryKey(newJournalTemplate.getPrimaryKey());
140:
141: assertEquals(existingJournalTemplate, newJournalTemplate);
142: }
143:
144: public void testFindByPrimaryKeyMissing() throws Exception {
145: long pk = nextLong();
146:
147: try {
148: _persistence.findByPrimaryKey(pk);
149:
150: fail("Missing entity did not throw NoSuchTemplateException");
151: } catch (NoSuchTemplateException nsee) {
152: }
153: }
154:
155: public void testFetchByPrimaryKeyExisting() throws Exception {
156: JournalTemplate newJournalTemplate = addJournalTemplate();
157:
158: JournalTemplate existingJournalTemplate = _persistence
159: .fetchByPrimaryKey(newJournalTemplate.getPrimaryKey());
160:
161: assertEquals(existingJournalTemplate, newJournalTemplate);
162: }
163:
164: public void testFetchByPrimaryKeyMissing() throws Exception {
165: long pk = nextLong();
166:
167: JournalTemplate missingJournalTemplate = _persistence
168: .fetchByPrimaryKey(pk);
169:
170: assertNull(missingJournalTemplate);
171: }
172:
173: protected JournalTemplate addJournalTemplate() throws Exception {
174: long pk = nextLong();
175:
176: JournalTemplate journalTemplate = _persistence.create(pk);
177:
178: journalTemplate.setUuid(randomString());
179: journalTemplate.setGroupId(nextLong());
180: journalTemplate.setCompanyId(nextLong());
181: journalTemplate.setUserId(nextLong());
182: journalTemplate.setUserName(randomString());
183: journalTemplate.setCreateDate(nextDate());
184: journalTemplate.setModifiedDate(nextDate());
185: journalTemplate.setTemplateId(randomString());
186: journalTemplate.setStructureId(randomString());
187: journalTemplate.setName(randomString());
188: journalTemplate.setDescription(randomString());
189: journalTemplate.setXsl(randomString());
190: journalTemplate.setLangType(randomString());
191: journalTemplate.setCacheable(randomBoolean());
192: journalTemplate.setSmallImage(randomBoolean());
193: journalTemplate.setSmallImageId(nextLong());
194: journalTemplate.setSmallImageURL(randomString());
195:
196: _persistence.update(journalTemplate);
197:
198: return journalTemplate;
199: }
200:
201: private static final String _TX_IMPL = JournalTemplatePersistence.class
202: .getName()
203: + ".transaction";
204: private JournalTemplatePersistence _persistence;
205: }
|