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