use of org.olat.restapi.support.vo.CourseConfigVO in project openolat by klemens.
the class CourseCalendarTest method setUp.
/**
* SetUp is called before each test.
*/
@Before
public void setUp() throws Exception {
super.setUp();
try {
// create course and persist as OLATResourceImpl
auth1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-course-cal-one");
CourseConfigVO config = new CourseConfigVO();
config.setCalendar(Boolean.TRUE);
course1 = CoursesWebService.createEmptyCourse(auth1, "course calendar", "course with calendar for REST API testing", config);
dbInstance.commit();
ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
Assert.assertTrue(course.getCourseConfig().isCalendarEnabled());
CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
KalendarRenderWrapper calendarWrapper = calManager.getCourseCalendar(course);
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 2; i++) {
Date begin = cal.getTime();
cal.add(Calendar.HOUR_OF_DAY, 1);
Date end = cal.getTime();
String eventId = UUID.randomUUID().toString();
KalendarEvent event = new KalendarEvent(eventId, null, "Unit test " + i, begin, end);
calManager.addEventTo(calendarWrapper.getKalendar(), event);
cal.add(Calendar.DATE, 1);
}
} catch (Exception e) {
log.error("Exception in setUp(): " + e);
}
}
use of org.olat.restapi.support.vo.CourseConfigVO in project openolat by klemens.
the class LecturesBlocksRootTest method getLecturesBlock_date.
@Test
public void getLecturesBlock_date() throws IOException, URISyntaxException {
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-root-1");
ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence", "Course with absence", new CourseConfigVO());
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
LectureBlock block = createLectureBlock(entry);
dbInstance.commit();
lectureService.addTeacher(block, author);
dbInstance.commit();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
String date = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss").format(new Date());
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("lectures").queryParam("date", date).build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
List<LectureBlockVO> voList = parseLectureBlockArray(response.getEntity().getContent());
Assert.assertNotNull(voList);
Assert.assertFalse(voList.isEmpty());
LectureBlockVO lectureBlockVo = null;
for (LectureBlockVO vo : voList) {
if (vo.getKey().equals(block.getKey())) {
lectureBlockVo = vo;
}
}
Assert.assertNotNull(lectureBlockVo);
Assert.assertEquals(block.getKey(), lectureBlockVo.getKey());
Assert.assertEquals(entry.getKey(), lectureBlockVo.getRepoEntryKey());
}
use of org.olat.restapi.support.vo.CourseConfigVO in project openolat by klemens.
the class LecturesBlocksRootTest method getLecturesBlock.
@Test
public void getLecturesBlock() throws IOException, URISyntaxException {
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-root-all");
ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence", "Course with absence", new CourseConfigVO());
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
LectureBlock block = createLectureBlock(entry);
dbInstance.commit();
lectureService.addTeacher(block, author);
dbInstance.commit();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("lectures").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
List<LectureBlockVO> voList = parseLectureBlockArray(response.getEntity().getContent());
Assert.assertNotNull(voList);
Assert.assertFalse(voList.isEmpty());
LectureBlockVO lectureBlockVo = null;
for (LectureBlockVO vo : voList) {
if (vo.getKey().equals(block.getKey())) {
lectureBlockVo = vo;
}
}
Assert.assertNotNull(lectureBlockVo);
Assert.assertEquals(block.getKey(), lectureBlockVo.getKey());
Assert.assertEquals(entry.getKey(), lectureBlockVo.getRepoEntryKey());
}
use of org.olat.restapi.support.vo.CourseConfigVO in project openolat by klemens.
the class LecturesBlocksTest method removeTeacherToLectureBlock.
@Test
public void removeTeacherToLectureBlock() throws IOException, URISyntaxException {
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
Identity teacher1 = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-2");
Identity teacher2 = JunitTestHelper.createAndPersistIdentityAsRndUser("teacher-3");
ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence config", "Course with absence configuration", new CourseConfigVO());
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
LectureBlock block = createLectureBlock(entry);
dbInstance.commit();
lectureService.addTeacher(block, teacher1);
lectureService.addTeacher(block, teacher2);
dbInstance.commit();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(entry.getKey().toString()).path("lectureblocks").path(block.getKey().toString()).path("teachers").path(teacher1.getKey().toString()).build();
HttpDelete method = conn.createDelete(uri, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
// check the response
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
// check the database
List<Identity> teachers = lectureService.getTeachers(block);
Assert.assertEquals(1, teachers.size());
Assert.assertFalse(teachers.contains(teacher1));
Assert.assertTrue(teachers.contains(teacher2));
}
use of org.olat.restapi.support.vo.CourseConfigVO in project openolat by klemens.
the class LecturesBlocksTest method getLecturesBlockConfiguration.
@Test
public void getLecturesBlockConfiguration() throws IOException, URISyntaxException {
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence config", "Course with absence configuration", new CourseConfigVO());
RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
dbInstance.commit();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(entry.getKey().toString()).path("lectureblocks").path("configuration").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
RepositoryEntryLectureConfigurationVO configVo = conn.parse(response, RepositoryEntryLectureConfigurationVO.class);
Assert.assertNotNull(configVo);
}
Aggregations