use of org.olat.user.restapi.RolesVO in project openolat by klemens.
the class UserMgmtTest method testUpdateRoles.
@Test
public void testUpdateRoles() throws IOException, URISyntaxException {
// create an author
Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("author-" + UUID.randomUUID().toString());
dbInstance.commitAndCloseSession();
RestConnection conn = new RestConnection();
assertTrue(conn.login("administrator", "openolat"));
RolesVO roles = new RolesVO();
roles.setAuthor(true);
roles.setUserManager(true);
// get roles of author
URI request = UriBuilder.fromUri(getContextURI()).path("/users/" + author.getKey() + "/roles").build();
HttpPost method = conn.createPost(request, MediaType.APPLICATION_JSON);
conn.addJsonEntity(method, roles);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
RolesVO modRoles = conn.parse(response, RolesVO.class);
Assert.assertNotNull(modRoles);
// check the roles
Roles reloadRoles = securityManager.getRoles(author);
Assert.assertTrue(reloadRoles.isAuthor());
Assert.assertFalse(reloadRoles.isGroupManager());
Assert.assertFalse(reloadRoles.isGuestOnly());
Assert.assertFalse(reloadRoles.isInstitutionalResourceManager());
Assert.assertFalse(reloadRoles.isInvitee());
Assert.assertFalse(reloadRoles.isOLATAdmin());
Assert.assertFalse(reloadRoles.isPoolAdmin());
Assert.assertTrue(reloadRoles.isUserManager());
conn.shutdown();
}
Aggregations