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