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