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.NoSuchContactException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.Contact;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="ContactPersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class ContactPersistenceTest extends BasePersistenceTestCase {
035: protected void setUp() throws Exception {
036: super .setUp();
037:
038: _persistence = (ContactPersistence) BeanLocatorUtil
039: .locate(_TX_IMPL);
040: }
041:
042: public void testCreate() throws Exception {
043: long pk = nextLong();
044:
045: Contact contact = _persistence.create(pk);
046:
047: assertNotNull(contact);
048:
049: assertEquals(contact.getPrimaryKey(), pk);
050: }
051:
052: public void testRemove() throws Exception {
053: Contact newContact = addContact();
054:
055: _persistence.remove(newContact);
056:
057: Contact existingContact = _persistence
058: .fetchByPrimaryKey(newContact.getPrimaryKey());
059:
060: assertNull(existingContact);
061: }
062:
063: public void testUpdateNew() throws Exception {
064: addContact();
065: }
066:
067: public void testUpdateExisting() throws Exception {
068: long pk = nextLong();
069:
070: Contact newContact = _persistence.create(pk);
071:
072: newContact.setCompanyId(nextLong());
073: newContact.setUserId(nextLong());
074: newContact.setUserName(randomString());
075: newContact.setCreateDate(nextDate());
076: newContact.setModifiedDate(nextDate());
077: newContact.setAccountId(nextLong());
078: newContact.setParentContactId(nextLong());
079: newContact.setFirstName(randomString());
080: newContact.setMiddleName(randomString());
081: newContact.setLastName(randomString());
082: newContact.setPrefixId(nextInt());
083: newContact.setSuffixId(nextInt());
084: newContact.setMale(randomBoolean());
085: newContact.setBirthday(nextDate());
086: newContact.setSmsSn(randomString());
087: newContact.setAimSn(randomString());
088: newContact.setIcqSn(randomString());
089: newContact.setJabberSn(randomString());
090: newContact.setMsnSn(randomString());
091: newContact.setSkypeSn(randomString());
092: newContact.setYmSn(randomString());
093: newContact.setEmployeeStatusId(randomString());
094: newContact.setEmployeeNumber(randomString());
095: newContact.setJobTitle(randomString());
096: newContact.setJobClass(randomString());
097: newContact.setHoursOfOperation(randomString());
098:
099: _persistence.update(newContact);
100:
101: Contact existingContact = _persistence
102: .findByPrimaryKey(newContact.getPrimaryKey());
103:
104: assertEquals(existingContact.getContactId(), newContact
105: .getContactId());
106: assertEquals(existingContact.getCompanyId(), newContact
107: .getCompanyId());
108: assertEquals(existingContact.getUserId(), newContact
109: .getUserId());
110: assertEquals(existingContact.getUserName(), newContact
111: .getUserName());
112: assertEquals(existingContact.getCreateDate(), newContact
113: .getCreateDate());
114: assertEquals(existingContact.getModifiedDate(), newContact
115: .getModifiedDate());
116: assertEquals(existingContact.getAccountId(), newContact
117: .getAccountId());
118: assertEquals(existingContact.getParentContactId(), newContact
119: .getParentContactId());
120: assertEquals(existingContact.getFirstName(), newContact
121: .getFirstName());
122: assertEquals(existingContact.getMiddleName(), newContact
123: .getMiddleName());
124: assertEquals(existingContact.getLastName(), newContact
125: .getLastName());
126: assertEquals(existingContact.getPrefixId(), newContact
127: .getPrefixId());
128: assertEquals(existingContact.getSuffixId(), newContact
129: .getSuffixId());
130: assertEquals(existingContact.getMale(), newContact.getMale());
131: assertEquals(existingContact.getBirthday(), newContact
132: .getBirthday());
133: assertEquals(existingContact.getSmsSn(), newContact.getSmsSn());
134: assertEquals(existingContact.getAimSn(), newContact.getAimSn());
135: assertEquals(existingContact.getIcqSn(), newContact.getIcqSn());
136: assertEquals(existingContact.getJabberSn(), newContact
137: .getJabberSn());
138: assertEquals(existingContact.getMsnSn(), newContact.getMsnSn());
139: assertEquals(existingContact.getSkypeSn(), newContact
140: .getSkypeSn());
141: assertEquals(existingContact.getYmSn(), newContact.getYmSn());
142: assertEquals(existingContact.getEmployeeStatusId(), newContact
143: .getEmployeeStatusId());
144: assertEquals(existingContact.getEmployeeNumber(), newContact
145: .getEmployeeNumber());
146: assertEquals(existingContact.getJobTitle(), newContact
147: .getJobTitle());
148: assertEquals(existingContact.getJobClass(), newContact
149: .getJobClass());
150: assertEquals(existingContact.getHoursOfOperation(), newContact
151: .getHoursOfOperation());
152: }
153:
154: public void testFindByPrimaryKeyExisting() throws Exception {
155: Contact newContact = addContact();
156:
157: Contact existingContact = _persistence
158: .findByPrimaryKey(newContact.getPrimaryKey());
159:
160: assertEquals(existingContact, newContact);
161: }
162:
163: public void testFindByPrimaryKeyMissing() throws Exception {
164: long pk = nextLong();
165:
166: try {
167: _persistence.findByPrimaryKey(pk);
168:
169: fail("Missing entity did not throw NoSuchContactException");
170: } catch (NoSuchContactException nsee) {
171: }
172: }
173:
174: public void testFetchByPrimaryKeyExisting() throws Exception {
175: Contact newContact = addContact();
176:
177: Contact existingContact = _persistence
178: .fetchByPrimaryKey(newContact.getPrimaryKey());
179:
180: assertEquals(existingContact, newContact);
181: }
182:
183: public void testFetchByPrimaryKeyMissing() throws Exception {
184: long pk = nextLong();
185:
186: Contact missingContact = _persistence.fetchByPrimaryKey(pk);
187:
188: assertNull(missingContact);
189: }
190:
191: protected Contact addContact() throws Exception {
192: long pk = nextLong();
193:
194: Contact contact = _persistence.create(pk);
195:
196: contact.setCompanyId(nextLong());
197: contact.setUserId(nextLong());
198: contact.setUserName(randomString());
199: contact.setCreateDate(nextDate());
200: contact.setModifiedDate(nextDate());
201: contact.setAccountId(nextLong());
202: contact.setParentContactId(nextLong());
203: contact.setFirstName(randomString());
204: contact.setMiddleName(randomString());
205: contact.setLastName(randomString());
206: contact.setPrefixId(nextInt());
207: contact.setSuffixId(nextInt());
208: contact.setMale(randomBoolean());
209: contact.setBirthday(nextDate());
210: contact.setSmsSn(randomString());
211: contact.setAimSn(randomString());
212: contact.setIcqSn(randomString());
213: contact.setJabberSn(randomString());
214: contact.setMsnSn(randomString());
215: contact.setSkypeSn(randomString());
216: contact.setYmSn(randomString());
217: contact.setEmployeeStatusId(randomString());
218: contact.setEmployeeNumber(randomString());
219: contact.setJobTitle(randomString());
220: contact.setJobClass(randomString());
221: contact.setHoursOfOperation(randomString());
222:
223: _persistence.update(contact);
224:
225: return contact;
226: }
227:
228: private static final String _TX_IMPL = ContactPersistence.class
229: .getName()
230: + ".transaction";
231: private ContactPersistence _persistence;
232: }
|