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.NoSuchPageResourceException;
027: import com.liferay.portlet.wiki.model.WikiPageResource;
028:
029: /**
030: * <a href="WikiPageResourcePersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class WikiPageResourcePersistenceTest extends
036: BasePersistenceTestCase {
037: protected void setUp() throws Exception {
038: super .setUp();
039:
040: _persistence = (WikiPageResourcePersistence) BeanLocatorUtil
041: .locate(_TX_IMPL);
042: }
043:
044: public void testCreate() throws Exception {
045: long pk = nextLong();
046:
047: WikiPageResource wikiPageResource = _persistence.create(pk);
048:
049: assertNotNull(wikiPageResource);
050:
051: assertEquals(wikiPageResource.getPrimaryKey(), pk);
052: }
053:
054: public void testRemove() throws Exception {
055: WikiPageResource newWikiPageResource = addWikiPageResource();
056:
057: _persistence.remove(newWikiPageResource);
058:
059: WikiPageResource existingWikiPageResource = _persistence
060: .fetchByPrimaryKey(newWikiPageResource.getPrimaryKey());
061:
062: assertNull(existingWikiPageResource);
063: }
064:
065: public void testUpdateNew() throws Exception {
066: addWikiPageResource();
067: }
068:
069: public void testUpdateExisting() throws Exception {
070: long pk = nextLong();
071:
072: WikiPageResource newWikiPageResource = _persistence.create(pk);
073:
074: newWikiPageResource.setNodeId(nextLong());
075: newWikiPageResource.setTitle(randomString());
076:
077: _persistence.update(newWikiPageResource);
078:
079: WikiPageResource existingWikiPageResource = _persistence
080: .findByPrimaryKey(newWikiPageResource.getPrimaryKey());
081:
082: assertEquals(existingWikiPageResource.getResourcePrimKey(),
083: newWikiPageResource.getResourcePrimKey());
084: assertEquals(existingWikiPageResource.getNodeId(),
085: newWikiPageResource.getNodeId());
086: assertEquals(existingWikiPageResource.getTitle(),
087: newWikiPageResource.getTitle());
088: }
089:
090: public void testFindByPrimaryKeyExisting() throws Exception {
091: WikiPageResource newWikiPageResource = addWikiPageResource();
092:
093: WikiPageResource existingWikiPageResource = _persistence
094: .findByPrimaryKey(newWikiPageResource.getPrimaryKey());
095:
096: assertEquals(existingWikiPageResource, newWikiPageResource);
097: }
098:
099: public void testFindByPrimaryKeyMissing() throws Exception {
100: long pk = nextLong();
101:
102: try {
103: _persistence.findByPrimaryKey(pk);
104:
105: fail("Missing entity did not throw NoSuchPageResourceException");
106: } catch (NoSuchPageResourceException nsee) {
107: }
108: }
109:
110: public void testFetchByPrimaryKeyExisting() throws Exception {
111: WikiPageResource newWikiPageResource = addWikiPageResource();
112:
113: WikiPageResource existingWikiPageResource = _persistence
114: .fetchByPrimaryKey(newWikiPageResource.getPrimaryKey());
115:
116: assertEquals(existingWikiPageResource, newWikiPageResource);
117: }
118:
119: public void testFetchByPrimaryKeyMissing() throws Exception {
120: long pk = nextLong();
121:
122: WikiPageResource missingWikiPageResource = _persistence
123: .fetchByPrimaryKey(pk);
124:
125: assertNull(missingWikiPageResource);
126: }
127:
128: protected WikiPageResource addWikiPageResource() throws Exception {
129: long pk = nextLong();
130:
131: WikiPageResource wikiPageResource = _persistence.create(pk);
132:
133: wikiPageResource.setNodeId(nextLong());
134: wikiPageResource.setTitle(randomString());
135:
136: _persistence.update(wikiPageResource);
137:
138: return wikiPageResource;
139: }
140:
141: private static final String _TX_IMPL = WikiPageResourcePersistence.class
142: .getName()
143: + ".transaction";
144: private WikiPageResourcePersistence _persistence;
145: }
|