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.NoSuchLayoutException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.Layout;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="LayoutPersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class LayoutPersistenceTest extends BasePersistenceTestCase {
035: protected void setUp() throws Exception {
036: super .setUp();
037:
038: _persistence = (LayoutPersistence) BeanLocatorUtil
039: .locate(_TX_IMPL);
040: }
041:
042: public void testCreate() throws Exception {
043: long pk = nextLong();
044:
045: Layout layout = _persistence.create(pk);
046:
047: assertNotNull(layout);
048:
049: assertEquals(layout.getPrimaryKey(), pk);
050: }
051:
052: public void testRemove() throws Exception {
053: Layout newLayout = addLayout();
054:
055: _persistence.remove(newLayout);
056:
057: Layout existingLayout = _persistence
058: .fetchByPrimaryKey(newLayout.getPrimaryKey());
059:
060: assertNull(existingLayout);
061: }
062:
063: public void testUpdateNew() throws Exception {
064: addLayout();
065: }
066:
067: public void testUpdateExisting() throws Exception {
068: long pk = nextLong();
069:
070: Layout newLayout = _persistence.create(pk);
071:
072: newLayout.setGroupId(nextLong());
073: newLayout.setCompanyId(nextLong());
074: newLayout.setPrivateLayout(randomBoolean());
075: newLayout.setLayoutId(nextLong());
076: newLayout.setParentLayoutId(nextLong());
077: newLayout.setName(randomString());
078: newLayout.setTitle(randomString());
079: newLayout.setDescription(randomString());
080: newLayout.setType(randomString());
081: newLayout.setTypeSettings(randomString());
082: newLayout.setHidden(randomBoolean());
083: newLayout.setFriendlyURL(randomString());
084: newLayout.setIconImage(randomBoolean());
085: newLayout.setIconImageId(nextLong());
086: newLayout.setThemeId(randomString());
087: newLayout.setColorSchemeId(randomString());
088: newLayout.setWapThemeId(randomString());
089: newLayout.setWapColorSchemeId(randomString());
090: newLayout.setCss(randomString());
091: newLayout.setPriority(nextInt());
092: newLayout.setDlFolderId(nextLong());
093:
094: _persistence.update(newLayout);
095:
096: Layout existingLayout = _persistence.findByPrimaryKey(newLayout
097: .getPrimaryKey());
098:
099: assertEquals(existingLayout.getPlid(), newLayout.getPlid());
100: assertEquals(existingLayout.getGroupId(), newLayout
101: .getGroupId());
102: assertEquals(existingLayout.getCompanyId(), newLayout
103: .getCompanyId());
104: assertEquals(existingLayout.getPrivateLayout(), newLayout
105: .getPrivateLayout());
106: assertEquals(existingLayout.getLayoutId(), newLayout
107: .getLayoutId());
108: assertEquals(existingLayout.getParentLayoutId(), newLayout
109: .getParentLayoutId());
110: assertEquals(existingLayout.getName(), newLayout.getName());
111: assertEquals(existingLayout.getTitle(), newLayout.getTitle());
112: assertEquals(existingLayout.getDescription(), newLayout
113: .getDescription());
114: assertEquals(existingLayout.getType(), newLayout.getType());
115: assertEquals(existingLayout.getTypeSettings(), newLayout
116: .getTypeSettings());
117: assertEquals(existingLayout.getHidden(), newLayout.getHidden());
118: assertEquals(existingLayout.getFriendlyURL(), newLayout
119: .getFriendlyURL());
120: assertEquals(existingLayout.getIconImage(), newLayout
121: .getIconImage());
122: assertEquals(existingLayout.getIconImageId(), newLayout
123: .getIconImageId());
124: assertEquals(existingLayout.getThemeId(), newLayout
125: .getThemeId());
126: assertEquals(existingLayout.getColorSchemeId(), newLayout
127: .getColorSchemeId());
128: assertEquals(existingLayout.getWapThemeId(), newLayout
129: .getWapThemeId());
130: assertEquals(existingLayout.getWapColorSchemeId(), newLayout
131: .getWapColorSchemeId());
132: assertEquals(existingLayout.getCss(), newLayout.getCss());
133: assertEquals(existingLayout.getPriority(), newLayout
134: .getPriority());
135: assertEquals(existingLayout.getDlFolderId(), newLayout
136: .getDlFolderId());
137: }
138:
139: public void testFindByPrimaryKeyExisting() throws Exception {
140: Layout newLayout = addLayout();
141:
142: Layout existingLayout = _persistence.findByPrimaryKey(newLayout
143: .getPrimaryKey());
144:
145: assertEquals(existingLayout, newLayout);
146: }
147:
148: public void testFindByPrimaryKeyMissing() throws Exception {
149: long pk = nextLong();
150:
151: try {
152: _persistence.findByPrimaryKey(pk);
153:
154: fail("Missing entity did not throw NoSuchLayoutException");
155: } catch (NoSuchLayoutException nsee) {
156: }
157: }
158:
159: public void testFetchByPrimaryKeyExisting() throws Exception {
160: Layout newLayout = addLayout();
161:
162: Layout existingLayout = _persistence
163: .fetchByPrimaryKey(newLayout.getPrimaryKey());
164:
165: assertEquals(existingLayout, newLayout);
166: }
167:
168: public void testFetchByPrimaryKeyMissing() throws Exception {
169: long pk = nextLong();
170:
171: Layout missingLayout = _persistence.fetchByPrimaryKey(pk);
172:
173: assertNull(missingLayout);
174: }
175:
176: protected Layout addLayout() throws Exception {
177: long pk = nextLong();
178:
179: Layout layout = _persistence.create(pk);
180:
181: layout.setGroupId(nextLong());
182: layout.setCompanyId(nextLong());
183: layout.setPrivateLayout(randomBoolean());
184: layout.setLayoutId(nextLong());
185: layout.setParentLayoutId(nextLong());
186: layout.setName(randomString());
187: layout.setTitle(randomString());
188: layout.setDescription(randomString());
189: layout.setType(randomString());
190: layout.setTypeSettings(randomString());
191: layout.setHidden(randomBoolean());
192: layout.setFriendlyURL(randomString());
193: layout.setIconImage(randomBoolean());
194: layout.setIconImageId(nextLong());
195: layout.setThemeId(randomString());
196: layout.setColorSchemeId(randomString());
197: layout.setWapThemeId(randomString());
198: layout.setWapColorSchemeId(randomString());
199: layout.setCss(randomString());
200: layout.setPriority(nextInt());
201: layout.setDlFolderId(nextLong());
202:
203: _persistence.update(layout);
204:
205: return layout;
206: }
207:
208: private static final String _TX_IMPL = LayoutPersistence.class
209: .getName()
210: + ".transaction";
211: private LayoutPersistence _persistence;
212: }
|