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