use of org.openmrs.Privilege in project openmrs-core by openmrs.
the class EncounterServiceTest method canEditAllEncounterTypes_shouldReturnTrueIfUserIsGrantedToEditEncounters.
/**
* @see EncounterService#canEditAllEncounterTypes(User)
*/
@Test
public void canEditAllEncounterTypes_shouldReturnTrueIfUserIsGrantedToEditEncounters() {
EncounterService encounterService = Context.getEncounterService();
EncounterType encounterType = new EncounterType("testing", "desc");
Privilege editPrivilege = Context.getUserService().getPrivilege("Some Privilege For Edit Encounter Types");
encounterType.setEditPrivilege(editPrivilege);
encounterService.saveEncounterType(encounterType);
User user = Context.getUserService().getUserByUsername("test_user");
assertNotNull(user);
assertFalse(encounterService.canEditAllEncounterTypes(user));
Role role = Context.getUserService().getRole("Provider");
role.addPrivilege(editPrivilege);
user.addRole(role);
assertTrue(encounterService.canEditAllEncounterTypes(user));
}
use of org.openmrs.Privilege in project openmrs-core by openmrs.
the class EncounterServiceTest method canViewAllEncounterTypes_shouldReturnTrueIfUserIsGrantedToViewEncounters.
/**
* @see EncounterService#canViewAllEncounterTypes(User)
*/
@Test
public void canViewAllEncounterTypes_shouldReturnTrueIfUserIsGrantedToViewEncounters() {
EncounterService encounterService = Context.getEncounterService();
EncounterType encounterType = new EncounterType("testing", "desc");
Privilege viewPrivilege = Context.getUserService().getPrivilege("Some Privilege For View Encounter Types");
encounterType.setViewPrivilege(viewPrivilege);
encounterService.saveEncounterType(encounterType);
User user = Context.getUserService().getUserByUsername("test_user");
assertNotNull(user);
assertFalse(encounterService.canViewAllEncounterTypes(user));
Role role = Context.getUserService().getRole("Provider");
role.addPrivilege(viewPrivilege);
user.addRole(role);
assertTrue(encounterService.canViewAllEncounterTypes(user));
}
use of org.openmrs.Privilege in project openmrs-core by openmrs.
the class PrivilegeEditor method setAsText.
/**
* @should set using name
* @should set using uuid
*/
@Override
public void setAsText(String text) throws IllegalArgumentException {
UserService es = Context.getUserService();
if (StringUtils.hasText(text)) {
try {
Privilege p = es.getPrivilege(text);
setValue(p);
// when a privilege is not found, no exception is generated. throw one to execute the catch block
if (p == null) {
throw new Exception();
}
} catch (Exception ex) {
Privilege p = es.getPrivilegeByUuid(text);
setValue(p);
if (p == null) {
log.error("Error setting text: " + text, ex);
throw new IllegalArgumentException("Privilege not found: " + ex.getMessage());
}
}
} else {
setValue(null);
}
}
use of org.openmrs.Privilege in project openmrs-core by openmrs.
the class PrivilegeValidatorTest method validate_shouldPassValidationIfDescriptionIsNullOrEmptyOrWhitespace.
/**
* @see PrivilegeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfDescriptionIsNullOrEmptyOrWhitespace() {
Privilege priv = new Privilege();
priv.setPrivilege("Wallhacking");
priv.setDescription(null);
Errors errors = new BindException(priv, "priv");
new PrivilegeValidator().validate(priv, errors);
Assert.assertFalse(errors.hasFieldErrors("description"));
priv.setDescription("");
errors = new BindException(priv, "priv");
new PrivilegeValidator().validate(priv, errors);
Assert.assertFalse(errors.hasFieldErrors("description"));
priv.setDescription(" ");
errors = new BindException(priv, "priv");
new PrivilegeValidator().validate(priv, errors);
Assert.assertFalse(errors.hasFieldErrors("description"));
}
use of org.openmrs.Privilege in project openmrs-core by openmrs.
the class PrivilegeValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.
/**
* @see PrivilegeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
Privilege priv = new Privilege();
priv.setPrivilege("Wallhacking");
priv.setDescription("idspispopd");
Errors errors = new BindException(priv, "priv");
new PrivilegeValidator().validate(priv, errors);
Assert.assertFalse(errors.hasErrors());
Assert.assertNotNull(priv.getName());
Assert.assertEquals(priv.getPrivilege(), "Wallhacking");
}
Aggregations