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.NoSuchAddressException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.Address;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="AddressPersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class AddressPersistenceTest extends BasePersistenceTestCase {
035: protected void setUp() throws Exception {
036: super .setUp();
037:
038: _persistence = (AddressPersistence) BeanLocatorUtil
039: .locate(_TX_IMPL);
040: }
041:
042: public void testCreate() throws Exception {
043: long pk = nextLong();
044:
045: Address address = _persistence.create(pk);
046:
047: assertNotNull(address);
048:
049: assertEquals(address.getPrimaryKey(), pk);
050: }
051:
052: public void testRemove() throws Exception {
053: Address newAddress = addAddress();
054:
055: _persistence.remove(newAddress);
056:
057: Address existingAddress = _persistence
058: .fetchByPrimaryKey(newAddress.getPrimaryKey());
059:
060: assertNull(existingAddress);
061: }
062:
063: public void testUpdateNew() throws Exception {
064: addAddress();
065: }
066:
067: public void testUpdateExisting() throws Exception {
068: long pk = nextLong();
069:
070: Address newAddress = _persistence.create(pk);
071:
072: newAddress.setCompanyId(nextLong());
073: newAddress.setUserId(nextLong());
074: newAddress.setUserName(randomString());
075: newAddress.setCreateDate(nextDate());
076: newAddress.setModifiedDate(nextDate());
077: newAddress.setClassNameId(nextLong());
078: newAddress.setClassPK(nextLong());
079: newAddress.setStreet1(randomString());
080: newAddress.setStreet2(randomString());
081: newAddress.setStreet3(randomString());
082: newAddress.setCity(randomString());
083: newAddress.setZip(randomString());
084: newAddress.setRegionId(nextLong());
085: newAddress.setCountryId(nextLong());
086: newAddress.setTypeId(nextInt());
087: newAddress.setMailing(randomBoolean());
088: newAddress.setPrimary(randomBoolean());
089:
090: _persistence.update(newAddress);
091:
092: Address existingAddress = _persistence
093: .findByPrimaryKey(newAddress.getPrimaryKey());
094:
095: assertEquals(existingAddress.getAddressId(), newAddress
096: .getAddressId());
097: assertEquals(existingAddress.getCompanyId(), newAddress
098: .getCompanyId());
099: assertEquals(existingAddress.getUserId(), newAddress
100: .getUserId());
101: assertEquals(existingAddress.getUserName(), newAddress
102: .getUserName());
103: assertEquals(existingAddress.getCreateDate(), newAddress
104: .getCreateDate());
105: assertEquals(existingAddress.getModifiedDate(), newAddress
106: .getModifiedDate());
107: assertEquals(existingAddress.getClassNameId(), newAddress
108: .getClassNameId());
109: assertEquals(existingAddress.getClassPK(), newAddress
110: .getClassPK());
111: assertEquals(existingAddress.getStreet1(), newAddress
112: .getStreet1());
113: assertEquals(existingAddress.getStreet2(), newAddress
114: .getStreet2());
115: assertEquals(existingAddress.getStreet3(), newAddress
116: .getStreet3());
117: assertEquals(existingAddress.getCity(), newAddress.getCity());
118: assertEquals(existingAddress.getZip(), newAddress.getZip());
119: assertEquals(existingAddress.getRegionId(), newAddress
120: .getRegionId());
121: assertEquals(existingAddress.getCountryId(), newAddress
122: .getCountryId());
123: assertEquals(existingAddress.getTypeId(), newAddress
124: .getTypeId());
125: assertEquals(existingAddress.getMailing(), newAddress
126: .getMailing());
127: assertEquals(existingAddress.getPrimary(), newAddress
128: .getPrimary());
129: }
130:
131: public void testFindByPrimaryKeyExisting() throws Exception {
132: Address newAddress = addAddress();
133:
134: Address existingAddress = _persistence
135: .findByPrimaryKey(newAddress.getPrimaryKey());
136:
137: assertEquals(existingAddress, newAddress);
138: }
139:
140: public void testFindByPrimaryKeyMissing() throws Exception {
141: long pk = nextLong();
142:
143: try {
144: _persistence.findByPrimaryKey(pk);
145:
146: fail("Missing entity did not throw NoSuchAddressException");
147: } catch (NoSuchAddressException nsee) {
148: }
149: }
150:
151: public void testFetchByPrimaryKeyExisting() throws Exception {
152: Address newAddress = addAddress();
153:
154: Address existingAddress = _persistence
155: .fetchByPrimaryKey(newAddress.getPrimaryKey());
156:
157: assertEquals(existingAddress, newAddress);
158: }
159:
160: public void testFetchByPrimaryKeyMissing() throws Exception {
161: long pk = nextLong();
162:
163: Address missingAddress = _persistence.fetchByPrimaryKey(pk);
164:
165: assertNull(missingAddress);
166: }
167:
168: protected Address addAddress() throws Exception {
169: long pk = nextLong();
170:
171: Address address = _persistence.create(pk);
172:
173: address.setCompanyId(nextLong());
174: address.setUserId(nextLong());
175: address.setUserName(randomString());
176: address.setCreateDate(nextDate());
177: address.setModifiedDate(nextDate());
178: address.setClassNameId(nextLong());
179: address.setClassPK(nextLong());
180: address.setStreet1(randomString());
181: address.setStreet2(randomString());
182: address.setStreet3(randomString());
183: address.setCity(randomString());
184: address.setZip(randomString());
185: address.setRegionId(nextLong());
186: address.setCountryId(nextLong());
187: address.setTypeId(nextInt());
188: address.setMailing(randomBoolean());
189: address.setPrimary(randomBoolean());
190:
191: _persistence.update(address);
192:
193: return address;
194: }
195:
196: private static final String _TX_IMPL = AddressPersistence.class
197: .getName()
198: + ".transaction";
199: private AddressPersistence _persistence;
200: }
|