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