Search in sources :

Example 6 with EventVO

use of org.olat.commons.calendar.restapi.EventVO in project openolat by klemens.

the class CalendarTest method putCalendarEvents_notAuthorized.

@Test
public void putCalendarEvents_notAuthorized() 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 calendarCourse_1 = getCourseCalendar(vos, course1);
    // 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(calendarCourse_1.getId()).path("event").build();
    HttpPut putEventMethod = conn.createPut(eventUri, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(putEventMethod, event);
    HttpResponse putEventResponse = conn.execute(putEventMethod);
    assertEquals(401, putEventResponse.getStatusLine().getStatusCode());
    EntityUtils.consume(putEventResponse.getEntity());
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Calendar(java.util.Calendar) CalendarVO(org.olat.commons.calendar.restapi.CalendarVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) EventVO(org.olat.commons.calendar.restapi.EventVO) Test(org.junit.Test)

Example 7 with EventVO

use of org.olat.commons.calendar.restapi.EventVO in project openolat by klemens.

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();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) EventVO(org.olat.commons.calendar.restapi.EventVO) Test(org.junit.Test)

Example 8 with EventVO

use of org.olat.commons.calendar.restapi.EventVO in project openolat by klemens.

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()));
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) Calendar(java.util.Calendar) HttpGet(org.apache.http.client.methods.HttpGet) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) HttpResponse(org.apache.http.HttpResponse) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) URI(java.net.URI) Date(java.util.Date) EventVO(org.olat.commons.calendar.restapi.EventVO) Test(org.junit.Test)

Example 9 with EventVO

use of org.olat.commons.calendar.restapi.EventVO in project openolat by klemens.

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();
}
Also used : Calendar(java.util.Calendar) HttpResponse(org.apache.http.HttpResponse) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) Identity(org.olat.core.id.Identity) EventVO(org.olat.commons.calendar.restapi.EventVO) Test(org.junit.Test)

Example 10 with EventVO

use of org.olat.commons.calendar.restapi.EventVO in project OpenOLAT by OpenOLAT.

the class CalendarTest method putCalendarEvents_notAuthorized.

@Test
public void putCalendarEvents_notAuthorized() 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 calendarCourse_1 = getCourseCalendar(vos, course1);
    // 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(calendarCourse_1.getId()).path("event").build();
    HttpPut putEventMethod = conn.createPut(eventUri, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(putEventMethod, event);
    HttpResponse putEventResponse = conn.execute(putEventMethod);
    assertEquals(401, putEventResponse.getStatusLine().getStatusCode());
    EntityUtils.consume(putEventResponse.getEntity());
    conn.shutdown();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Calendar(java.util.Calendar) CalendarVO(org.olat.commons.calendar.restapi.CalendarVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) EventVO(org.olat.commons.calendar.restapi.EventVO) Test(org.junit.Test)

Aggregations

URI (java.net.URI)24 HttpResponse (org.apache.http.HttpResponse)24 Test (org.junit.Test)24 EventVO (org.olat.commons.calendar.restapi.EventVO)24 HttpGet (org.apache.http.client.methods.HttpGet)20 Calendar (java.util.Calendar)16 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)12 CalendarVO (org.olat.commons.calendar.restapi.CalendarVO)12 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)12 HttpPut (org.apache.http.client.methods.HttpPut)10 Date (java.util.Date)4 HttpDelete (org.apache.http.client.methods.HttpDelete)2 HttpPost (org.apache.http.client.methods.HttpPost)2 Identity (org.olat.core.id.Identity)2 ICourse (org.olat.course.ICourse)2 CourseConfigVO (org.olat.restapi.support.vo.CourseConfigVO)2