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