@Override protected PersonAttributeType getExistingObject() { return personService.getPersonAttributeType(EXISTING_ID); } }
@Test public void getPersonAttributeTypes_shouldReturnUserAndPatientAttributesWhenViewTypeListiningAndPerson() { adminService.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_LISTING_ATTRIBUTES, "1"); adminService.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_USER_LISTING_ATTRIBUTES, "2"); PersonAttributeType race = personService.getPersonAttributeType(1); PersonAttributeType birthplace = personService.getPersonAttributeType(2); List<PersonAttributeType> result = personService.getPersonAttributeTypes(OpenmrsConstants.PERSON_TYPE.PERSON, PersonService.ATTR_VIEW_TYPE.LISTING); assertThat(result, contains(race, birthplace)); assertEquals(result.size(), 2); }
@Test public void getPersonAttributeTypes_shouldReturnPatientAttributesWhenGivenViewTypeListing() { adminService.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_LISTING_ATTRIBUTES, "1"); PersonAttributeType race = personService.getPersonAttributeType(1); List<PersonAttributeType> result = personService.getPersonAttributeTypes(null, PersonService.ATTR_VIEW_TYPE.LISTING); assertThat(result, contains(race)); assertEquals(result.size(), 1); }
@Override protected PersonAttributeType getObjectById(Integer id) { return Context.getPersonService().getPersonAttributeType(id); }
@Test public void getPersonAttributeTypes_shouldReturnUserAttributesWhenViewTypeHeaderAndUser() { adminService.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_HEADER_ATTRIBUTES, "1"); adminService.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_USER_HEADER_ATTRIBUTES, "2"); PersonAttributeType birthplace = personService.getPersonAttributeType(2); List<PersonAttributeType> result = personService.getPersonAttributeTypes(OpenmrsConstants.PERSON_TYPE.USER, PersonService.ATTR_VIEW_TYPE.HEADER); assertThat(result, contains(birthplace)); assertEquals(result.size(), 1); } }
@Test(expected = APIException.class) public void shouldFailToRetirePersonAttributeTypeIfGivenReasonIsEmpty() { PersonAttributeType pat = personService.getPersonAttributeType(UNRETIRED_PERSON_ATTRIBUTE_TYPE); personService.retirePersonAttributeType(pat, ""); }
@Test public void getPersonAttributeTypes_shouldReturnPatientAttributesWhenViewTypeViewingAndPatient() { adminService.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_VIEWING_ATTRIBUTES, "1"); adminService.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_USER_VIEWING_ATTRIBUTES, "2"); PersonAttributeType race = personService.getPersonAttributeType(1); List<PersonAttributeType> result = personService.getPersonAttributeTypes(OpenmrsConstants.PERSON_TYPE.PATIENT, PersonService.ATTR_VIEW_TYPE.VIEWING); assertThat(result, contains(race)); assertEquals(result.size(), 1); }
@Test(expected = APIException.class) public void shouldFailToRetirePersonAttributeTypeIfGivenReasonIsNull() { PersonAttributeType pat = personService.getPersonAttributeType(UNRETIRED_PERSON_ATTRIBUTE_TYPE); personService.retirePersonAttributeType(pat, null); }
@Test public void getPersonAttributeTypes_shouldReturnListWithNullWhenGlobalPropertyNotExists() { adminService.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_LISTING_ATTRIBUTES, "9"); assertNull(personService.getPersonAttributeType(9)); List<PersonAttributeType> result = personService.getPersonAttributeTypes(null, PersonService.ATTR_VIEW_TYPE.LISTING); // This is a bug Trunk-5149 assertEquals(result.size(), 1); assertNull(result.get(0)); }
@Test(expected = PersonAttributeTypeLockedException.class) public void shouldFailToRetirePersonAttributeTypeWhilePersonAttributeTypesAreLocked() { createPersonAttributeTypeLockedGPAndSetValue("true"); PersonAttributeType pat = personService.getPersonAttributeType(UNRETIRED_PERSON_ATTRIBUTE_TYPE); personService.retirePersonAttributeType(pat, "Retire test"); }
@Test public void getPersonAttributeTypes_shouldReturnNothingWhenGlobalPropertyLargerNineExists() { adminService.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_LISTING_ATTRIBUTES, "99"); executeDataSet(CREATE_PERSON_PROPERTY_XML); assertNotNull(personService.getPersonAttributeType(99)); List<PersonAttributeType> result = personService.getPersonAttributeTypes(null, PersonService.ATTR_VIEW_TYPE.LISTING); // This is probably a bug TRUNK-5148 assertEquals(result.size(), 1); assertNull(result.get(0)); }
/** * @see PersonService#getPersonAttributeType(Integer) */ @Test public void getPersonAttributeType_shouldReturnNullWhenNoPersonAttributeWithTheGivenIdExist() throws Exception { PersonAttributeType attributeType = Context.getPersonService().getPersonAttributeType(10000); Assert.assertNull(attributeType); }
@Test(expected = PersonAttributeTypeLockedException.class) public void unretirePersonAttributeType_shouldThrowAnErrorWhenTryingToUnretirePersonAttributeTypeWhilePersonAttributeTypesAreLocked() { createPersonAttributeTypeLockedGPAndSetValue("true"); PersonAttributeType pat = personService.getPersonAttributeType(RETIRED_PERSON_ATTRIBUTE_TYPE); personService.unretirePersonAttributeType(pat); }
/** * @see PersonService#purgePersonAttributeType(PersonAttributeType) * @throws PersonAttributeTypeLockedException */ @Test(expected = PersonAttributeTypeLockedException.class) public void purgePersonAttributeType_shouldThrowAnErrorWhileTryingToDeletePersonAttributeTypeWhenPersonAttributeTypesAreLocked() throws Exception { PersonService ps = Context.getPersonService(); createPersonAttributeTypeLockedGPAndSetValue("true"); PersonAttributeType pat = ps.getPersonAttributeType(1); ps.purgePersonAttributeType(pat); }
@Test public void shouldRetirePersonAttributeType() { PersonAttributeType pat = personService.getPersonAttributeType(UNRETIRED_PERSON_ATTRIBUTE_TYPE); assertFalse("need an unretired PersonAttributeType", pat.getRetired()); String retireReason = "reason"; personService.retirePersonAttributeType(pat, retireReason); PersonAttributeType retiredPat = personService.getPersonAttributeType(UNRETIRED_PERSON_ATTRIBUTE_TYPE); assertTrue(retiredPat.getRetired()); assertThat(retiredPat.getRetiredBy(), is(Context.getAuthenticatedUser())); assertThat(retiredPat.getRetireReason(), is(retireReason)); assertNotNull(retiredPat.getDateRetired()); }
/** * @see PersonAttribute#toString() */ @Test public void toString_shouldReturnToStringOfHydratedValue() { // type = CIVIL STATUS, concept = MARRIED PersonAttributeType type = Context.getPersonService().getPersonAttributeType(8); PersonAttribute attr = new PersonAttribute(type, "6"); Assert.assertEquals("MARRIED", attr.toString()); }
@Test public void shouldUnretirePersonAttributeType() { PersonAttributeType pat = personService.getPersonAttributeType(RETIRED_PERSON_ATTRIBUTE_TYPE); personService.unretirePersonAttributeType(pat); PersonAttributeType unretiredPat = personService.getPersonAttributeType(UNRETIRED_PERSON_ATTRIBUTE_TYPE); assertFalse(unretiredPat.getRetired()); assertNull(unretiredPat.getRetiredBy()); assertNull(unretiredPat.getRetireReason()); assertNull(unretiredPat.getDateRetired()); }
/** * @see PersonService#savePersonAttributeType(PersonAttributeType) * @throws PersonAttributeTypeLockedException */ @Test(expected = PersonAttributeTypeLockedException.class) public void savePersonAttributeType_shouldThrowAnErrorWhenTryingToSavePersonAttributeTypeWhilePersonAttributeTypesAreLocked() throws Exception { PersonService ps = Context.getPersonService(); createPersonAttributeTypeLockedGPAndSetValue("true"); PersonAttributeType pat = ps.getPersonAttributeType(1); pat.setDescription("New person attribute type"); ps.savePersonAttributeType(pat); }
/** * @see PersonService#savePersonAttributeType(PersonAttributeType) */ @Test public void savePersonAttributeType_shouldSetTheDateChangedAndChangedByOnUpdate() throws Exception { PersonService service = Context.getPersonService(); // get the type and change something about it PersonAttributeType pat = service.getPersonAttributeType(2); pat.setName("attr type name"); // save the type again service.savePersonAttributeType(pat); assertEquals(1, pat.getChangedBy().getId().intValue()); assertNotNull(pat.getDateChanged()); }
/** * @see PersonService#purgePersonAttributeType(PersonAttributeType) */ @Test public void purgePersonAttributeType_shouldDeletePersonAttributeTypeFromDatabase() throws Exception { PersonService service = Context.getPersonService(); PersonAttributeType pat = new PersonAttributeType(); pat.setName("attr type name"); pat.setDescription("attr type desc"); pat.setFormat("java.lang.String"); service.savePersonAttributeType(pat); assertNotNull(pat.getId()); service.purgePersonAttributeType(pat); PersonAttributeType deletedPersonAttributeType = service.getPersonAttributeType(pat.getId()); Assert.assertNull(deletedPersonAttributeType); }