/** * @see UserService#saveRole(Role) */ @Test public void saveRole_shouldSaveGivenRoleToTheDatabase() { Role role = new Role("new role", "new desc"); userService.saveRole(role); Assert.assertNotNull(userService.getRole("new role")); }
/** * @see UserService#saveRole(Role) */ @Test public void saveRole_shouldThrowErrorIfRoleInheritsFromItself() { Role parentRole = new Role("parent role"); // Have child inherit parent role Role childRole = new Role("child role"); Set<Role> inheritsFromParent = new HashSet<>(); inheritsFromParent.add(parentRole); childRole.setInheritedRoles(inheritsFromParent); // Now have parent try to inherit the child role. Set<Role> inheritsFromChild = new HashSet<>(); inheritsFromChild.add(childRole); parentRole.setInheritedRoles(inheritsFromChild); expectedException.expect(APIException.class); expectedException.expectMessage(messages.getMessage("Role.cannot.inherit.descendant")); userService.saveRole(parentRole); }
role.setRole(roleName); role.setDescription(entry.getValue()); Context.getUserService().saveRole(role);
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#save(java.lang.Object) */ @Override public Role save(Role delegate) { return Context.getUserService().saveRole(delegate); }
role.setDescription("boo"); role.setCreator(Context.getAuthenticatedUser()); Context.getUserService().saveRole(role); User user = Context.getUserService().getUser(userId); user.addRole(role);