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.NoSuchNodeException;
027: import com.liferay.portlet.wiki.model.WikiNode;
028:
029: /**
030: * <a href="WikiNodePersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class WikiNodePersistenceTest extends BasePersistenceTestCase {
036: protected void setUp() throws Exception {
037: super .setUp();
038:
039: _persistence = (WikiNodePersistence) BeanLocatorUtil
040: .locate(_TX_IMPL);
041: }
042:
043: public void testCreate() throws Exception {
044: long pk = nextLong();
045:
046: WikiNode wikiNode = _persistence.create(pk);
047:
048: assertNotNull(wikiNode);
049:
050: assertEquals(wikiNode.getPrimaryKey(), pk);
051: }
052:
053: public void testRemove() throws Exception {
054: WikiNode newWikiNode = addWikiNode();
055:
056: _persistence.remove(newWikiNode);
057:
058: WikiNode existingWikiNode = _persistence
059: .fetchByPrimaryKey(newWikiNode.getPrimaryKey());
060:
061: assertNull(existingWikiNode);
062: }
063:
064: public void testUpdateNew() throws Exception {
065: addWikiNode();
066: }
067:
068: public void testUpdateExisting() throws Exception {
069: long pk = nextLong();
070:
071: WikiNode newWikiNode = _persistence.create(pk);
072:
073: newWikiNode.setUuid(randomString());
074: newWikiNode.setGroupId(nextLong());
075: newWikiNode.setCompanyId(nextLong());
076: newWikiNode.setUserId(nextLong());
077: newWikiNode.setUserName(randomString());
078: newWikiNode.setCreateDate(nextDate());
079: newWikiNode.setModifiedDate(nextDate());
080: newWikiNode.setName(randomString());
081: newWikiNode.setDescription(randomString());
082: newWikiNode.setLastPostDate(nextDate());
083:
084: _persistence.update(newWikiNode);
085:
086: WikiNode existingWikiNode = _persistence
087: .findByPrimaryKey(newWikiNode.getPrimaryKey());
088:
089: assertEquals(existingWikiNode.getUuid(), newWikiNode.getUuid());
090: assertEquals(existingWikiNode.getNodeId(), newWikiNode
091: .getNodeId());
092: assertEquals(existingWikiNode.getGroupId(), newWikiNode
093: .getGroupId());
094: assertEquals(existingWikiNode.getCompanyId(), newWikiNode
095: .getCompanyId());
096: assertEquals(existingWikiNode.getUserId(), newWikiNode
097: .getUserId());
098: assertEquals(existingWikiNode.getUserName(), newWikiNode
099: .getUserName());
100: assertEquals(existingWikiNode.getCreateDate(), newWikiNode
101: .getCreateDate());
102: assertEquals(existingWikiNode.getModifiedDate(), newWikiNode
103: .getModifiedDate());
104: assertEquals(existingWikiNode.getName(), newWikiNode.getName());
105: assertEquals(existingWikiNode.getDescription(), newWikiNode
106: .getDescription());
107: assertEquals(existingWikiNode.getLastPostDate(), newWikiNode
108: .getLastPostDate());
109: }
110:
111: public void testFindByPrimaryKeyExisting() throws Exception {
112: WikiNode newWikiNode = addWikiNode();
113:
114: WikiNode existingWikiNode = _persistence
115: .findByPrimaryKey(newWikiNode.getPrimaryKey());
116:
117: assertEquals(existingWikiNode, newWikiNode);
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 NoSuchNodeException");
127: } catch (NoSuchNodeException nsee) {
128: }
129: }
130:
131: public void testFetchByPrimaryKeyExisting() throws Exception {
132: WikiNode newWikiNode = addWikiNode();
133:
134: WikiNode existingWikiNode = _persistence
135: .fetchByPrimaryKey(newWikiNode.getPrimaryKey());
136:
137: assertEquals(existingWikiNode, newWikiNode);
138: }
139:
140: public void testFetchByPrimaryKeyMissing() throws Exception {
141: long pk = nextLong();
142:
143: WikiNode missingWikiNode = _persistence.fetchByPrimaryKey(pk);
144:
145: assertNull(missingWikiNode);
146: }
147:
148: protected WikiNode addWikiNode() throws Exception {
149: long pk = nextLong();
150:
151: WikiNode wikiNode = _persistence.create(pk);
152:
153: wikiNode.setUuid(randomString());
154: wikiNode.setGroupId(nextLong());
155: wikiNode.setCompanyId(nextLong());
156: wikiNode.setUserId(nextLong());
157: wikiNode.setUserName(randomString());
158: wikiNode.setCreateDate(nextDate());
159: wikiNode.setModifiedDate(nextDate());
160: wikiNode.setName(randomString());
161: wikiNode.setDescription(randomString());
162: wikiNode.setLastPostDate(nextDate());
163:
164: _persistence.update(wikiNode);
165:
166: return wikiNode;
167: }
168:
169: private static final String _TX_IMPL = WikiNodePersistence.class
170: .getName()
171: + ".transaction";
172: private WikiNodePersistence _persistence;
173: }
|