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.NoSuchFileVersionException;
027: import com.liferay.portlet.documentlibrary.model.DLFileVersion;
028:
029: /**
030: * <a href="DLFileVersionPersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class DLFileVersionPersistenceTest extends
036: BasePersistenceTestCase {
037: protected void setUp() throws Exception {
038: super .setUp();
039:
040: _persistence = (DLFileVersionPersistence) BeanLocatorUtil
041: .locate(_TX_IMPL);
042: }
043:
044: public void testCreate() throws Exception {
045: long pk = nextLong();
046:
047: DLFileVersion dlFileVersion = _persistence.create(pk);
048:
049: assertNotNull(dlFileVersion);
050:
051: assertEquals(dlFileVersion.getPrimaryKey(), pk);
052: }
053:
054: public void testRemove() throws Exception {
055: DLFileVersion newDLFileVersion = addDLFileVersion();
056:
057: _persistence.remove(newDLFileVersion);
058:
059: DLFileVersion existingDLFileVersion = _persistence
060: .fetchByPrimaryKey(newDLFileVersion.getPrimaryKey());
061:
062: assertNull(existingDLFileVersion);
063: }
064:
065: public void testUpdateNew() throws Exception {
066: addDLFileVersion();
067: }
068:
069: public void testUpdateExisting() throws Exception {
070: long pk = nextLong();
071:
072: DLFileVersion newDLFileVersion = _persistence.create(pk);
073:
074: newDLFileVersion.setCompanyId(nextLong());
075: newDLFileVersion.setUserId(nextLong());
076: newDLFileVersion.setUserName(randomString());
077: newDLFileVersion.setCreateDate(nextDate());
078: newDLFileVersion.setFolderId(nextLong());
079: newDLFileVersion.setName(randomString());
080: newDLFileVersion.setVersion(nextDouble());
081: newDLFileVersion.setSize(nextInt());
082:
083: _persistence.update(newDLFileVersion);
084:
085: DLFileVersion existingDLFileVersion = _persistence
086: .findByPrimaryKey(newDLFileVersion.getPrimaryKey());
087:
088: assertEquals(existingDLFileVersion.getFileVersionId(),
089: newDLFileVersion.getFileVersionId());
090: assertEquals(existingDLFileVersion.getCompanyId(),
091: newDLFileVersion.getCompanyId());
092: assertEquals(existingDLFileVersion.getUserId(),
093: newDLFileVersion.getUserId());
094: assertEquals(existingDLFileVersion.getUserName(),
095: newDLFileVersion.getUserName());
096: assertEquals(existingDLFileVersion.getCreateDate(),
097: newDLFileVersion.getCreateDate());
098: assertEquals(existingDLFileVersion.getFolderId(),
099: newDLFileVersion.getFolderId());
100: assertEquals(existingDLFileVersion.getName(), newDLFileVersion
101: .getName());
102: assertEquals(existingDLFileVersion.getVersion(),
103: newDLFileVersion.getVersion());
104: assertEquals(existingDLFileVersion.getSize(), newDLFileVersion
105: .getSize());
106: }
107:
108: public void testFindByPrimaryKeyExisting() throws Exception {
109: DLFileVersion newDLFileVersion = addDLFileVersion();
110:
111: DLFileVersion existingDLFileVersion = _persistence
112: .findByPrimaryKey(newDLFileVersion.getPrimaryKey());
113:
114: assertEquals(existingDLFileVersion, newDLFileVersion);
115: }
116:
117: public void testFindByPrimaryKeyMissing() throws Exception {
118: long pk = nextLong();
119:
120: try {
121: _persistence.findByPrimaryKey(pk);
122:
123: fail("Missing entity did not throw NoSuchFileVersionException");
124: } catch (NoSuchFileVersionException nsee) {
125: }
126: }
127:
128: public void testFetchByPrimaryKeyExisting() throws Exception {
129: DLFileVersion newDLFileVersion = addDLFileVersion();
130:
131: DLFileVersion existingDLFileVersion = _persistence
132: .fetchByPrimaryKey(newDLFileVersion.getPrimaryKey());
133:
134: assertEquals(existingDLFileVersion, newDLFileVersion);
135: }
136:
137: public void testFetchByPrimaryKeyMissing() throws Exception {
138: long pk = nextLong();
139:
140: DLFileVersion missingDLFileVersion = _persistence
141: .fetchByPrimaryKey(pk);
142:
143: assertNull(missingDLFileVersion);
144: }
145:
146: protected DLFileVersion addDLFileVersion() throws Exception {
147: long pk = nextLong();
148:
149: DLFileVersion dlFileVersion = _persistence.create(pk);
150:
151: dlFileVersion.setCompanyId(nextLong());
152: dlFileVersion.setUserId(nextLong());
153: dlFileVersion.setUserName(randomString());
154: dlFileVersion.setCreateDate(nextDate());
155: dlFileVersion.setFolderId(nextLong());
156: dlFileVersion.setName(randomString());
157: dlFileVersion.setVersion(nextDouble());
158: dlFileVersion.setSize(nextInt());
159:
160: _persistence.update(dlFileVersion);
161:
162: return dlFileVersion;
163: }
164:
165: private static final String _TX_IMPL = DLFileVersionPersistence.class
166: .getName()
167: + ".transaction";
168: private DLFileVersionPersistence _persistence;
169: }
|