use of org.olat.commons.calendar.restapi.EventVO in project OpenOLAT by OpenOLAT.
the class CourseCalendarTest method deleteCalendarEvent.
@Test
public void deleteCalendarEvent() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(auth1.getName(), "A6B7C8"));
// create an event if the event is saved
KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course1);
Calendar cal = Calendar.getInstance();
Date begin = cal.getTime();
cal.add(Calendar.HOUR_OF_DAY, 1);
String id = UUID.randomUUID().toString();
KalendarEvent kalEvent = new KalendarEvent(id, null, "Subject (" + id + ")", begin, cal.getTime());
calendarManager.addEventTo(calendarWrapper.getKalendar(), kalEvent);
// check if the event exists
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course1.getResourceableId().toString()).path("calendar").path("events").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<EventVO> vos = parseEventArray(response.getEntity().getContent());
assertNotNull(vos);
boolean found = false;
for (EventVO vo : vos) {
if (id.equals(vo.getId())) {
found = true;
}
}
assertTrue(found);
// delete the event
URI eventUri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course1.getResourceableId().toString()).path("calendar").path("events").path(kalEvent.getID()).build();
HttpDelete delEventMethod = conn.createDelete(eventUri, MediaType.APPLICATION_JSON);
HttpResponse delEventResponse = conn.execute(delEventMethod);
assertEquals(200, delEventResponse.getStatusLine().getStatusCode());
EntityUtils.consume(delEventResponse.getEntity());
conn.shutdown();
// check if the event is really deleted
KalendarRenderWrapper reloadedCalendarWrapper = calendarManager.getCourseCalendar(course1);
Collection<KalendarEvent> savedEvents = reloadedCalendarWrapper.getKalendar().getEvents();
for (KalendarEvent savedEvent : savedEvents) {
Assert.assertFalse(savedEvent.getID().equals(kalEvent.getID()));
}
}
use of org.olat.commons.calendar.restapi.EventVO in project OpenOLAT by OpenOLAT.
the class CalendarTest method testGetCalendarEvents.
@Test
public void testGetCalendarEvents() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id1.getName(), "A6B7C8"));
URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id1.getKey().toString()).path("calendars").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<CalendarVO> vos = parseArray(response);
assertNotNull(vos);
// course1 + personal
assertTrue(2 <= vos.size());
CalendarVO calendar = getCourseCalendar(vos, course1);
URI eventUri = UriBuilder.fromUri(getContextURI()).path("users").path(id1.getKey().toString()).path("calendars").path(calendar.getId()).path("events").build();
HttpGet eventMethod = conn.createGet(eventUri, MediaType.APPLICATION_JSON, true);
HttpResponse eventResponse = conn.execute(eventMethod);
assertEquals(200, eventResponse.getStatusLine().getStatusCode());
List<EventVO> events = parseEventArray(eventResponse);
assertNotNull(events);
// Root-1
assertEquals(11, events.size());
conn.shutdown();
}
use of org.olat.commons.calendar.restapi.EventVO in project OpenOLAT by OpenOLAT.
the class CalendarTest method testGetEvents_onlyFuture.
@Test
public void testGetEvents_onlyFuture() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id1.getName(), "A6B7C8"));
URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id1.getKey().toString()).path("calendars").path("events").queryParam("onlyFuture", "true").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<EventVO> vos = parseEventArray(response);
assertNotNull(vos);
// Root-1
assertTrue(10 <= vos.size());
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date currentDate = cal.getTime();
for (EventVO event : vos) {
assertTrue(currentDate.equals(event.getEnd()) || currentDate.before(event.getEnd()));
}
conn.shutdown();
}
use of org.olat.commons.calendar.restapi.EventVO in project openolat by klemens.
the class CalendarTest method testPutPersonalCalendarEvents.
@Test
public void testPutPersonalCalendarEvents() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id2.getName(), "A6B7C8"));
URI calUri = UriBuilder.fromUri(getContextURI()).path("users").path(id2.getKey().toString()).path("calendars").build();
HttpGet calMethod = conn.createGet(calUri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(calMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
List<CalendarVO> vos = parseArray(response);
assertNotNull(vos);
assertTrue(2 <= vos.size());
CalendarVO calendar = getUserCalendar(vos);
// create an event
EventVO event = new EventVO();
Calendar cal = Calendar.getInstance();
event.setBegin(cal.getTime());
cal.add(Calendar.HOUR_OF_DAY, 1);
event.setEnd(cal.getTime());
String subject = UUID.randomUUID().toString();
event.setSubject(subject);
URI eventUri = UriBuilder.fromUri(getContextURI()).path("users").path(id2.getKey().toString()).path("calendars").path(calendar.getId()).path("event").build();
HttpPut putEventMethod = conn.createPut(eventUri, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(putEventMethod, event);
HttpResponse putEventResponse = conn.execute(putEventMethod);
assertEquals(200, putEventResponse.getStatusLine().getStatusCode());
EntityUtils.consume(putEventResponse.getEntity());
// check if the event is saved
KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(id2);
Collection<KalendarEvent> savedEvents = calendarWrapper.getKalendar().getEvents();
boolean found = false;
for (KalendarEvent savedEvent : savedEvents) {
if (subject.equals(savedEvent.getSubject())) {
found = true;
}
}
Assert.assertTrue(found);
conn.shutdown();
}
use of org.olat.commons.calendar.restapi.EventVO in project openolat by klemens.
the class CalendarTest method testGetEvents_onlyFuture.
@Test
public void testGetEvents_onlyFuture() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id1.getName(), "A6B7C8"));
URI uri = UriBuilder.fromUri(getContextURI()).path("users").path(id1.getKey().toString()).path("calendars").path("events").queryParam("onlyFuture", "true").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<EventVO> vos = parseEventArray(response);
assertNotNull(vos);
// Root-1
assertTrue(10 <= vos.size());
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date currentDate = cal.getTime();
for (EventVO event : vos) {
assertTrue(currentDate.equals(event.getEnd()) || currentDate.before(event.getEnd()));
}
conn.shutdown();
}
Aggregations