Skip to content

Commit

Permalink
Fix timestamp related test failure
Browse files Browse the repository at this point in the history
Due to Timestamp not properly overloading after(Date).

See issue #1 for preferred solution
  • Loading branch information
nealeu committed Jan 15, 2013
1 parent ee442df commit 7ff992e
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
*/
package org.osaf.cosmo.dao.hibernate;

import junit.framework.Assert;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.Component;
import net.fortuna.ical4j.model.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.validator.InvalidStateException;
import org.junit.Assert;
import org.osaf.cosmo.calendar.EntityConverter;
import org.osaf.cosmo.dao.UserDao;
import org.osaf.cosmo.model.CalendarCollectionStamp;
Expand Down Expand Up @@ -57,7 +59,7 @@ public HibernateContentDaoStampingTest() {
public void testStampsCreate() throws Exception {
EntityConverter entityConverter = new EntityConverter(null);
User user = getUser(userDao, "testuser");
CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
CollectionItem root = contentDao.getRootItem(user);

NoteItem item = generateTestContent();

Expand Down Expand Up @@ -107,7 +109,7 @@ public void testStampsCreate() throws Exception {

public void testStampHandlers() throws Exception {
User user = getUser(userDao, "testuser");
CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
CollectionItem root = contentDao.getRootItem(user);

NoteItem item = generateTestContent();

Expand Down Expand Up @@ -147,7 +149,7 @@ public void testStampHandlers() throws Exception {

public void testStampsUpdate() throws Exception {
User user = getUser(userDao, "testuser");
CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
CollectionItem root = contentDao.getRootItem(user);

ContentItem item = generateTestContent();

Expand Down Expand Up @@ -180,7 +182,7 @@ public void testStampsUpdate() throws Exception {
queryItem.setClientModifiedDate(new Date());
es.setEventCalendar(helper.getCalendar("cal2.ics"));
Calendar newCal = es.getEventCalendar();
Thread.sleep(10);
Thread.sleep(1000); // need to sleep 1 sec as getModifiedDate() is Timestamp and SQL db resolution may be only 1 sec

contentDao.updateContent(queryItem);

Expand All @@ -191,7 +193,11 @@ public void testStampsUpdate() throws Exception {
stamp = queryItem.getStamp(EventStamp.class);
es = (EventStamp) stamp;

Assert.assertTrue(stamp.getModifiedDate().after(stamp.getCreationDate()));
// NOTE: NOTE! this calls Date.after(Date) instead of Timestamp.after(Timestamp),
// so will only see resolution of seconds
// Assert.assertTrue(stamp.getModifiedDate().after(stamp.getCreationDate()));
// This uses compareTo, which does work
Assert.assertThat(stamp.getModifiedDate(),is(greaterThan(stamp.getCreationDate())));

if(!es.getEventCalendar().toString().equals(newCal.toString())) {
log.error(es.getEventCalendar().toString());
Expand All @@ -202,7 +208,7 @@ public void testStampsUpdate() throws Exception {

public void testEventStampValidation() throws Exception {
User user = getUser(userDao, "testuser");
CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
CollectionItem root = contentDao.getRootItem(user);

ContentItem item = generateTestContent();

Expand All @@ -220,7 +226,7 @@ public void testEventStampValidation() throws Exception {

public void testRemoveStamp() throws Exception {
User user = getUser(userDao, "testuser");
CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
CollectionItem root = contentDao.getRootItem(user);

NoteItem item = generateTestContent();

Expand Down Expand Up @@ -261,7 +267,7 @@ public void testRemoveStamp() throws Exception {

public void testCalendarCollectionStamp() throws Exception {
User user = getUser(userDao, "testuser");
CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
CollectionItem root = contentDao.getRootItem(user);

Calendar testCal = helper.getCalendar("timezone.ics");

Expand Down Expand Up @@ -302,7 +308,7 @@ public void testCalendarCollectionStamp() throws Exception {

public void testCalendarCollectionStampValidation() throws Exception {
User user = getUser(userDao, "testuser");
CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
CollectionItem root = contentDao.getRootItem(user);

Calendar testCal = helper.getCalendar("cal1.ics");

Expand All @@ -322,7 +328,7 @@ public void testCalendarCollectionStampValidation() throws Exception {

public void testEventExceptionStamp() throws Exception {
User user = getUser(userDao, "testuser");
CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
CollectionItem root = contentDao.getRootItem(user);

NoteItem item = generateTestContent();

Expand Down Expand Up @@ -353,7 +359,7 @@ public void testEventExceptionStamp() throws Exception {

public void testEventExceptionStampValidation() throws Exception {
User user = getUser(userDao, "testuser");
CollectionItem root = (CollectionItem) contentDao.getRootItem(user);
CollectionItem root = contentDao.getRootItem(user);

NoteItem item = generateTestContent();

Expand Down

0 comments on commit 7ff992e

Please sign in to comment.