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