Search in sources :

Example 26 with CourseVO

use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.

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 27 with CourseVO

use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.

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 28 with CourseVO

use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.

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 29 with CourseVO

use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.

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)

Example 30 with CourseVO

use of org.olat.restapi.support.vo.CourseVO in project openolat by klemens.

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)

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