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