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.NoSuchLayoutSetException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.LayoutSet;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="LayoutSetPersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class LayoutSetPersistenceTest extends BasePersistenceTestCase {
035: protected void setUp() throws Exception {
036: super .setUp();
037:
038: _persistence = (LayoutSetPersistence) BeanLocatorUtil
039: .locate(_TX_IMPL);
040: }
041:
042: public void testCreate() throws Exception {
043: long pk = nextLong();
044:
045: LayoutSet layoutSet = _persistence.create(pk);
046:
047: assertNotNull(layoutSet);
048:
049: assertEquals(layoutSet.getPrimaryKey(), pk);
050: }
051:
052: public void testRemove() throws Exception {
053: LayoutSet newLayoutSet = addLayoutSet();
054:
055: _persistence.remove(newLayoutSet);
056:
057: LayoutSet existingLayoutSet = _persistence
058: .fetchByPrimaryKey(newLayoutSet.getPrimaryKey());
059:
060: assertNull(existingLayoutSet);
061: }
062:
063: public void testUpdateNew() throws Exception {
064: addLayoutSet();
065: }
066:
067: public void testUpdateExisting() throws Exception {
068: long pk = nextLong();
069:
070: LayoutSet newLayoutSet = _persistence.create(pk);
071:
072: newLayoutSet.setGroupId(nextLong());
073: newLayoutSet.setCompanyId(nextLong());
074: newLayoutSet.setPrivateLayout(randomBoolean());
075: newLayoutSet.setLogo(randomBoolean());
076: newLayoutSet.setLogoId(nextLong());
077: newLayoutSet.setThemeId(randomString());
078: newLayoutSet.setColorSchemeId(randomString());
079: newLayoutSet.setWapThemeId(randomString());
080: newLayoutSet.setWapColorSchemeId(randomString());
081: newLayoutSet.setCss(randomString());
082: newLayoutSet.setPageCount(nextInt());
083: newLayoutSet.setVirtualHost(randomString());
084:
085: _persistence.update(newLayoutSet);
086:
087: LayoutSet existingLayoutSet = _persistence
088: .findByPrimaryKey(newLayoutSet.getPrimaryKey());
089:
090: assertEquals(existingLayoutSet.getLayoutSetId(), newLayoutSet
091: .getLayoutSetId());
092: assertEquals(existingLayoutSet.getGroupId(), newLayoutSet
093: .getGroupId());
094: assertEquals(existingLayoutSet.getCompanyId(), newLayoutSet
095: .getCompanyId());
096: assertEquals(existingLayoutSet.getPrivateLayout(), newLayoutSet
097: .getPrivateLayout());
098: assertEquals(existingLayoutSet.getLogo(), newLayoutSet
099: .getLogo());
100: assertEquals(existingLayoutSet.getLogoId(), newLayoutSet
101: .getLogoId());
102: assertEquals(existingLayoutSet.getThemeId(), newLayoutSet
103: .getThemeId());
104: assertEquals(existingLayoutSet.getColorSchemeId(), newLayoutSet
105: .getColorSchemeId());
106: assertEquals(existingLayoutSet.getWapThemeId(), newLayoutSet
107: .getWapThemeId());
108: assertEquals(existingLayoutSet.getWapColorSchemeId(),
109: newLayoutSet.getWapColorSchemeId());
110: assertEquals(existingLayoutSet.getCss(), newLayoutSet.getCss());
111: assertEquals(existingLayoutSet.getPageCount(), newLayoutSet
112: .getPageCount());
113: assertEquals(existingLayoutSet.getVirtualHost(), newLayoutSet
114: .getVirtualHost());
115: }
116:
117: public void testFindByPrimaryKeyExisting() throws Exception {
118: LayoutSet newLayoutSet = addLayoutSet();
119:
120: LayoutSet existingLayoutSet = _persistence
121: .findByPrimaryKey(newLayoutSet.getPrimaryKey());
122:
123: assertEquals(existingLayoutSet, newLayoutSet);
124: }
125:
126: public void testFindByPrimaryKeyMissing() throws Exception {
127: long pk = nextLong();
128:
129: try {
130: _persistence.findByPrimaryKey(pk);
131:
132: fail("Missing entity did not throw NoSuchLayoutSetException");
133: } catch (NoSuchLayoutSetException nsee) {
134: }
135: }
136:
137: public void testFetchByPrimaryKeyExisting() throws Exception {
138: LayoutSet newLayoutSet = addLayoutSet();
139:
140: LayoutSet existingLayoutSet = _persistence
141: .fetchByPrimaryKey(newLayoutSet.getPrimaryKey());
142:
143: assertEquals(existingLayoutSet, newLayoutSet);
144: }
145:
146: public void testFetchByPrimaryKeyMissing() throws Exception {
147: long pk = nextLong();
148:
149: LayoutSet missingLayoutSet = _persistence.fetchByPrimaryKey(pk);
150:
151: assertNull(missingLayoutSet);
152: }
153:
154: protected LayoutSet addLayoutSet() throws Exception {
155: long pk = nextLong();
156:
157: LayoutSet layoutSet = _persistence.create(pk);
158:
159: layoutSet.setGroupId(nextLong());
160: layoutSet.setCompanyId(nextLong());
161: layoutSet.setPrivateLayout(randomBoolean());
162: layoutSet.setLogo(randomBoolean());
163: layoutSet.setLogoId(nextLong());
164: layoutSet.setThemeId(randomString());
165: layoutSet.setColorSchemeId(randomString());
166: layoutSet.setWapThemeId(randomString());
167: layoutSet.setWapColorSchemeId(randomString());
168: layoutSet.setCss(randomString());
169: layoutSet.setPageCount(nextInt());
170: layoutSet.setVirtualHost(randomString());
171:
172: _persistence.update(layoutSet);
173:
174: return layoutSet;
175: }
176:
177: private static final String _TX_IMPL = LayoutSetPersistence.class
178: .getName()
179: + ".transaction";
180: private LayoutSetPersistence _persistence;
181: }
|