use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CoursesElementsTest method testUpdateRootNodeCoursePostWithFile.
@Test
public // fxdiff FXOLAT-122: course management
void testUpdateRootNodeCoursePostWithFile() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
// create an empty course
URI uri = getCoursesUri().queryParam("shortTitle", "course5").queryParam("title", "course5 long name").build();
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
CourseVO course = conn.parse(response, CourseVO.class);
assertNotNull(course);
assertNotNull(course.getKey());
assertNotNull(course.getEditorRootNodeId());
// the page
URL pageUrl = CoursesElementsTest.class.getResource("singlepage.html");
assertNotNull(pageUrl);
File page = new File(pageUrl.toURI());
// update the root node
URI rootUri = getElementsUri(course).path("structure").path(course.getEditorRootNodeId()).build();
HttpPost newStructureMethod = conn.createPost(rootUri, MediaType.APPLICATION_JSON);
HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).addBinaryBody("file", page, ContentType.APPLICATION_OCTET_STREAM, page.getName()).addTextBody("filename", page.getName()).addTextBody("parentNodeId", course.getEditorRootNodeId()).addTextBody("position", "1").addTextBody("shortTitle", "Structure-0-with-file").addTextBody("longTitle", "Structure-long-0-with-file").addTextBody("objectives", "Structure-objectives-0-with-file").addTextBody("displayType", "file").build();
newStructureMethod.setEntity(entity);
HttpResponse newStructureCode = conn.execute(newStructureMethod);
assertTrue(newStructureCode.getStatusLine().getStatusCode() == 200 || newStructureCode.getStatusLine().getStatusCode() == 201);
// check the response
CourseNodeVO structureNode = conn.parse(newStructureCode, CourseNodeVO.class);
assertNotNull(structureNode);
assertNotNull(structureNode.getId());
assertEquals(structureNode.getShortTitle(), "Structure-0-with-file");
assertEquals(structureNode.getLongTitle(), "Structure-long-0-with-file");
assertEquals(structureNode.getLearningObjectives(), "Structure-objectives-0-with-file");
assertEquals(structureNode.getId(), course.getEditorRootNodeId());
// check the real node
ICourse realCourse = CourseFactory.loadCourse(course.getKey());
CourseEditorTreeModel editorTreeModel = realCourse.getEditorTreeModel();
CourseEditorTreeNode rootNode = (CourseEditorTreeNode) editorTreeModel.getRootNode();
assertNotNull(rootNode);
assertNotNull(rootNode.getIdent());
assertNotNull(rootNode.getCourseNode());
assertEquals(rootNode.getCourseNode().getShortTitle(), "Structure-0-with-file");
assertEquals(rootNode.getCourseNode().getLongTitle(), "Structure-long-0-with-file");
assertEquals(rootNode.getCourseNode().getLearningObjectives(), "Structure-objectives-0-with-file");
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CoursesTest method testGetCourses_searchExternalRef.
@Test
public void testGetCourses_searchExternalRef() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses").queryParam("externalRef", externalRef).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 (externalRef.equals(course.getExternalRef())) {
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_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 OpenOLAT.
the class CoursesTest method testCreateEmptyCourse.
@Test
public void testCreateEmptyCourse() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").queryParam("shortTitle", "course3").queryParam("title", "course3 long name").build();
HttpPut method = conn.createPut(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
CourseVO course = conn.parse(response, CourseVO.class);
assertNotNull(course);
assertEquals("course3", course.getTitle());
// check repository entry
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(course.getRepoEntryKey());
assertNotNull(re);
assertNotNull(re.getOlatResource());
}
use of org.olat.restapi.support.vo.CourseVO in project OpenOLAT by OpenOLAT.
the class CoursesTest method testGetCourses_managed.
@Test
public void testGetCourses_managed() throws IOException, URISyntaxException {
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses").queryParam("managed", "true").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.assertTrue(managed);
}
}
Aggregations