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