Search in sources :

Example 46 with CourseVO

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");
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) HttpPost(org.apache.http.client.methods.HttpPost) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) HttpEntity(org.apache.http.HttpEntity) CourseNodeVO(org.olat.restapi.support.vo.CourseNodeVO) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) HttpResponse(org.apache.http.HttpResponse) ICourse(org.olat.course.ICourse) URI(java.net.URI) File(java.io.File) HttpPut(org.apache.http.client.methods.HttpPut) URL(java.net.URL) Test(org.junit.Test)

Example 47 with CourseVO

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());
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 48 with CourseVO

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());
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 49 with CourseVO

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());
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) Test(org.junit.Test)

Example 50 with CourseVO

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);
    }
}
Also used : CourseVO(org.olat.restapi.support.vo.CourseVO) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Aggregations

CourseVO (org.olat.restapi.support.vo.CourseVO)70 Test (org.junit.Test)48 URI (java.net.URI)46 HttpResponse (org.apache.http.HttpResponse)46 RepositoryEntry (org.olat.repository.RepositoryEntry)34 HttpGet (org.apache.http.client.methods.HttpGet)26 ICourse (org.olat.course.ICourse)26 Identity (org.olat.core.id.Identity)20 InputStream (java.io.InputStream)18 Produces (javax.ws.rs.Produces)16 HttpEntity (org.apache.http.HttpEntity)16 HttpPut (org.apache.http.client.methods.HttpPut)16 File (java.io.File)14 HttpPost (org.apache.http.client.methods.HttpPost)14 CourseVOes (org.olat.restapi.support.vo.CourseVOes)14 URL (java.net.URL)12 GET (javax.ws.rs.GET)8 Path (javax.ws.rs.Path)8 UserRequest (org.olat.core.gui.UserRequest)8 RepositoryManager (org.olat.repository.RepositoryManager)8