use of org.openmrs.Role in project openmrs-core by openmrs.
the class RoleValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see RoleValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
Role role = new Role();
role.setRole("Bowling race car driver");
role.setDescription("description");
Errors errors = new BindException(role, "type");
new RoleValidator().validate(role, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.Role in project openmrs-core by openmrs.
the class EncounterServiceTest method canViewEncounter_shouldReturnTrueIfUserCanViewEncounter.
/**
* @see EncounterService#canViewEncounter(Encounter, User)
*/
@Test
public void canViewEncounter_shouldReturnTrueIfUserCanViewEncounter() {
// get encounter that has type with view privilege set
Encounter encounter = getEncounterWithViewPrivilege();
User user = Context.getUserService().getUserByUsername("test_user");
assertNotNull(user);
// add required privilege to role in which this user is
Role role = Context.getUserService().getRole("Provider");
role.addPrivilege(encounter.getEncounterType().getViewPrivilege());
user.addRole(role);
assertTrue(Context.getEncounterService().canViewEncounter(encounter, user));
}
use of org.openmrs.Role in project openmrs-core by openmrs.
the class UserServiceTest method getRole_shouldFetchRoleForGivenRoleName.
/**
* @see UserService#getRole(String)
*/
@Test
public void getRole_shouldFetchRoleForGivenRoleName() {
executeDataSet(XML_FILENAME);
Role role = userService.getRole("Some Role");
Assert.assertEquals("Some Role", role.getRole());
}
use of org.openmrs.Role in project openmrs-core by openmrs.
the class UserServiceTest method purgeRole_shouldThrowErrorWhenRoleHasChildRoles.
/**
* @see UserService#purgeUser(User)
*/
@Test
public void purgeRole_shouldThrowErrorWhenRoleHasChildRoles() {
Set<Role> childRole = new HashSet<>();
Role role1 = new Role("role_parent");
Role role2 = new Role("role_child");
childRole.add(role1);
role2.setChildRoles(childRole);
expectedException.expect(CannotDeleteRoleWithChildrenException.class);
userService.purgeRole(role2);
}
use of org.openmrs.Role in project openmrs-core by openmrs.
the class UserServiceTest method getUsersByRole_shouldNotFetchUserThatDoesNotBelongToGivenRole.
/**
* @see UserService#getUsersByRole(Role)
*/
@Test
public void getUsersByRole_shouldNotFetchUserThatDoesNotBelongToGivenRole() {
executeDataSet(XML_FILENAME);
Assert.assertEquals(0, userService.getUsersByRole(new Role("Nonexistent role")).size());
}
Aggregations