Search in sources :

Example 1 with EventVOes

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

the class CalendarTest method testGetEvents_paging.

@Test
public void testGetEvents_paging() 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("start", "0").queryParam("limit", "5").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    EventVOes voes = conn.parse(response, EventVOes.class);
    assertNotNull(voes);
    assertTrue(10 <= voes.getTotalCount());
    assertNotNull(voes.getEvents());
    assertEquals(5, voes.getEvents().length);
    // check reliability of api
    URI uriOverflow = UriBuilder.fromUri(getContextURI()).path("users").path(id1.getKey().toString()).path("calendars").path("events").queryParam("start", voes.getTotalCount()).queryParam("limit", "5").build();
    HttpGet methodOverflow = conn.createGet(uriOverflow, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse responseOverflow = conn.execute(methodOverflow);
    assertEquals(200, responseOverflow.getStatusLine().getStatusCode());
    EventVOes voesOverflow = conn.parse(responseOverflow, EventVOes.class);
    assertNotNull(voesOverflow);
    assertNotNull(voesOverflow.getEvents());
    assertEquals(0, voesOverflow.getEvents().length);
    conn.shutdown();
}
Also used : EventVOes(org.olat.commons.calendar.restapi.EventVOes) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 2 with EventVOes

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

the class CalendarTest method testGetCalendarEvents_paging.

@Test
public void testGetCalendarEvents_paging() 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("start", "0").queryParam("limit", "5").queryParam("onlyFuture", "true").build();
    HttpGet eventMethod = conn.createGet(eventUri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse eventResponse = conn.execute(eventMethod);
    assertEquals(200, eventResponse.getStatusLine().getStatusCode());
    EventVOes events = conn.parse(eventResponse, EventVOes.class);
    assertNotNull(events);
    assertEquals(10, events.getTotalCount());
    assertNotNull(events.getEvents());
    assertEquals(5, events.getEvents().length);
    conn.shutdown();
}
Also used : EventVOes(org.olat.commons.calendar.restapi.EventVOes) HttpGet(org.apache.http.client.methods.HttpGet) CalendarVO(org.olat.commons.calendar.restapi.CalendarVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 3 with EventVOes

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

the class CalendarTest method testGetCalendarEvents_paging.

@Test
public void testGetCalendarEvents_paging() 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("start", "0").queryParam("limit", "5").queryParam("onlyFuture", "true").build();
    HttpGet eventMethod = conn.createGet(eventUri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse eventResponse = conn.execute(eventMethod);
    assertEquals(200, eventResponse.getStatusLine().getStatusCode());
    EventVOes events = conn.parse(eventResponse, EventVOes.class);
    assertNotNull(events);
    assertEquals(10, events.getTotalCount());
    assertNotNull(events.getEvents());
    assertEquals(5, events.getEvents().length);
    conn.shutdown();
}
Also used : EventVOes(org.olat.commons.calendar.restapi.EventVOes) HttpGet(org.apache.http.client.methods.HttpGet) CalendarVO(org.olat.commons.calendar.restapi.CalendarVO) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 4 with EventVOes

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

the class CalendarTest method testGetEvents_paging.

@Test
public void testGetEvents_paging() 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("start", "0").queryParam("limit", "5").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    EventVOes voes = conn.parse(response, EventVOes.class);
    assertNotNull(voes);
    assertTrue(10 <= voes.getTotalCount());
    assertNotNull(voes.getEvents());
    assertEquals(5, voes.getEvents().length);
    // check reliability of api
    URI uriOverflow = UriBuilder.fromUri(getContextURI()).path("users").path(id1.getKey().toString()).path("calendars").path("events").queryParam("start", voes.getTotalCount()).queryParam("limit", "5").build();
    HttpGet methodOverflow = conn.createGet(uriOverflow, MediaType.APPLICATION_JSON + ";pagingspec=1.0", true);
    HttpResponse responseOverflow = conn.execute(methodOverflow);
    assertEquals(200, responseOverflow.getStatusLine().getStatusCode());
    EventVOes voesOverflow = conn.parse(responseOverflow, EventVOes.class);
    assertNotNull(voesOverflow);
    assertNotNull(voesOverflow.getEvents());
    assertEquals(0, voesOverflow.getEvents().length);
    conn.shutdown();
}
Also used : EventVOes(org.olat.commons.calendar.restapi.EventVOes) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Aggregations

URI (java.net.URI)4 HttpResponse (org.apache.http.HttpResponse)4 HttpGet (org.apache.http.client.methods.HttpGet)4 Test (org.junit.Test)4 EventVOes (org.olat.commons.calendar.restapi.EventVOes)4 CalendarVO (org.olat.commons.calendar.restapi.CalendarVO)2