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.journal.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.journal.NoSuchArticleImageException;
027: import com.liferay.portlet.journal.model.JournalArticleImage;
028:
029: /**
030: * <a href="JournalArticleImagePersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class JournalArticleImagePersistenceTest extends
036: BasePersistenceTestCase {
037: protected void setUp() throws Exception {
038: super .setUp();
039:
040: _persistence = (JournalArticleImagePersistence) BeanLocatorUtil
041: .locate(_TX_IMPL);
042: }
043:
044: public void testCreate() throws Exception {
045: long pk = nextLong();
046:
047: JournalArticleImage journalArticleImage = _persistence
048: .create(pk);
049:
050: assertNotNull(journalArticleImage);
051:
052: assertEquals(journalArticleImage.getPrimaryKey(), pk);
053: }
054:
055: public void testRemove() throws Exception {
056: JournalArticleImage newJournalArticleImage = addJournalArticleImage();
057:
058: _persistence.remove(newJournalArticleImage);
059:
060: JournalArticleImage existingJournalArticleImage = _persistence
061: .fetchByPrimaryKey(newJournalArticleImage
062: .getPrimaryKey());
063:
064: assertNull(existingJournalArticleImage);
065: }
066:
067: public void testUpdateNew() throws Exception {
068: addJournalArticleImage();
069: }
070:
071: public void testUpdateExisting() throws Exception {
072: long pk = nextLong();
073:
074: JournalArticleImage newJournalArticleImage = _persistence
075: .create(pk);
076:
077: newJournalArticleImage.setGroupId(nextLong());
078: newJournalArticleImage.setArticleId(randomString());
079: newJournalArticleImage.setVersion(nextDouble());
080: newJournalArticleImage.setElName(randomString());
081: newJournalArticleImage.setLanguageId(randomString());
082: newJournalArticleImage.setTempImage(randomBoolean());
083:
084: _persistence.update(newJournalArticleImage);
085:
086: JournalArticleImage existingJournalArticleImage = _persistence
087: .findByPrimaryKey(newJournalArticleImage
088: .getPrimaryKey());
089:
090: assertEquals(existingJournalArticleImage.getArticleImageId(),
091: newJournalArticleImage.getArticleImageId());
092: assertEquals(existingJournalArticleImage.getGroupId(),
093: newJournalArticleImage.getGroupId());
094: assertEquals(existingJournalArticleImage.getArticleId(),
095: newJournalArticleImage.getArticleId());
096: assertEquals(existingJournalArticleImage.getVersion(),
097: newJournalArticleImage.getVersion());
098: assertEquals(existingJournalArticleImage.getElName(),
099: newJournalArticleImage.getElName());
100: assertEquals(existingJournalArticleImage.getLanguageId(),
101: newJournalArticleImage.getLanguageId());
102: assertEquals(existingJournalArticleImage.getTempImage(),
103: newJournalArticleImage.getTempImage());
104: }
105:
106: public void testFindByPrimaryKeyExisting() throws Exception {
107: JournalArticleImage newJournalArticleImage = addJournalArticleImage();
108:
109: JournalArticleImage existingJournalArticleImage = _persistence
110: .findByPrimaryKey(newJournalArticleImage
111: .getPrimaryKey());
112:
113: assertEquals(existingJournalArticleImage,
114: newJournalArticleImage);
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 NoSuchArticleImageException");
124: } catch (NoSuchArticleImageException nsee) {
125: }
126: }
127:
128: public void testFetchByPrimaryKeyExisting() throws Exception {
129: JournalArticleImage newJournalArticleImage = addJournalArticleImage();
130:
131: JournalArticleImage existingJournalArticleImage = _persistence
132: .fetchByPrimaryKey(newJournalArticleImage
133: .getPrimaryKey());
134:
135: assertEquals(existingJournalArticleImage,
136: newJournalArticleImage);
137: }
138:
139: public void testFetchByPrimaryKeyMissing() throws Exception {
140: long pk = nextLong();
141:
142: JournalArticleImage missingJournalArticleImage = _persistence
143: .fetchByPrimaryKey(pk);
144:
145: assertNull(missingJournalArticleImage);
146: }
147:
148: protected JournalArticleImage addJournalArticleImage()
149: throws Exception {
150: long pk = nextLong();
151:
152: JournalArticleImage journalArticleImage = _persistence
153: .create(pk);
154:
155: journalArticleImage.setGroupId(nextLong());
156: journalArticleImage.setArticleId(randomString());
157: journalArticleImage.setVersion(nextDouble());
158: journalArticleImage.setElName(randomString());
159: journalArticleImage.setLanguageId(randomString());
160: journalArticleImage.setTempImage(randomBoolean());
161:
162: _persistence.update(journalArticleImage);
163:
164: return journalArticleImage;
165: }
166:
167: private static final String _TX_IMPL = JournalArticleImagePersistence.class
168: .getName()
169: + ".transaction";
170: private JournalArticleImagePersistence _persistence;
171: }
|