Search in sources :

Example 6 with Privilege

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

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

Example 8 with Privilege

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;
}
Also used : Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) Privilege(org.openmrs.Privilege)

Example 9 with Privilege

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;
}
Also used : Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) Privilege(org.openmrs.Privilege)

Example 10 with Privilege

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

Aggregations

Privilege (org.openmrs.Privilege)25 Test (org.junit.Test)15 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)15 Role (org.openmrs.Role)6 BindException (org.springframework.validation.BindException)5 Errors (org.springframework.validation.Errors)5 EncounterType (org.openmrs.EncounterType)4 User (org.openmrs.User)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Encounter (org.openmrs.Encounter)2 EncounterRole (org.openmrs.EncounterRole)2 APIException (org.openmrs.api.APIException)2 UserService (org.openmrs.api.UserService)2 Document (org.w3c.dom.Document)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Before (org.junit.Before)1 GlobalProperty (org.openmrs.GlobalProperty)1 AdministrationService (org.openmrs.api.AdministrationService)1