use of org.openmrs.Privilege in project openmrs-core by openmrs.
the class PrivilegeValidatorTest method validate_shouldFailValidationIfPrivilegeIsNullOrEmptyOrWhitespace.
/**
* @see PrivilegeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfPrivilegeIsNullOrEmptyOrWhitespace() {
Privilege priv = new Privilege();
priv.setPrivilege(null);
priv.setDescription("some text");
Errors errors = new BindException(priv, "priv");
new PrivilegeValidator().validate(priv, errors);
Assert.assertTrue(errors.hasFieldErrors("privilege"));
priv.setPrivilege("");
errors = new BindException(priv, "priv");
new PrivilegeValidator().validate(priv, errors);
Assert.assertTrue(errors.hasFieldErrors("privilege"));
priv.setPrivilege(" ");
errors = new BindException(priv, "priv");
new PrivilegeValidator().validate(priv, errors);
Assert.assertTrue(errors.hasFieldErrors("privilege"));
}
use of org.openmrs.Privilege in project openmrs-core by openmrs.
the class PrivilegeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see PrivilegeValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
Privilege priv = new Privilege();
priv.setPrivilege("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
priv.setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
Errors errors = new BindException(priv, "priv");
new PrivilegeValidator().validate(priv, errors);
Assert.assertTrue(errors.hasFieldErrors("privilege"));
Assert.assertTrue(errors.hasFieldErrors("description"));
}
use of org.openmrs.Privilege in project openmrs-core by openmrs.
the class EncounterServiceTest method getEncounterWithEditPrivilege.
/**
* Gets encounter and adds edit privilege to it
*
* @return encounter with type having non null edit privilege
*/
private Encounter getEncounterWithEditPrivilege() {
// create service to be used for encounter manipulations
EncounterService encounterService = Context.getEncounterService();
Encounter encounter = encounterService.getEncounter(1);
EncounterType encounterType = encounter.getEncounterType();
// make sure that encounter type is not null
assertNotNull(encounterType);
// set view privilege on this encounter type
Privilege editPrivilege = Context.getUserService().getPrivilege("Some Privilege For Edit Encounter Types");
encounterType.setEditPrivilege(editPrivilege);
encounter.setEncounterType(encounterType);
// update encounter
encounter = encounterService.saveEncounter(encounter);
// make sure that encounter type updated successfully
assertNotNull(encounter);
return encounter;
}
use of org.openmrs.Privilege in project openmrs-core by openmrs.
the class EncounterServiceTest method getEncounterWithViewPrivilege.
/**
* Gets encounter and adds view privilege to it
*
* @return encounter with type having non null view privilege
*/
private Encounter getEncounterWithViewPrivilege() {
// create service to be used for encounter manipulations
EncounterService encounterService = Context.getEncounterService();
Encounter encounter = encounterService.getEncounter(1);
EncounterType encounterType = encounter.getEncounterType();
// make sure that encounter type is not null
assertNotNull(encounterType);
// set view privilege on this encounter type
Privilege viewPrivilege = Context.getUserService().getPrivilege("Some Privilege For View Encounter Types");
encounterType.setViewPrivilege(viewPrivilege);
encounter.setEncounterType(encounterType);
// update encounter
encounter = encounterService.saveEncounter(encounter);
// make sure that encounter was updated successfully
assertNotNull(encounter);
return encounter;
}
use of org.openmrs.Privilege in project openmrs-core by openmrs.
the class UserServiceTest method purgePrivilege_shouldDeleteGivenPrivilegeFromTheDatabase.
/**
* @see UserService#purgePrivilege(Privilege)
*/
@Test
public void purgePrivilege_shouldDeleteGivenPrivilegeFromTheDatabase() {
userService.purgePrivilege(new Privilege("Some Privilege"));
Assert.assertNull(userService.getPrivilege("Some Privilege"));
}
Aggregations