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