Search in sources :

Example 6 with Role

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());
}
Also used : Role(org.openmrs.Role) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with Role

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));
}
Also used : Role(org.openmrs.Role) EncounterRole(org.openmrs.EncounterRole) User(org.openmrs.User) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 8 with Role

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());
}
Also used : Role(org.openmrs.Role) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 9 with Role

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);
}
Also used : Role(org.openmrs.Role) HashSet(java.util.HashSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 10 with Role

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());
}
Also used : Role(org.openmrs.Role) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Role (org.openmrs.Role)42 Test (org.junit.Test)27 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)26 User (org.openmrs.User)15 BindException (org.springframework.validation.BindException)8 Errors (org.springframework.validation.Errors)8 Privilege (org.openmrs.Privilege)7 EncounterRole (org.openmrs.EncounterRole)6 HashSet (java.util.HashSet)5 Person (org.openmrs.Person)5 PersonName (org.openmrs.PersonName)4 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 Encounter (org.openmrs.Encounter)3 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 EncounterType (org.openmrs.EncounterType)2 RelationshipType (org.openmrs.RelationshipType)2