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