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