use of org.openmrs.User in project openmrs-core by openmrs.
the class EncounterServiceTest method canViewAllEncounterTypes_shouldReturnTrueWhenTheEncounterTypesViewPrivilegeColumnIsNull.
/**
* @see EncounterService#canViewAllEncounterTypes(User)
*/
@Test
public void canViewAllEncounterTypes_shouldReturnTrueWhenTheEncounterTypesViewPrivilegeColumnIsNull() {
EncounterService encounterService = Context.getEncounterService();
// set viewPrivilege on each encounter type to null
for (EncounterType encounterType : encounterService.getAllEncounterTypes()) {
encounterType.setViewPrivilege(null);
encounterService.saveEncounterType(encounterType);
}
User user = Context.getUserService().getUserByUsername("test_user");
assertNotNull(user);
assertTrue(encounterService.canViewAllEncounterTypes(user));
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounter_shouldNotOverwriteDateCreatedIfNonNull.
/**
* @see EncounterService#saveEncounter(Encounter)
*/
@Test
public void saveEncounter_shouldNotOverwriteDateCreatedIfNonNull() {
EncounterService encounterService = Context.getEncounterService();
// the encounter to save without a dateCreated
Encounter encounter = buildEncounter();
encounter.setCreator(new User(4));
// make sure we
Date date = new Date(System.currentTimeMillis() - 5000);
// have a
// date that
// isn't
// "right now"
encounter.setDateCreated(date);
encounterService.saveEncounter(encounter);
// make sure the encounter creator is user 4 not user 1
assertEquals(4, encounter.getCreator().getId().intValue());
assertNotSame(encounter.getCreator(), Context.getAuthenticatedUser());
// make sure the encounter date created wasn't overwritten
assertEquals(DateUtil.truncateToSeconds(date), encounter.getDateCreated());
// make sure we can fetch this new encounter
// from the database and its values are the same as the passed in ones
Encounter newEncounter = encounterService.getEncounter(encounter.getEncounterId());
assertNotNull(newEncounter);
assertEquals(DateUtil.truncateToSeconds(date), encounter.getDateCreated());
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class EncounterServiceTest method getEncounter_shouldFailIfUserIsNotAllowedToViewEncounterByGivenId.
/**
* @see EncounterService#getEncounter(Integer)
*/
@Test(expected = APIException.class)
public void getEncounter_shouldFailIfUserIsNotAllowedToViewEncounterByGivenId() {
// get encounter that has type with view privilege set
Encounter encounter = getEncounterWithViewPrivilege();
User user = Context.getUserService().getUserByUsername("test_user");
assertNotNull(user);
// left this user as is - i.e. without required privilege
// and authenticate under it's account
Context.becomeUser(user.getSystemId());
// have to add privilege in order to be able to call getEncounter(Integer) method
Context.addProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS);
assertNull(Context.getEncounterService().getEncounter(encounter.getId()));
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class EncounterServiceTest method purgeEncounter_shouldFailfIfUserIsNotSupposedToEditEncountersOfTypeOfGivenEncounter.
/**
* @see EncounterService#purgeEncounter(Encounter)
*/
@Test(expected = APIException.class)
public void purgeEncounter_shouldFailfIfUserIsNotSupposedToEditEncountersOfTypeOfGivenEncounter() {
// get encounter that has type with edit privilege set
Encounter encounter = getEncounterWithEditPrivilege();
User user = Context.getUserService().getUserByUsername("test_user");
assertNotNull(user);
// left this user as is - i.e. without required privilege
// and authenticate under it's account
Context.becomeUser(user.getSystemId());
// have to add privilege in order to be able to call purgeEncounter(Encounter) method
Context.addProxyPrivilege(PrivilegeConstants.PURGE_ENCOUNTERS);
Context.getEncounterService().purgeEncounter(encounter);
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounterType_shouldNotOverwriteCreatorOrDateCreated.
/**
* @see EncounterService#saveEncounterType(EncounterType)
*/
@Test
public void saveEncounterType_shouldNotOverwriteCreatorOrDateCreated() {
EncounterService encounterService = Context.getEncounterService();
// the encounter to save without a dateCreated
EncounterType encounterType = new EncounterType("testing", "desc");
encounterType.setCreator(new User(4));
// make sure we have a date that isn't "right now"
Date date = new Date(System.currentTimeMillis() - 5000);
encounterType.setDateCreated(date);
// make sure the logged in user isn't the user we're testing with
assertNotSame(encounterType.getCreator(), Context.getAuthenticatedUser());
encounterService.saveEncounterType(encounterType);
// make sure the encounter type creator is user 4 not user 1
assertNotSame(encounterType.getCreator().getId(), Context.getAuthenticatedUser().getId());
// make sure the encounter type date created wasn't overwritten
assertEquals(DateUtil.truncateToSeconds(date), encounterType.getDateCreated());
// make sure we can fetch this new encounter type
// from the database and its values are the same as the passed in ones
EncounterType newEncounterType = encounterService.getEncounterType(encounterType.getEncounterTypeId());
assertNotNull(newEncounterType);
assertEquals(4, encounterType.getCreator().getId().intValue());
assertNotSame(encounterType.getCreator(), Context.getAuthenticatedUser());
assertEquals(DateUtil.truncateToSeconds(date), encounterType.getDateCreated());
}
Aggregations