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