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