use of org.olat.modules.lecture.restapi.LectureBlockRollCallVO in project openolat by klemens.
the class LecturesBlockRollCallTest method getRollCalls_searchParams_True.
@Test
public void getRollCalls_searchParams_True() throws IOException, URISyntaxException {
// an open lecture block
LectureBlock openLectureBlock = createMinimalLectureBlock(3);
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-2");
dbInstance.commitAndCloseSession();
// a closed lecture block
LectureBlock closedLectureBlock = createMinimalLectureBlock(3);
dbInstance.commitAndCloseSession();
closedLectureBlock.setStatus(LectureBlockStatus.done);
closedLectureBlock.setRollCallStatus(LectureRollCallStatus.closed);
lectureBlockDao.update(closedLectureBlock);
List<Integer> absences = Arrays.asList(1, 2);
LectureBlockRollCall rollCall1 = lectureBlockRollCallDao.createAndPersistRollCall(closedLectureBlock, id1, null, null, null, Collections.emptyList());
LectureBlockRollCall rollCall2 = lectureBlockRollCallDao.createAndPersistRollCall(closedLectureBlock, id2, null, null, null, absences);
LectureBlockRollCall rollCall3 = lectureBlockRollCallDao.createAndPersistRollCall(openLectureBlock, id1, null, null, null, absences);
LectureBlockRollCall rollCall4 = lectureBlockRollCallDao.createAndPersistRollCall(openLectureBlock, id2, null, null, null, Collections.emptyList());
dbInstance.commit();
rollCall2.setAbsenceSupervisorNotificationDate(new Date());
rollCall2 = lectureBlockRollCallDao.update(rollCall2);
dbInstance.commitAndCloseSession();
// REST call
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("lectures").path("rollcalls").queryParam("hasAbsences", "true").queryParam("closed", "true").queryParam("hasSupervisorNotificationDate", "true").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
List<LectureBlockRollCallVO> voList = parseLectureBlockRollCallArray(response.getEntity().getContent());
Assert.assertNotNull(voList);
// check the return values
List<Long> rollCallVoKeys = voList.stream().map(vo -> vo.getKey()).collect(Collectors.toList());
Assert.assertFalse(rollCallVoKeys.contains(rollCall1.getKey()));
Assert.assertTrue(rollCallVoKeys.contains(rollCall2.getKey()));
Assert.assertFalse(rollCallVoKeys.contains(rollCall3.getKey()));
Assert.assertFalse(rollCallVoKeys.contains(rollCall4.getKey()));
// check that roll call 2 has a date
boolean found = false;
for (LectureBlockRollCallVO vo : voList) {
if (vo.getKey().equals(rollCall2.getKey()) && vo.getAbsenceSupervisorNotificationDate() != null) {
found = true;
}
}
Assert.assertTrue(found);
}
Aggregations