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