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