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()));
}
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()));
}
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);
}
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());
}
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));
}
Aggregations