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.NoSuchPortletPreferencesException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.PortletPreferences;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="PortletPreferencesPersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class PortletPreferencesPersistenceTest extends
035: BasePersistenceTestCase {
036: protected void setUp() throws Exception {
037: super .setUp();
038:
039: _persistence = (PortletPreferencesPersistence) BeanLocatorUtil
040: .locate(_TX_IMPL);
041: }
042:
043: public void testCreate() throws Exception {
044: long pk = nextLong();
045:
046: PortletPreferences portletPreferences = _persistence.create(pk);
047:
048: assertNotNull(portletPreferences);
049:
050: assertEquals(portletPreferences.getPrimaryKey(), pk);
051: }
052:
053: public void testRemove() throws Exception {
054: PortletPreferences newPortletPreferences = addPortletPreferences();
055:
056: _persistence.remove(newPortletPreferences);
057:
058: PortletPreferences existingPortletPreferences = _persistence
059: .fetchByPrimaryKey(newPortletPreferences
060: .getPrimaryKey());
061:
062: assertNull(existingPortletPreferences);
063: }
064:
065: public void testUpdateNew() throws Exception {
066: addPortletPreferences();
067: }
068:
069: public void testUpdateExisting() throws Exception {
070: long pk = nextLong();
071:
072: PortletPreferences newPortletPreferences = _persistence
073: .create(pk);
074:
075: newPortletPreferences.setOwnerId(nextLong());
076: newPortletPreferences.setOwnerType(nextInt());
077: newPortletPreferences.setPlid(nextLong());
078: newPortletPreferences.setPortletId(randomString());
079: newPortletPreferences.setPreferences(randomString());
080:
081: _persistence.update(newPortletPreferences);
082:
083: PortletPreferences existingPortletPreferences = _persistence
084: .findByPrimaryKey(newPortletPreferences.getPrimaryKey());
085:
086: assertEquals(existingPortletPreferences
087: .getPortletPreferencesId(), newPortletPreferences
088: .getPortletPreferencesId());
089: assertEquals(existingPortletPreferences.getOwnerId(),
090: newPortletPreferences.getOwnerId());
091: assertEquals(existingPortletPreferences.getOwnerType(),
092: newPortletPreferences.getOwnerType());
093: assertEquals(existingPortletPreferences.getPlid(),
094: newPortletPreferences.getPlid());
095: assertEquals(existingPortletPreferences.getPortletId(),
096: newPortletPreferences.getPortletId());
097: assertEquals(existingPortletPreferences.getPreferences(),
098: newPortletPreferences.getPreferences());
099: }
100:
101: public void testFindByPrimaryKeyExisting() throws Exception {
102: PortletPreferences newPortletPreferences = addPortletPreferences();
103:
104: PortletPreferences existingPortletPreferences = _persistence
105: .findByPrimaryKey(newPortletPreferences.getPrimaryKey());
106:
107: assertEquals(existingPortletPreferences, newPortletPreferences);
108: }
109:
110: public void testFindByPrimaryKeyMissing() throws Exception {
111: long pk = nextLong();
112:
113: try {
114: _persistence.findByPrimaryKey(pk);
115:
116: fail("Missing entity did not throw NoSuchPortletPreferencesException");
117: } catch (NoSuchPortletPreferencesException nsee) {
118: }
119: }
120:
121: public void testFetchByPrimaryKeyExisting() throws Exception {
122: PortletPreferences newPortletPreferences = addPortletPreferences();
123:
124: PortletPreferences existingPortletPreferences = _persistence
125: .fetchByPrimaryKey(newPortletPreferences
126: .getPrimaryKey());
127:
128: assertEquals(existingPortletPreferences, newPortletPreferences);
129: }
130:
131: public void testFetchByPrimaryKeyMissing() throws Exception {
132: long pk = nextLong();
133:
134: PortletPreferences missingPortletPreferences = _persistence
135: .fetchByPrimaryKey(pk);
136:
137: assertNull(missingPortletPreferences);
138: }
139:
140: protected PortletPreferences addPortletPreferences()
141: throws Exception {
142: long pk = nextLong();
143:
144: PortletPreferences portletPreferences = _persistence.create(pk);
145:
146: portletPreferences.setOwnerId(nextLong());
147: portletPreferences.setOwnerType(nextInt());
148: portletPreferences.setPlid(nextLong());
149: portletPreferences.setPortletId(randomString());
150: portletPreferences.setPreferences(randomString());
151:
152: _persistence.update(portletPreferences);
153:
154: return portletPreferences;
155: }
156:
157: private static final String _TX_IMPL = PortletPreferencesPersistence.class
158: .getName()
159: + ".transaction";
160: private PortletPreferencesPersistence _persistence;
161: }
|