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.portlet.calendar.service.persistence;
022:
023: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
024: import com.liferay.portal.service.persistence.BasePersistenceTestCase;
025:
026: import com.liferay.portlet.calendar.NoSuchEventException;
027: import com.liferay.portlet.calendar.model.CalEvent;
028:
029: /**
030: * <a href="CalEventPersistenceTest.java.html"><b><i>View Source</i></b></a>
031: *
032: * @author Brian Wing Shun Chan
033: *
034: */
035: public class CalEventPersistenceTest extends BasePersistenceTestCase {
036: protected void setUp() throws Exception {
037: super .setUp();
038:
039: _persistence = (CalEventPersistence) BeanLocatorUtil
040: .locate(_TX_IMPL);
041: }
042:
043: public void testCreate() throws Exception {
044: long pk = nextLong();
045:
046: CalEvent calEvent = _persistence.create(pk);
047:
048: assertNotNull(calEvent);
049:
050: assertEquals(calEvent.getPrimaryKey(), pk);
051: }
052:
053: public void testRemove() throws Exception {
054: CalEvent newCalEvent = addCalEvent();
055:
056: _persistence.remove(newCalEvent);
057:
058: CalEvent existingCalEvent = _persistence
059: .fetchByPrimaryKey(newCalEvent.getPrimaryKey());
060:
061: assertNull(existingCalEvent);
062: }
063:
064: public void testUpdateNew() throws Exception {
065: addCalEvent();
066: }
067:
068: public void testUpdateExisting() throws Exception {
069: long pk = nextLong();
070:
071: CalEvent newCalEvent = _persistence.create(pk);
072:
073: newCalEvent.setUuid(randomString());
074: newCalEvent.setGroupId(nextLong());
075: newCalEvent.setCompanyId(nextLong());
076: newCalEvent.setUserId(nextLong());
077: newCalEvent.setUserName(randomString());
078: newCalEvent.setCreateDate(nextDate());
079: newCalEvent.setModifiedDate(nextDate());
080: newCalEvent.setTitle(randomString());
081: newCalEvent.setDescription(randomString());
082: newCalEvent.setStartDate(nextDate());
083: newCalEvent.setEndDate(nextDate());
084: newCalEvent.setDurationHour(nextInt());
085: newCalEvent.setDurationMinute(nextInt());
086: newCalEvent.setAllDay(randomBoolean());
087: newCalEvent.setTimeZoneSensitive(randomBoolean());
088: newCalEvent.setType(randomString());
089: newCalEvent.setRepeating(randomBoolean());
090: newCalEvent.setRecurrence(randomString());
091: newCalEvent.setRemindBy(randomString());
092: newCalEvent.setFirstReminder(nextInt());
093: newCalEvent.setSecondReminder(nextInt());
094:
095: _persistence.update(newCalEvent);
096:
097: CalEvent existingCalEvent = _persistence
098: .findByPrimaryKey(newCalEvent.getPrimaryKey());
099:
100: assertEquals(existingCalEvent.getUuid(), newCalEvent.getUuid());
101: assertEquals(existingCalEvent.getEventId(), newCalEvent
102: .getEventId());
103: assertEquals(existingCalEvent.getGroupId(), newCalEvent
104: .getGroupId());
105: assertEquals(existingCalEvent.getCompanyId(), newCalEvent
106: .getCompanyId());
107: assertEquals(existingCalEvent.getUserId(), newCalEvent
108: .getUserId());
109: assertEquals(existingCalEvent.getUserName(), newCalEvent
110: .getUserName());
111: assertEquals(existingCalEvent.getCreateDate(), newCalEvent
112: .getCreateDate());
113: assertEquals(existingCalEvent.getModifiedDate(), newCalEvent
114: .getModifiedDate());
115: assertEquals(existingCalEvent.getTitle(), newCalEvent
116: .getTitle());
117: assertEquals(existingCalEvent.getDescription(), newCalEvent
118: .getDescription());
119: assertEquals(existingCalEvent.getStartDate(), newCalEvent
120: .getStartDate());
121: assertEquals(existingCalEvent.getEndDate(), newCalEvent
122: .getEndDate());
123: assertEquals(existingCalEvent.getDurationHour(), newCalEvent
124: .getDurationHour());
125: assertEquals(existingCalEvent.getDurationMinute(), newCalEvent
126: .getDurationMinute());
127: assertEquals(existingCalEvent.getAllDay(), newCalEvent
128: .getAllDay());
129: assertEquals(existingCalEvent.getTimeZoneSensitive(),
130: newCalEvent.getTimeZoneSensitive());
131: assertEquals(existingCalEvent.getType(), newCalEvent.getType());
132: assertEquals(existingCalEvent.getRepeating(), newCalEvent
133: .getRepeating());
134: assertEquals(existingCalEvent.getRecurrence(), newCalEvent
135: .getRecurrence());
136: assertEquals(existingCalEvent.getRemindBy(), newCalEvent
137: .getRemindBy());
138: assertEquals(existingCalEvent.getFirstReminder(), newCalEvent
139: .getFirstReminder());
140: assertEquals(existingCalEvent.getSecondReminder(), newCalEvent
141: .getSecondReminder());
142: }
143:
144: public void testFindByPrimaryKeyExisting() throws Exception {
145: CalEvent newCalEvent = addCalEvent();
146:
147: CalEvent existingCalEvent = _persistence
148: .findByPrimaryKey(newCalEvent.getPrimaryKey());
149:
150: assertEquals(existingCalEvent, newCalEvent);
151: }
152:
153: public void testFindByPrimaryKeyMissing() throws Exception {
154: long pk = nextLong();
155:
156: try {
157: _persistence.findByPrimaryKey(pk);
158:
159: fail("Missing entity did not throw NoSuchEventException");
160: } catch (NoSuchEventException nsee) {
161: }
162: }
163:
164: public void testFetchByPrimaryKeyExisting() throws Exception {
165: CalEvent newCalEvent = addCalEvent();
166:
167: CalEvent existingCalEvent = _persistence
168: .fetchByPrimaryKey(newCalEvent.getPrimaryKey());
169:
170: assertEquals(existingCalEvent, newCalEvent);
171: }
172:
173: public void testFetchByPrimaryKeyMissing() throws Exception {
174: long pk = nextLong();
175:
176: CalEvent missingCalEvent = _persistence.fetchByPrimaryKey(pk);
177:
178: assertNull(missingCalEvent);
179: }
180:
181: protected CalEvent addCalEvent() throws Exception {
182: long pk = nextLong();
183:
184: CalEvent calEvent = _persistence.create(pk);
185:
186: calEvent.setUuid(randomString());
187: calEvent.setGroupId(nextLong());
188: calEvent.setCompanyId(nextLong());
189: calEvent.setUserId(nextLong());
190: calEvent.setUserName(randomString());
191: calEvent.setCreateDate(nextDate());
192: calEvent.setModifiedDate(nextDate());
193: calEvent.setTitle(randomString());
194: calEvent.setDescription(randomString());
195: calEvent.setStartDate(nextDate());
196: calEvent.setEndDate(nextDate());
197: calEvent.setDurationHour(nextInt());
198: calEvent.setDurationMinute(nextInt());
199: calEvent.setAllDay(randomBoolean());
200: calEvent.setTimeZoneSensitive(randomBoolean());
201: calEvent.setType(randomString());
202: calEvent.setRepeating(randomBoolean());
203: calEvent.setRecurrence(randomString());
204: calEvent.setRemindBy(randomString());
205: calEvent.setFirstReminder(nextInt());
206: calEvent.setSecondReminder(nextInt());
207:
208: _persistence.update(calEvent);
209:
210: return calEvent;
211: }
212:
213: private static final String _TX_IMPL = CalEventPersistence.class
214: .getName()
215: + ".transaction";
216: private CalEventPersistence _persistence;
217: }
|