use of org.olat.commons.calendar.model.ImportedCalendar in project openolat by klemens.
the class ImportedCalendarDAOTest method getImportedCalendar.
@Test
public void getImportedCalendar() {
Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("Imp-cal-2");
String calendarId = UUID.randomUUID().toString();
String type = "imported-test-2";
String url = "http://www.openolat.org/calendar1.ics";
ImportedCalendar importedCalendar = importedCalendarDao.createImportedCalendar(user, "Imported calendar 2", calendarId, type, url, new Date());
Assert.assertNotNull(importedCalendar);
dbInstance.commit();
List<ImportedCalendar> calendars = importedCalendarDao.getImportedCalendar(user, calendarId, type);
Assert.assertNotNull(calendars);
Assert.assertEquals(1, calendars.size());
Assert.assertTrue(calendars.contains(importedCalendar));
// paranoia check
ImportedCalendar reloadedCalendar = calendars.get(0);
Assert.assertNotNull(reloadedCalendar.getCreationDate());
Assert.assertNotNull(reloadedCalendar.getLastModified());
Assert.assertNotNull(reloadedCalendar.getLastUpdate());
Assert.assertEquals(importedCalendar.getKey(), reloadedCalendar.getKey());
Assert.assertEquals("Imported calendar 2", reloadedCalendar.getDisplayName());
Assert.assertEquals(user, reloadedCalendar.getIdentity());
Assert.assertEquals(calendarId, reloadedCalendar.getCalendarId());
Assert.assertEquals(type, reloadedCalendar.getType());
Assert.assertEquals(url, reloadedCalendar.getUrl());
}
use of org.olat.commons.calendar.model.ImportedCalendar in project openolat by klemens.
the class ImportedCalendarDAOTest method deleteImportedCalendar.
@Test
public void deleteImportedCalendar() {
Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("Imp-cal-5");
String calendarId = UUID.randomUUID().toString();
ImportedCalendar importedCalendar1 = importedCalendarDao.createImportedCalendar(user, "Imported calendar 5", calendarId, "rnd-3", null, new Date());
ImportedCalendar importedCalendar2 = importedCalendarDao.createImportedCalendar(user, "Imported calendar 6", UUID.randomUUID().toString(), "rnd-4", "http://www.openolat.org/calendar5.ics", new Date());
// noise
Identity noiseUser = JunitTestHelper.createAndPersistIdentityAsRndUser("Imp-cal-6");
ImportedCalendar noiseImportedCalendar = importedCalendarDao.createImportedCalendar(noiseUser, "Imported calendar 7", calendarId, "rnd-3", null, new Date());
dbInstance.commit();
// check
List<ImportedCalendar> importedCalendars = importedCalendarDao.getImportedCalendars(user);
Assert.assertEquals(2, importedCalendars.size());
List<ImportedCalendar> noiseImportedCalendars = importedCalendarDao.getImportedCalendars(noiseUser);
Assert.assertEquals(1, noiseImportedCalendars.size());
// delete
importedCalendarDao.deleteImportedCalendar(user, calendarId, "rnd-3");
dbInstance.commitAndCloseSession();
// check the the first imported calendar is really deleted
List<ImportedCalendar> reloadedCalendars = importedCalendarDao.getImportedCalendars(user);
Assert.assertEquals(1, reloadedCalendars.size());
Assert.assertFalse(reloadedCalendars.contains(importedCalendar1));
Assert.assertTrue(reloadedCalendars.contains(importedCalendar2));
Assert.assertFalse(reloadedCalendars.contains(noiseImportedCalendar));
// noise must still have its calendar
List<ImportedCalendar> noiseReloadedCalendars = importedCalendarDao.getImportedCalendars(noiseUser);
Assert.assertEquals(1, noiseReloadedCalendars.size());
Assert.assertFalse(noiseReloadedCalendars.contains(importedCalendar1));
Assert.assertFalse(noiseReloadedCalendars.contains(importedCalendar2));
Assert.assertTrue(noiseReloadedCalendars.contains(noiseImportedCalendar));
}
use of org.olat.commons.calendar.model.ImportedCalendar in project openolat by klemens.
the class ImportedCalendarDAO method createImportedCalendar.
public ImportedCalendar createImportedCalendar(Identity owner, String displayName, String calendarId, String type, String url, Date lastUpdate) {
ImportedCalendar calendar = new ImportedCalendar();
calendar.setCreationDate(new Date());
calendar.setLastModified(calendar.getCreationDate());
calendar.setLastUpdate(lastUpdate);
calendar.setDisplayName(displayName);
calendar.setCalendarId(calendarId);
calendar.setType(type);
calendar.setUrl(url);
calendar.setIdentity(owner);
dbInstance.getCurrentEntityManager().persist(calendar);
return calendar;
}
Aggregations