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