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.NoSuchWebsiteException;
024: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
025: import com.liferay.portal.model.Website;
026: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
027:
028: /**
029: * <a href="WebsitePersistenceTest.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class WebsitePersistenceTest extends BasePersistenceTestCase {
035: protected void setUp() throws Exception {
036: super .setUp();
037:
038: _persistence = (WebsitePersistence) BeanLocatorUtil
039: .locate(_TX_IMPL);
040: }
041:
042: public void testCreate() throws Exception {
043: long pk = nextLong();
044:
045: Website website = _persistence.create(pk);
046:
047: assertNotNull(website);
048:
049: assertEquals(website.getPrimaryKey(), pk);
050: }
051:
052: public void testRemove() throws Exception {
053: Website newWebsite = addWebsite();
054:
055: _persistence.remove(newWebsite);
056:
057: Website existingWebsite = _persistence
058: .fetchByPrimaryKey(newWebsite.getPrimaryKey());
059:
060: assertNull(existingWebsite);
061: }
062:
063: public void testUpdateNew() throws Exception {
064: addWebsite();
065: }
066:
067: public void testUpdateExisting() throws Exception {
068: long pk = nextLong();
069:
070: Website newWebsite = _persistence.create(pk);
071:
072: newWebsite.setCompanyId(nextLong());
073: newWebsite.setUserId(nextLong());
074: newWebsite.setUserName(randomString());
075: newWebsite.setCreateDate(nextDate());
076: newWebsite.setModifiedDate(nextDate());
077: newWebsite.setClassNameId(nextLong());
078: newWebsite.setClassPK(nextLong());
079: newWebsite.setUrl(randomString());
080: newWebsite.setTypeId(nextInt());
081: newWebsite.setPrimary(randomBoolean());
082:
083: _persistence.update(newWebsite);
084:
085: Website existingWebsite = _persistence
086: .findByPrimaryKey(newWebsite.getPrimaryKey());
087:
088: assertEquals(existingWebsite.getWebsiteId(), newWebsite
089: .getWebsiteId());
090: assertEquals(existingWebsite.getCompanyId(), newWebsite
091: .getCompanyId());
092: assertEquals(existingWebsite.getUserId(), newWebsite
093: .getUserId());
094: assertEquals(existingWebsite.getUserName(), newWebsite
095: .getUserName());
096: assertEquals(existingWebsite.getCreateDate(), newWebsite
097: .getCreateDate());
098: assertEquals(existingWebsite.getModifiedDate(), newWebsite
099: .getModifiedDate());
100: assertEquals(existingWebsite.getClassNameId(), newWebsite
101: .getClassNameId());
102: assertEquals(existingWebsite.getClassPK(), newWebsite
103: .getClassPK());
104: assertEquals(existingWebsite.getUrl(), newWebsite.getUrl());
105: assertEquals(existingWebsite.getTypeId(), newWebsite
106: .getTypeId());
107: assertEquals(existingWebsite.getPrimary(), newWebsite
108: .getPrimary());
109: }
110:
111: public void testFindByPrimaryKeyExisting() throws Exception {
112: Website newWebsite = addWebsite();
113:
114: Website existingWebsite = _persistence
115: .findByPrimaryKey(newWebsite.getPrimaryKey());
116:
117: assertEquals(existingWebsite, newWebsite);
118: }
119:
120: public void testFindByPrimaryKeyMissing() throws Exception {
121: long pk = nextLong();
122:
123: try {
124: _persistence.findByPrimaryKey(pk);
125:
126: fail("Missing entity did not throw NoSuchWebsiteException");
127: } catch (NoSuchWebsiteException nsee) {
128: }
129: }
130:
131: public void testFetchByPrimaryKeyExisting() throws Exception {
132: Website newWebsite = addWebsite();
133:
134: Website existingWebsite = _persistence
135: .fetchByPrimaryKey(newWebsite.getPrimaryKey());
136:
137: assertEquals(existingWebsite, newWebsite);
138: }
139:
140: public void testFetchByPrimaryKeyMissing() throws Exception {
141: long pk = nextLong();
142:
143: Website missingWebsite = _persistence.fetchByPrimaryKey(pk);
144:
145: assertNull(missingWebsite);
146: }
147:
148: protected Website addWebsite() throws Exception {
149: long pk = nextLong();
150:
151: Website website = _persistence.create(pk);
152:
153: website.setCompanyId(nextLong());
154: website.setUserId(nextLong());
155: website.setUserName(randomString());
156: website.setCreateDate(nextDate());
157: website.setModifiedDate(nextDate());
158: website.setClassNameId(nextLong());
159: website.setClassPK(nextLong());
160: website.setUrl(randomString());
161: website.setTypeId(nextInt());
162: website.setPrimary(randomBoolean());
163:
164: _persistence.update(website);
165:
166: return website;
167: }
168:
169: private static final String _TX_IMPL = WebsitePersistence.class
170: .getName()
171: + ".transaction";
172: private WebsitePersistence _persistence;
173: }
|