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