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