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