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