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