Search in sources :

Example 36 with CourseConfigVO

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);
    }
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) CalendarManager(org.olat.commons.calendar.CalendarManager) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Before(org.junit.Before)

Example 37 with CourseConfigVO

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());
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) LectureBlockVO(org.olat.modules.lecture.restapi.LectureBlockVO) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) URI(java.net.URI) Date(java.util.Date) CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) Identity(org.olat.core.id.Identity) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 38 with CourseConfigVO

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());
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) HttpGet(org.apache.http.client.methods.HttpGet) LectureBlockVO(org.olat.modules.lecture.restapi.LectureBlockVO) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 39 with CourseConfigVO

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));
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 40 with CourseConfigVO

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);
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) RepositoryEntryLectureConfigurationVO(org.olat.modules.lecture.restapi.RepositoryEntryLectureConfigurationVO) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Aggregations

CourseConfigVO (org.olat.restapi.support.vo.CourseConfigVO)44 ICourse (org.olat.course.ICourse)40 URI (java.net.URI)32 HttpResponse (org.apache.http.HttpResponse)32 Test (org.junit.Test)32 Identity (org.olat.core.id.Identity)32 RepositoryEntry (org.olat.repository.RepositoryEntry)30 LectureBlock (org.olat.modules.lecture.LectureBlock)24 HttpGet (org.apache.http.client.methods.HttpGet)14 LectureBlockVO (org.olat.modules.lecture.restapi.LectureBlockVO)14 Date (java.util.Date)10 HttpPut (org.apache.http.client.methods.HttpPut)10 Calendar (java.util.Calendar)6 Produces (javax.ws.rs.Produces)6 HttpDelete (org.apache.http.client.methods.HttpDelete)6 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)6 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)6 CourseConfig (org.olat.course.config.CourseConfig)6 Consumes (javax.ws.rs.Consumes)4 PUT (javax.ws.rs.PUT)4