Search in sources :

Example 76 with UserVO

use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.

the class RepositoryEntriesTest method addOwners.

@Test
public void addOwners() throws IOException, URISyntaxException {
    Identity owner1 = JunitTestHelper.createAndPersistIdentityAsRndUser("author-3b-");
    Identity owner2 = JunitTestHelper.createAndPersistIdentityAsRndUser("author-3c-");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    dbInstance.commitAndCloseSession();
    // add an owner
    UserVO[] newOwners = new UserVO[2];
    newOwners[0] = UserVOFactory.get(owner1);
    newOwners[1] = UserVOFactory.get(owner2);
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(re.getKey().toString()).path("owners").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, newOwners);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    conn.shutdown();
    // check
    List<Identity> owners = repositoryService.getMembers(re, GroupRoles.owner.name());
    Assert.assertNotNull(owners);
    Assert.assertEquals(2, owners.size());
    Assert.assertTrue(owners.contains(owner1));
    Assert.assertTrue(owners.contains(owner2));
}
Also used : UserVO(org.olat.user.restapi.UserVO) 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 77 with UserVO

use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.

the class RepositoryEntriesTest method addParticipants.

@Test
public void addParticipants() throws IOException, URISyntaxException {
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("participant-3b-");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("participant-3c-");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    dbInstance.commitAndCloseSession();
    // add an owner
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    // add the 2 participants to the course
    UserVO[] newParticipants = new UserVO[2];
    newParticipants[0] = UserVOFactory.get(participant1);
    newParticipants[1] = UserVOFactory.get(participant2);
    URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("participants").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, newParticipants);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    conn.shutdown();
    // check
    List<Identity> participants = repositoryService.getMembers(re, GroupRoles.participant.name());
    Assert.assertNotNull(participants);
    Assert.assertEquals(2, participants.size());
    Assert.assertTrue(participants.contains(participant1));
    Assert.assertTrue(participants.contains(participant2));
}
Also used : UserVO(org.olat.user.restapi.UserVO) 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 78 with UserVO

use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.

the class RepositoryEntriesTest method addCoaches.

@Test
public void addCoaches() throws IOException, URISyntaxException {
    Identity coach1 = JunitTestHelper.createAndPersistIdentityAsRndUser("coach-3b-");
    Identity coach2 = JunitTestHelper.createAndPersistIdentityAsRndUser("coach-3c-");
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    dbInstance.commitAndCloseSession();
    // add an owner
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    UserVO[] newCoaches = new UserVO[2];
    newCoaches[0] = UserVOFactory.get(coach1);
    newCoaches[1] = UserVOFactory.get(coach2);
    URI request = UriBuilder.fromUri(getContextURI()).path("repo").path("entries").path(re.getKey().toString()).path("coaches").build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(method, newCoaches);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    conn.shutdown();
    // check
    List<Identity> coaches = repositoryService.getMembers(re, GroupRoles.coach.name());
    Assert.assertNotNull(coaches);
    Assert.assertEquals(2, coaches.size());
    Assert.assertTrue(coaches.contains(coach1));
    Assert.assertTrue(coaches.contains(coach2));
}
Also used : UserVO(org.olat.user.restapi.UserVO) 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 79 with UserVO

use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.

the class RepositoryEntriesTest method getCoaches.

@Test
public void getCoaches() throws IOException, URISyntaxException {
    Identity coach1 = JunitTestHelper.createAndPersistIdentityAsAuthor("coach-1-" + UUID.randomUUID().toString());
    Identity coach2 = JunitTestHelper.createAndPersistIdentityAsAuthor("coach-2-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    repositoryManager.addTutors(coach1, ADMIN_ROLES, new IdentitiesAddEvent(coach1), re, new MailPackage(false));
    repositoryManager.addTutors(coach1, ADMIN_ROLES, new IdentitiesAddEvent(coach2), re, new MailPackage(false));
    dbInstance.commitAndCloseSession();
    // get the coaches
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("repo/entries").path(re.getKey().toString()).path("coaches").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    List<UserVO> users = parseUserArray(response.getEntity());
    Assert.assertNotNull(users);
    // our 2
    Assert.assertEquals(2, users.size());
    int found = 0;
    for (UserVO user : users) {
        String login = user.getLogin();
        Assert.assertNotNull(login);
        if (coach1.getName().equals(login) || coach2.getName().equals(login)) {
            found++;
        }
    }
    Assert.assertEquals(2, found);
    conn.shutdown();
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) UserVO(org.olat.user.restapi.UserVO) HttpGet(org.apache.http.client.methods.HttpGet) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) HttpResponse(org.apache.http.HttpResponse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) URI(java.net.URI) Test(org.junit.Test)

Example 80 with UserVO

use of org.olat.user.restapi.UserVO in project OpenOLAT by OpenOLAT.

the class GroupMgmtTest method testGetOwnersAdmin.

@Test
public void testGetOwnersAdmin() throws IOException, URISyntaxException {
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("/groups/" + g1.getKey() + "/owners").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<UserVO> owners = parseUserArray(body);
    assertNotNull(owners);
    assertEquals(owners.size(), 2);
    Long idKey1 = null;
    Long idKey2 = null;
    for (UserVO participant : owners) {
        if (participant.getKey().equals(owner1.getKey())) {
            idKey1 = owner1.getKey();
        } else if (participant.getKey().equals(owner2.getKey())) {
            idKey2 = owner2.getKey();
        }
    }
    assertNotNull(idKey1);
    assertNotNull(idKey2);
}
Also used : UserVO(org.olat.user.restapi.UserVO) 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

UserVO (org.olat.user.restapi.UserVO)364 Test (org.junit.Test)332 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)260 UserRestClient (org.olat.test.rest.UserRestClient)258 LoginPage (org.olat.selenium.page.LoginPage)114 NavigationPage (org.olat.selenium.page.NavigationPage)110 CoursePageFragment (org.olat.selenium.page.course.CoursePageFragment)102 QTI21Page (org.olat.selenium.page.qti.QTI21Page)96 URL (java.net.URL)90 File (java.io.File)88 CourseEditorPageFragment (org.olat.selenium.page.course.CourseEditorPageFragment)84 URI (java.net.URI)72 HttpResponse (org.apache.http.HttpResponse)72 Identity (org.olat.core.id.Identity)72 UserToolsPage (org.olat.selenium.page.user.UserToolsPage)64 WebElement (org.openqa.selenium.WebElement)48 QTI21EditorPage (org.olat.selenium.page.qti.QTI21EditorPage)46 HttpGet (org.apache.http.client.methods.HttpGet)40 MembersPage (org.olat.selenium.page.course.MembersPage)36 AuthoringEnvPage (org.olat.selenium.page.repository.AuthoringEnvPage)34