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