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