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