use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.
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 klemens.
the class CoursesTest method testImportCourse_owner.
@Test
public void testImportCourse_owner() throws IOException, URISyntaxException {
URL cpUrl = CoursesTest.class.getResource("Course_with_blog.zip");
File cp = new File(cpUrl.toURI());
String username = "ownerImportCourse";
Identity owner = JunitTestHelper.createAndPersistIdentityAsUser(username);
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo/courses").queryParam("ownerUsername", owner.getName()).build();
HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON);
String softKey = UUID.randomUUID().toString().replace("-", "").substring(0, 30);
HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", cp, ContentType.APPLICATION_OCTET_STREAM, cp.getName()).addTextBody("filename", "Very_small_course.zip").addTextBody("foldername", "New folder 1 2 3").addTextBody("resourcename", "Very small course").addTextBody("displayname", "Very small course").addTextBody("access", "3").addTextBody("softkey", softKey).build();
method.setEntity(entity);
HttpResponse response = conn.execute(method);
assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 201);
CourseVO vo = conn.parse(response, CourseVO.class);
Long repoKey = vo.getRepoEntryKey();
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(repoKey);
assertTrue(repositoryEntryRelationDao.hasRole(owner, re, GroupRoles.owner.name()));
}
use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.
the class CoursesTest method testGetCourses_searchExternalID_withLifecycle.
@Test
public void testGetCourses_searchExternalID_withLifecycle() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses").queryParam("externalId", externalId3).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("Course list cannot be null", courses);
assertEquals(1, courses.size());
CourseVO vo = courses.get(0);
assertNotNull("Course cannot be null", vo);
assertEquals(vo.getKey(), course3.getResourceableId());
assertNotNull("Has a lifecycle", vo.getLifecycle());
assertNotNull("Life cycle has a soft key", vo.getLifecycle().getSoftkey());
}
use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.
the class CoursesTest method testImportCourse.
@Test
public void testImportCourse() throws IOException, URISyntaxException {
URL cpUrl = CoursesTest.class.getResource("Course_with_blog.zip");
assertNotNull(cpUrl);
File cp = new File(cpUrl.toURI());
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo/courses").build();
HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON);
String softKey = UUID.randomUUID().toString().replace("-", "").substring(0, 30);
HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", cp, ContentType.APPLICATION_OCTET_STREAM, cp.getName()).addTextBody("filename", "Very_small_course.zip").addTextBody("foldername", "New folder 1 2 3").addTextBody("resourcename", "Very small course").addTextBody("displayname", "Very small course").addTextBody("access", "3").addTextBody("softkey", softKey).build();
method.setEntity(entity);
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());
Long repoKey = vo.getRepoEntryKey();
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(repoKey);
assertNotNull(re);
assertNotNull(re.getOlatResource());
assertEquals("Very small course", re.getDisplayname());
assertEquals(softKey, re.getSoftkey());
}
use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.
the class CoursePublishTest method testGetCourse.
@Test
public void testGetCourse() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
// deploy a test course
URL courseWithForumsUrl = CoursePublishTest.class.getResource("myCourseWS.zip");
Assert.assertNotNull(courseWithForumsUrl);
File courseWithForums = new File(courseWithForumsUrl.toURI());
String softKey = UUID.randomUUID().toString().replace("-", "").substring(0, 30);
RepositoryEntry re = CourseFactory.deployCourseFromZIP(courseWithForums, softKey, 4);
Assert.assertNotNull(re);
ICourse course = CourseFactory.loadCourse(re.getOlatResource().getResourceableId());
CourseNode rootNode = course.getRunStructure().getRootNode();
Assert.assertEquals(2, rootNode.getChildCount());
dbInstance.commitAndCloseSession();
// get the course
URI uri = conn.getContextURI().path("repo").path("courses").path(course.getResourceableId().toString()).build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
CourseVO courseVo = conn.parse(response, CourseVO.class);
Assert.assertNotNull(courseVo);
// update the root node
URI rootUri = getElementsUri(courseVo).path("structure").path(courseVo.getEditorRootNodeId()).build();
HttpPost updateMethod = conn.createPost(rootUri, MediaType.APPLICATION_JSON);
HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addTextBody("shortTitle", "Change it short").addTextBody("longTitle", "Change it long").build();
updateMethod.setEntity(entity);
HttpResponse updateRootResponse = conn.execute(updateMethod);
int updateRootCode = updateRootResponse.getStatusLine().getStatusCode();
assertTrue(updateRootCode == 200 || updateRootCode == 201);
EntityUtils.consume(updateRootResponse.getEntity());
// publish
URI publishUri = getCoursesUri().path(courseVo.getKey().toString()).path("publish").build();
HttpPost publishMethod = conn.createPost(publishUri, MediaType.APPLICATION_JSON);
HttpResponse publishResponse = conn.execute(publishMethod);
int publishCode = publishResponse.getStatusLine().getStatusCode();
assertTrue(publishCode == 200 || publishCode == 201);
EntityUtils.consume(publishResponse.getEntity());
// reload the course
ICourse reloadedCourse = CourseFactory.loadCourse(re.getOlatResource().getResourceableId());
CourseNode reloadRootNode = reloadedCourse.getRunStructure().getRootNode();
Assert.assertEquals(2, reloadRootNode.getChildCount());
}
Aggregations