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