Search in sources :

Example 1 with Privilege

use of org.openmrs.Privilege in project openmrs-core by openmrs.

the class ModuleFileParserTest method parse_shouldParsePrivilegeContainingElementsOtherThanNameAndDescription.

@Test
public void parse_shouldParsePrivilegeContainingElementsOtherThanNameAndDescription() throws IOException {
    Privilege p1 = new Privilege("Manage Reports", "Add report");
    Document config = buildOnValidConfigXml().withPrivilege(p1.getName(), p1.getDescription()).build();
    config.getElementsByTagName("privilege").item(0).appendChild(config.createElement("ignoreMe"));
    ModuleFileParser parser = new ModuleFileParser(writeConfigXmlToFile(config));
    Module module = parser.parse();
    assertThat(module.getPrivileges().size(), is(1));
    assertThat(module.getPrivileges().get(0).getPrivilege(), is(p1.getPrivilege()));
    assertThat(module.getPrivileges().get(0).getDescription(), is(p1.getDescription()));
}
Also used : Privilege(org.openmrs.Privilege) Document(org.w3c.dom.Document) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 2 with Privilege

use of org.openmrs.Privilege in project openmrs-core by openmrs.

the class ModuleFileParserTest method parse_shouldParsePrivileges.

@Test
public void parse_shouldParsePrivileges() throws IOException {
    Privilege p1 = new Privilege("Manage Reports", "Add report");
    Privilege p2 = new Privilege("Manage Report Definitions", "Add report definitions");
    Document config = buildOnValidConfigXml().withPrivilege(p1.getName(), p1.getDescription()).withPrivilege(p2.getName(), p2.getDescription()).build();
    ModuleFileParser parser = new ModuleFileParser(writeConfigXmlToFile(config));
    Module module = parser.parse();
    assertThat(module.getPrivileges().size(), is(2));
    assertThat(module.getPrivileges().get(0).getPrivilege(), is(p1.getPrivilege()));
    assertThat(module.getPrivileges().get(0).getDescription(), is(p1.getDescription()));
    assertThat(module.getPrivileges().get(1).getPrivilege(), is(p2.getPrivilege()));
    assertThat(module.getPrivileges().get(1).getDescription(), is(p2.getDescription()));
}
Also used : Privilege(org.openmrs.Privilege) Document(org.w3c.dom.Document) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with Privilege

use of org.openmrs.Privilege in project openmrs-core by openmrs.

the class UserServiceTest method savePrivilege_shouldSaveGivenPrivilegeToTheDatabase.

/**
 * @see UserService#savePrivilege(Privilege)
 */
@Test
public void savePrivilege_shouldSaveGivenPrivilegeToTheDatabase() {
    Privilege p = new Privilege("new privilege name", "new privilege desc");
    userService.savePrivilege(p);
    Privilege savedPrivilege = userService.getPrivilege("new privilege name");
    Assert.assertNotNull(savedPrivilege);
}
Also used : Privilege(org.openmrs.Privilege) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with Privilege

use of org.openmrs.Privilege in project openmrs-core by openmrs.

the class UserServiceTest method getPrivilege_shouldFetchPrivilegeForGivenName.

/**
 * @see UserService#getPrivilege(String)
 */
@Test
public void getPrivilege_shouldFetchPrivilegeForGivenName() {
    executeDataSet(XML_FILENAME);
    Privilege privilege = userService.getPrivilege("Some Privilege");
    Assert.assertEquals("Some Privilege", privilege.getPrivilege());
}
Also used : Privilege(org.openmrs.Privilege) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with Privilege

use of org.openmrs.Privilege in project openmrs-core by openmrs.

the class UserServiceTest method purgePrivilege_shouldThrowErrorWhenPrivilegeIsCorePrivilege.

/**
 * @see UserService#purgePrivilege(Privilege)
 */
@Test
public void purgePrivilege_shouldThrowErrorWhenPrivilegeIsCorePrivilege() {
    expectedException.expect(APIException.class);
    userService.purgePrivilege(new Privilege(PrivilegeConstants.ADD_COHORTS));
}
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