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