Search in sources :

Example 1 with CourseVO

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

Example 2 with CourseVO

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);
}
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 3 with CourseVO

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

Example 4 with CourseVO

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());
}
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 5 with CourseVO

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);
    }
}
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