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