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