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.portal.service.persistence;
022:
023: import com.liferay.portal.NoSuchImageException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.Image;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="ImagePersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class ImagePersistenceTest extends BasePersistenceTestCase {
035: protected void setUp() throws Exception {
036: super .setUp();
037:
038: _persistence = (ImagePersistence) BeanLocatorUtil
039: .locate(_TX_IMPL);
040: }
041:
042: public void testCreate() throws Exception {
043: long pk = nextLong();
044:
045: Image image = _persistence.create(pk);
046:
047: assertNotNull(image);
048:
049: assertEquals(image.getPrimaryKey(), pk);
050: }
051:
052: public void testRemove() throws Exception {
053: Image newImage = addImage();
054:
055: _persistence.remove(newImage);
056:
057: Image existingImage = _persistence.fetchByPrimaryKey(newImage
058: .getPrimaryKey());
059:
060: assertNull(existingImage);
061: }
062:
063: public void testUpdateNew() throws Exception {
064: addImage();
065: }
066:
067: public void testUpdateExisting() throws Exception {
068: long pk = nextLong();
069:
070: Image newImage = _persistence.create(pk);
071:
072: newImage.setModifiedDate(nextDate());
073: newImage.setText(randomString());
074: newImage.setType(randomString());
075: newImage.setHeight(nextInt());
076: newImage.setWidth(nextInt());
077: newImage.setSize(nextInt());
078:
079: _persistence.update(newImage);
080:
081: Image existingImage = _persistence.findByPrimaryKey(newImage
082: .getPrimaryKey());
083:
084: assertEquals(existingImage.getImageId(), newImage.getImageId());
085: assertEquals(existingImage.getModifiedDate(), newImage
086: .getModifiedDate());
087: assertEquals(existingImage.getText(), newImage.getText());
088: assertEquals(existingImage.getType(), newImage.getType());
089: assertEquals(existingImage.getHeight(), newImage.getHeight());
090: assertEquals(existingImage.getWidth(), newImage.getWidth());
091: assertEquals(existingImage.getSize(), newImage.getSize());
092: }
093:
094: public void testFindByPrimaryKeyExisting() throws Exception {
095: Image newImage = addImage();
096:
097: Image existingImage = _persistence.findByPrimaryKey(newImage
098: .getPrimaryKey());
099:
100: assertEquals(existingImage, newImage);
101: }
102:
103: public void testFindByPrimaryKeyMissing() throws Exception {
104: long pk = nextLong();
105:
106: try {
107: _persistence.findByPrimaryKey(pk);
108:
109: fail("Missing entity did not throw NoSuchImageException");
110: } catch (NoSuchImageException nsee) {
111: }
112: }
113:
114: public void testFetchByPrimaryKeyExisting() throws Exception {
115: Image newImage = addImage();
116:
117: Image existingImage = _persistence.fetchByPrimaryKey(newImage
118: .getPrimaryKey());
119:
120: assertEquals(existingImage, newImage);
121: }
122:
123: public void testFetchByPrimaryKeyMissing() throws Exception {
124: long pk = nextLong();
125:
126: Image missingImage = _persistence.fetchByPrimaryKey(pk);
127:
128: assertNull(missingImage);
129: }
130:
131: protected Image addImage() throws Exception {
132: long pk = nextLong();
133:
134: Image image = _persistence.create(pk);
135:
136: image.setModifiedDate(nextDate());
137: image.setText(randomString());
138: image.setType(randomString());
139: image.setHeight(nextInt());
140: image.setWidth(nextInt());
141: image.setSize(nextInt());
142:
143: _persistence.update(image);
144:
145: return image;
146: }
147:
148: private static final String _TX_IMPL = ImagePersistence.class
149: .getName()
150: + ".transaction";
151: private ImagePersistence _persistence;
152: }
|