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