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