use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CoursesTest method testCreateEmpty_withoutAuthorCourse.
@Test
public void testCreateEmpty_withoutAuthorCourse() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").queryParam("shortTitle", "Course without author").queryParam("title", "Course without author").queryParam("setAuthor", "false").build();
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
CourseVO courseVo = conn.parse(response, CourseVO.class);
Assert.assertNotNull(courseVo);
Assert.assertEquals("Course without author", courseVo.getTitle());
// load repository entry
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(courseVo.getRepoEntryKey());
Assert.assertNotNull(re);
Assert.assertNotNull(re.getOlatResource());
Assert.assertEquals("Course without author", re.getDisplayname());
// load the course
ICourse course = CourseFactory.loadCourse(re.getOlatResource().getResourceableId());
Assert.assertNotNull(course);
Assert.assertEquals("Course without author", course.getCourseTitle());
Assert.assertEquals(re, course.getCourseEnvironment().getCourseGroupManager().getCourseEntry());
// check the list of owners
List<Identity> owners = repositoryEntryRelationDao.getMembers(re, RepositoryEntryRelationType.both, GroupRoles.owner.name());
Assert.assertNotNull(owners);
Assert.assertTrue(owners.isEmpty());
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CoursesTest method testGetCourses.
@Test
public void testGetCourses() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<CourseVO> courses = parseCourseArray(body);
assertNotNull(courses);
assertTrue(courses.size() >= 2);
boolean vo1 = false;
boolean vo2 = false;
for (CourseVO course : courses) {
Long repoEntryKey = course.getRepoEntryKey();
if (repoEntryKey != null && re1.getKey().equals(repoEntryKey)) {
vo1 = true;
Assert.assertEquals("courses1", course.getTitle());
}
if (repoEntryKey != null && re2.getKey().equals(repoEntryKey)) {
vo2 = true;
Assert.assertEquals("courses2", course.getTitle());
}
}
Assert.assertTrue(vo1);
Assert.assertTrue(vo2);
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CoursesTest method testCopyCourse.
@Test
public void testCopyCourse() throws IOException, URISyntaxException {
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("author-5");
RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
Assert.assertNotNull(entry);
conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").queryParam("shortTitle", "Course copy").queryParam("title", "Course copy").queryParam("initialAuthor", author.getKey().toString()).queryParam("copyFrom", entry.getKey().toString()).build();
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
CourseVO vo = conn.parse(response, CourseVO.class);
assertNotNull(vo);
assertNotNull(vo.getRepoEntryKey());
assertNotNull(vo.getKey());
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CoursesTest method testGetCourses_searchExternalID.
@Test
public void testGetCourses_searchExternalID() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses").queryParam("externalId", externalId).build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<CourseVO> courses = parseCourseArray(body);
assertNotNull(courses);
assertTrue(courses.size() >= 1);
CourseVO vo = null;
for (CourseVO course : courses) {
if (externalId.equals(course.getExternalId())) {
vo = course;
}
}
assertNotNull(vo);
assertEquals(vo.getKey(), course2.getResourceableId());
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CoursesTest method testGetCourses_notManaged.
@Test
public void testGetCourses_notManaged() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses").queryParam("managed", "false").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
InputStream body = response.getEntity().getContent();
List<CourseVO> courses = parseCourseArray(body);
assertNotNull(courses);
assertTrue(courses.size() >= 1);
for (CourseVO course : courses) {
boolean managed = StringHelper.containsNonWhitespace(course.getManagedFlags());
Assert.assertFalse(managed);
}
}
Aggregations