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