Search in sources :

Example 6 with LectureBlockVO

use of org.olat.modules.lecture.restapi.LectureBlockVO in project openolat by klemens.

the class LecturesBlocksTest method putLecturesBlock_repository.

@Test
public void putLecturesBlock_repository() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "Course with absence", "Course with absence", new CourseConfigVO());
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    dbInstance.commit();
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    String externalId = UUID.randomUUID().toString();
    LectureBlockVO lectureBlockVo = new LectureBlockVO();
    lectureBlockVo.setTitle("New block");
    lectureBlockVo.setDescription("A little description");
    lectureBlockVo.setComment("A comment");
    lectureBlockVo.setLocation("The secret location");
    lectureBlockVo.setManagedFlagsString("all");
    lectureBlockVo.setPreparation("Lot of");
    lectureBlockVo.setPlannedLectures(4);
    lectureBlockVo.setExternalId(externalId);
    lectureBlockVo.setStartDate(new Date());
    lectureBlockVo.setEndDate(new Date());
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(entry.getKey().toString()).path("lectureblocks").build();
    HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, lectureBlockVo);
    HttpResponse response = conn.execute(method);
    // check the response
    Assertions.assertThat(response.getStatusLine().getStatusCode()).isIn(200, 201);
    LectureBlockVO blockVo = conn.parse(response.getEntity().getContent(), LectureBlockVO.class);
    Assert.assertNotNull(blockVo);
    Assert.assertEquals(entry.getKey(), blockVo.getRepoEntryKey());
    Assert.assertEquals("New block", blockVo.getTitle());
    Assert.assertEquals("A little description", blockVo.getDescription());
    Assert.assertEquals("A comment", blockVo.getComment());
    Assert.assertEquals("The secret location", blockVo.getLocation());
    Assert.assertEquals("all", blockVo.getManagedFlagsString());
    Assert.assertEquals(4, blockVo.getPlannedLectures());
    Assert.assertEquals(externalId, blockVo.getExternalId());
    Assert.assertNotNull(blockVo.getStartDate());
    Assert.assertNotNull(blockVo.getEndDate());
    // check the database
    LectureBlock dbBlock = lectureService.getLectureBlock(new LectureBlockRefImpl(blockVo.getKey()));
    Assert.assertNotNull(dbBlock);
    Assert.assertEquals("New block", dbBlock.getTitle());
    Assert.assertEquals("A little description", dbBlock.getDescription());
    Assert.assertEquals("A comment", dbBlock.getComment());
    Assert.assertEquals("The secret location", dbBlock.getLocation());
    Assert.assertEquals("all", dbBlock.getManagedFlagsString());
    Assert.assertEquals(4, dbBlock.getPlannedLecturesNumber());
    Assert.assertEquals(externalId, dbBlock.getExternalId());
    Assert.assertNotNull(dbBlock.getStartDate());
    Assert.assertNotNull(dbBlock.getEndDate());
}
Also used : 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) HttpPut(org.apache.http.client.methods.HttpPut) CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRefImpl(org.olat.modules.lecture.model.LectureBlockRefImpl) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 7 with LectureBlockVO

use of org.olat.modules.lecture.restapi.LectureBlockVO in project openolat by klemens.

the class LecturesBlocksTest method getLecturesBlock_repository.

/**
 *  Get the list of lecture block through the repository entry.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void getLecturesBlock_repository() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-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();
    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").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.assertEquals(1, voList.size());
    LectureBlockVO blockVo = voList.get(0);
    Assert.assertEquals(block.getKey(), blockVo.getKey());
    Assert.assertEquals(entry.getKey(), blockVo.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 8 with LectureBlockVO

use of org.olat.modules.lecture.restapi.LectureBlockVO in project OpenOLAT by OpenOLAT.

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 9 with LectureBlockVO

use of org.olat.modules.lecture.restapi.LectureBlockVO in project OpenOLAT by OpenOLAT.

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 10 with LectureBlockVO

use of org.olat.modules.lecture.restapi.LectureBlockVO in project OpenOLAT by OpenOLAT.

the class LecturesBlocksTest method getLecturesBlock_repository.

/**
 *  Get the list of lecture block through the repository entry.
 *
 * @throws IOException
 * @throws URISyntaxException
 */
@Test
public void getLecturesBlock_repository() throws IOException, URISyntaxException {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("lect-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();
    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").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.assertEquals(1, voList.size());
    LectureBlockVO blockVo = voList.get(0);
    Assert.assertEquals(block.getKey(), blockVo.getKey());
    Assert.assertEquals(entry.getKey(), blockVo.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)

Aggregations

URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 Test (org.junit.Test)14 Identity (org.olat.core.id.Identity)14 ICourse (org.olat.course.ICourse)14 LectureBlock (org.olat.modules.lecture.LectureBlock)14 LectureBlockVO (org.olat.modules.lecture.restapi.LectureBlockVO)14 RepositoryEntry (org.olat.repository.RepositoryEntry)14 CourseConfigVO (org.olat.restapi.support.vo.CourseConfigVO)14 HttpGet (org.apache.http.client.methods.HttpGet)10 Date (java.util.Date)6 HttpPut (org.apache.http.client.methods.HttpPut)4 LectureBlockRefImpl (org.olat.modules.lecture.model.LectureBlockRefImpl)4 SimpleDateFormat (java.text.SimpleDateFormat)2