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