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