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.wiki.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.wiki.NoSuchPageException;
027: import com.liferay.portlet.wiki.model.WikiPage;
028:
029: /**
030: * <a href="WikiPagePersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class WikiPagePersistenceTest extends BasePersistenceTestCase {
036: protected void setUp() throws Exception {
037: super .setUp();
038:
039: _persistence = (WikiPagePersistence) BeanLocatorUtil
040: .locate(_TX_IMPL);
041: }
042:
043: public void testCreate() throws Exception {
044: long pk = nextLong();
045:
046: WikiPage wikiPage = _persistence.create(pk);
047:
048: assertNotNull(wikiPage);
049:
050: assertEquals(wikiPage.getPrimaryKey(), pk);
051: }
052:
053: public void testRemove() throws Exception {
054: WikiPage newWikiPage = addWikiPage();
055:
056: _persistence.remove(newWikiPage);
057:
058: WikiPage existingWikiPage = _persistence
059: .fetchByPrimaryKey(newWikiPage.getPrimaryKey());
060:
061: assertNull(existingWikiPage);
062: }
063:
064: public void testUpdateNew() throws Exception {
065: addWikiPage();
066: }
067:
068: public void testUpdateExisting() throws Exception {
069: long pk = nextLong();
070:
071: WikiPage newWikiPage = _persistence.create(pk);
072:
073: newWikiPage.setUuid(randomString());
074: newWikiPage.setResourcePrimKey(nextLong());
075: newWikiPage.setCompanyId(nextLong());
076: newWikiPage.setUserId(nextLong());
077: newWikiPage.setUserName(randomString());
078: newWikiPage.setCreateDate(nextDate());
079: newWikiPage.setNodeId(nextLong());
080: newWikiPage.setTitle(randomString());
081: newWikiPage.setVersion(nextDouble());
082: newWikiPage.setContent(randomString());
083: newWikiPage.setFormat(randomString());
084: newWikiPage.setHead(randomBoolean());
085:
086: _persistence.update(newWikiPage);
087:
088: WikiPage existingWikiPage = _persistence
089: .findByPrimaryKey(newWikiPage.getPrimaryKey());
090:
091: assertEquals(existingWikiPage.getUuid(), newWikiPage.getUuid());
092: assertEquals(existingWikiPage.getPageId(), newWikiPage
093: .getPageId());
094: assertEquals(existingWikiPage.getResourcePrimKey(), newWikiPage
095: .getResourcePrimKey());
096: assertEquals(existingWikiPage.getCompanyId(), newWikiPage
097: .getCompanyId());
098: assertEquals(existingWikiPage.getUserId(), newWikiPage
099: .getUserId());
100: assertEquals(existingWikiPage.getUserName(), newWikiPage
101: .getUserName());
102: assertEquals(existingWikiPage.getCreateDate(), newWikiPage
103: .getCreateDate());
104: assertEquals(existingWikiPage.getNodeId(), newWikiPage
105: .getNodeId());
106: assertEquals(existingWikiPage.getTitle(), newWikiPage
107: .getTitle());
108: assertEquals(existingWikiPage.getVersion(), newWikiPage
109: .getVersion());
110: assertEquals(existingWikiPage.getContent(), newWikiPage
111: .getContent());
112: assertEquals(existingWikiPage.getFormat(), newWikiPage
113: .getFormat());
114: assertEquals(existingWikiPage.getHead(), newWikiPage.getHead());
115: }
116:
117: public void testFindByPrimaryKeyExisting() throws Exception {
118: WikiPage newWikiPage = addWikiPage();
119:
120: WikiPage existingWikiPage = _persistence
121: .findByPrimaryKey(newWikiPage.getPrimaryKey());
122:
123: assertEquals(existingWikiPage, newWikiPage);
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 NoSuchPageException");
133: } catch (NoSuchPageException nsee) {
134: }
135: }
136:
137: public void testFetchByPrimaryKeyExisting() throws Exception {
138: WikiPage newWikiPage = addWikiPage();
139:
140: WikiPage existingWikiPage = _persistence
141: .fetchByPrimaryKey(newWikiPage.getPrimaryKey());
142:
143: assertEquals(existingWikiPage, newWikiPage);
144: }
145:
146: public void testFetchByPrimaryKeyMissing() throws Exception {
147: long pk = nextLong();
148:
149: WikiPage missingWikiPage = _persistence.fetchByPrimaryKey(pk);
150:
151: assertNull(missingWikiPage);
152: }
153:
154: protected WikiPage addWikiPage() throws Exception {
155: long pk = nextLong();
156:
157: WikiPage wikiPage = _persistence.create(pk);
158:
159: wikiPage.setUuid(randomString());
160: wikiPage.setResourcePrimKey(nextLong());
161: wikiPage.setCompanyId(nextLong());
162: wikiPage.setUserId(nextLong());
163: wikiPage.setUserName(randomString());
164: wikiPage.setCreateDate(nextDate());
165: wikiPage.setNodeId(nextLong());
166: wikiPage.setTitle(randomString());
167: wikiPage.setVersion(nextDouble());
168: wikiPage.setContent(randomString());
169: wikiPage.setFormat(randomString());
170: wikiPage.setHead(randomBoolean());
171:
172: _persistence.update(wikiPage);
173:
174: return wikiPage;
175: }
176:
177: private static final String _TX_IMPL = WikiPagePersistence.class
178: .getName()
179: + ".transaction";
180: private WikiPagePersistence _persistence;
181: }
|