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.NoSuchVoteException;
027: import com.liferay.portlet.polls.model.PollsVote;
028:
029: /**
030: * <a href="PollsVotePersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class PollsVotePersistenceTest extends BasePersistenceTestCase {
036: protected void setUp() throws Exception {
037: super .setUp();
038:
039: _persistence = (PollsVotePersistence) BeanLocatorUtil
040: .locate(_TX_IMPL);
041: }
042:
043: public void testCreate() throws Exception {
044: long pk = nextLong();
045:
046: PollsVote pollsVote = _persistence.create(pk);
047:
048: assertNotNull(pollsVote);
049:
050: assertEquals(pollsVote.getPrimaryKey(), pk);
051: }
052:
053: public void testRemove() throws Exception {
054: PollsVote newPollsVote = addPollsVote();
055:
056: _persistence.remove(newPollsVote);
057:
058: PollsVote existingPollsVote = _persistence
059: .fetchByPrimaryKey(newPollsVote.getPrimaryKey());
060:
061: assertNull(existingPollsVote);
062: }
063:
064: public void testUpdateNew() throws Exception {
065: addPollsVote();
066: }
067:
068: public void testUpdateExisting() throws Exception {
069: long pk = nextLong();
070:
071: PollsVote newPollsVote = _persistence.create(pk);
072:
073: newPollsVote.setUserId(nextLong());
074: newPollsVote.setQuestionId(nextLong());
075: newPollsVote.setChoiceId(nextLong());
076: newPollsVote.setVoteDate(nextDate());
077:
078: _persistence.update(newPollsVote);
079:
080: PollsVote existingPollsVote = _persistence
081: .findByPrimaryKey(newPollsVote.getPrimaryKey());
082:
083: assertEquals(existingPollsVote.getVoteId(), newPollsVote
084: .getVoteId());
085: assertEquals(existingPollsVote.getUserId(), newPollsVote
086: .getUserId());
087: assertEquals(existingPollsVote.getQuestionId(), newPollsVote
088: .getQuestionId());
089: assertEquals(existingPollsVote.getChoiceId(), newPollsVote
090: .getChoiceId());
091: assertEquals(existingPollsVote.getVoteDate(), newPollsVote
092: .getVoteDate());
093: }
094:
095: public void testFindByPrimaryKeyExisting() throws Exception {
096: PollsVote newPollsVote = addPollsVote();
097:
098: PollsVote existingPollsVote = _persistence
099: .findByPrimaryKey(newPollsVote.getPrimaryKey());
100:
101: assertEquals(existingPollsVote, newPollsVote);
102: }
103:
104: public void testFindByPrimaryKeyMissing() throws Exception {
105: long pk = nextLong();
106:
107: try {
108: _persistence.findByPrimaryKey(pk);
109:
110: fail("Missing entity did not throw NoSuchVoteException");
111: } catch (NoSuchVoteException nsee) {
112: }
113: }
114:
115: public void testFetchByPrimaryKeyExisting() throws Exception {
116: PollsVote newPollsVote = addPollsVote();
117:
118: PollsVote existingPollsVote = _persistence
119: .fetchByPrimaryKey(newPollsVote.getPrimaryKey());
120:
121: assertEquals(existingPollsVote, newPollsVote);
122: }
123:
124: public void testFetchByPrimaryKeyMissing() throws Exception {
125: long pk = nextLong();
126:
127: PollsVote missingPollsVote = _persistence.fetchByPrimaryKey(pk);
128:
129: assertNull(missingPollsVote);
130: }
131:
132: protected PollsVote addPollsVote() throws Exception {
133: long pk = nextLong();
134:
135: PollsVote pollsVote = _persistence.create(pk);
136:
137: pollsVote.setUserId(nextLong());
138: pollsVote.setQuestionId(nextLong());
139: pollsVote.setChoiceId(nextLong());
140: pollsVote.setVoteDate(nextDate());
141:
142: _persistence.update(pollsVote);
143:
144: return pollsVote;
145: }
146:
147: private static final String _TX_IMPL = PollsVotePersistence.class
148: .getName()
149: + ".transaction";
150: private PollsVotePersistence _persistence;
151: }
|