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