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