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