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