use of org.olat.commons.calendar.restapi.EventVO in project OpenOLAT by OpenOLAT.
the class CourseCalendarTest method putCalendarEvent.
@Test
public void putCalendarEvent() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(auth1.getName(), "A6B7C8"));
// 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("repo").path("courses").path(course1.getResourceableId().toString()).path("calendar").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.getCourseCalendar(course1);
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 OpenOLAT.
the class CourseCalendarTest method getCalendarEvents.
@Test
public void getCalendarEvents() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(auth1.getName(), "A6B7C8"));
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);
assertTrue(2 <= vos.size());
conn.shutdown();
}
use of org.olat.commons.calendar.restapi.EventVO in project OpenOLAT by OpenOLAT.
the class CourseCalendarTest method putCalendarEvents.
@Test
public void putCalendarEvents() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
Identity admin = BaseSecurityManager.getInstance().findIdentityByName("administrator");
Assert.assertTrue(conn.login("administrator", "openolat"));
CourseConfigVO config = new CourseConfigVO();
config.setCalendar(Boolean.TRUE);
ICourse course = CoursesWebService.createEmptyCourse(admin, "Course with calendar", "Course with calendar", config);
dbInstance.commitAndCloseSession();
// create an event
EventVO event1 = new EventVO();
Calendar cal = Calendar.getInstance();
event1.setBegin(cal.getTime());
cal.add(Calendar.HOUR_OF_DAY, 1);
event1.setEnd(cal.getTime());
String subject1 = UUID.randomUUID().toString();
event1.setSubject(subject1);
EventVO event2 = new EventVO();
event2.setBegin(cal.getTime());
cal.add(Calendar.HOUR_OF_DAY, 1);
event2.setEnd(cal.getTime());
String subject2 = UUID.randomUUID().toString();
event2.setSubject(subject2);
EventVO[] newEvents = new EventVO[2];
newEvents[0] = event1;
newEvents[1] = event2;
URI eventUri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course.getResourceableId().toString()).path("calendar").path("events").build();
HttpPut putEventMethod = conn.createPut(eventUri, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(putEventMethod, newEvents);
HttpResponse putEventResponse = conn.execute(putEventMethod);
assertEquals(200, putEventResponse.getStatusLine().getStatusCode());
EntityUtils.consume(putEventResponse.getEntity());
// check if the event is saved
KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course);
Collection<KalendarEvent> savedEvents = calendarWrapper.getKalendar().getEvents();
boolean found1 = false;
boolean found2 = false;
for (KalendarEvent savedEvent : savedEvents) {
if (subject1.equals(savedEvent.getSubject())) {
found1 = true;
} else if (subject2.equals(savedEvent.getSubject())) {
found2 = true;
}
}
Assert.assertTrue(found1);
Assert.assertTrue(found2);
conn.shutdown();
}
use of org.olat.commons.calendar.restapi.EventVO in project openolat by klemens.
the class CalendarTest method testGetEvents.
@Test
public void testGetEvents() 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").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(11 <= vos.size());
conn.shutdown();
}
use of org.olat.commons.calendar.restapi.EventVO in project openolat by klemens.
the class CalendarTest method testGetCalendarEvents_onlyFuture.
@Test
public void testGetCalendarEvents_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").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").queryParam("onlyFuture", "true").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);
assertEquals(10, events.size());
conn.shutdown();
}
Aggregations