@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 PersonService#getAllPersonAttributeTypes() */ @Test public void getAllPersonAttributeTypes_shouldReturnAllPersonAttributeTypesIncludingRetired() throws Exception { executeDataSet("org/openmrs/api/include/PersonServiceTest-createRetiredPersonAttributeType.xml"); List<PersonAttributeType> attributeTypes = Context.getPersonService().getAllPersonAttributeTypes(); assertTrue("At least one element, otherwise no checking for retired will take place", attributeTypes.size() > 0); boolean foundRetired = false; for (PersonAttributeType personAttributeType : attributeTypes) { if (personAttributeType.getRetired()) { foundRetired = true; break; } } assertTrue("There should be at least one retired person attribute type found in the list", foundRetired); }
/** * @see PersonService#getAllPersonAttributeTypes(null) */ @Test public void getAllPersonAttributeTypes_shouldReturnAllPersonAttributeTypesExcludingRetiredWhenIncludeRetiredIsFalse() throws Exception { executeDataSet("org/openmrs/api/include/PersonServiceTest-createRetiredPersonAttributeType.xml"); List<PersonAttributeType> attributeTypes = Context.getPersonService().getAllPersonAttributeTypes(false); assertTrue("At least one element, otherwise no checking for retired will take place", attributeTypes.size() > 0); boolean foundRetired = false; for (PersonAttributeType personAttributeType : attributeTypes) { if (personAttributeType.getRetired()) { foundRetired = true; break; } } Assert.assertFalse("There should be no retired person attribute type found in the list", foundRetired); }
@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#getAllPersonAttributeTypes(null) */ @Test public void getAllPersonAttributeTypes_shouldReturnAllPersonAttributeTypesIncludingRetiredWhenIncludeRetiredIsTrue() throws Exception { executeDataSet("org/openmrs/api/include/PersonServiceTest-createRetiredPersonAttributeType.xml"); //TODO: is this the correct way? or should we loop to find a retired type and then perform the following? List<PersonAttributeType> attributeTypes = Context.getPersonService().getAllPersonAttributeTypes(true); assertTrue("At least one element, otherwise no checking for retired will take place", attributeTypes.size() > 0); boolean foundRetired = false; for (PersonAttributeType personAttributeType : attributeTypes) { if (personAttributeType.getRetired()) { foundRetired = true; break; } } assertTrue("There should be at least one retired person attribute type found in the list", foundRetired); }
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("format", getObject().getFormat()); assertPropEquals("foreignKey", getObject().getForeignKey()); assertPropEquals("sortWeight", getObject().getSortWeight()); assertPropEquals("searchable", getObject().getSearchable()); assertPropEquals("editPrivilege", getObject().getEditPrivilege()); assertPropEquals("retired", getObject().getRetired()); }
@Override public void validateFullRepresentation() throws Exception { super.validateFullRepresentation(); assertPropEquals("name", getObject().getName()); assertPropEquals("description", getObject().getDescription()); assertPropEquals("format", getObject().getFormat()); assertPropEquals("foreignKey", getObject().getForeignKey()); assertPropEquals("sortWeight", getObject().getSortWeight()); assertPropEquals("searchable", getObject().getSearchable()); assertPropEquals("editPrivilege", getObject().getEditPrivilege()); assertPropEquals("retired", getObject().getRetired()); assertPropPresent("auditInfo"); }