/** * @see Person#getAttribute(PersonAttributeType) */ @Test public void getAttribute_shouldReturnNullWhenExistingPersonAttributeTypeIsVoided() { Person person = personHelper(true, 1, 2, 3, "name1", "name2", "name3", "value1", "value2", "value3"); PersonAttributeType type = new PersonAttributeType(3); type.setName("name3"); Assert.assertNull(person.getAttribute(type)); }
private Person personHelper(boolean isVoid, int attributeType1, int attributeType2, int attributeType3, String attributeName1, String attributeName2, String attributeName3, String attributeValue1, String attributeValue2, String attributeValue3) { Person person = new Person(); PersonAttributeType type1 = new PersonAttributeType(attributeType1); PersonAttributeType type2 = new PersonAttributeType(attributeType2); PersonAttributeType type3 = new PersonAttributeType(attributeType3); type1.setName(attributeName1); type2.setName(attributeName2); type3.setName(attributeName3); PersonAttribute personAttribute1 = new PersonAttribute(type1, attributeValue1); PersonAttribute personAttribute2 = new PersonAttribute(type2, attributeValue2); PersonAttribute personAttribute3 = new PersonAttribute(type3, attributeValue3); personAttribute1.setVoided(isVoid); personAttribute2.setVoided(isVoid); personAttribute3.setVoided(isVoid); person.addAttribute(personAttribute1); person.addAttribute(personAttribute2); person.addAttribute(personAttribute3); return person; }
/** * @see PersonDAO#getSavedPersonAttributeTypeName(org.openmrs.PersonAttributeType) */ @Test public void getSavedPersonAttributeTypeName_shouldGetSavedPersonAttributeTypeNameFromDatabase() { PersonAttributeType pat = Context.getPersonService().getPersonAttributeType(1); // save the name from the db for later checks String origName = pat.getName(); String newName = "Race Updated"; assertFalse(newName.equals(origName)); // change the name on the java pojo (NOT in the database) pat.setName(newName); // the value from the database should match the original name from the // pat right after /it/ was fetched from the database String nameFromDatabase = dao.getSavedPersonAttributeTypeName(pat); assertEquals(origName, nameFromDatabase); }
/** * @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 PersonAttributeTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfNameAlreadyInUse() { PersonAttributeType type = new PersonAttributeType(); type.setName("Birthplace"); Errors errors = new BindException(type, "patObj"); new PersonAttributeTypeValidator().validate(type, errors); Assert.assertTrue(errors.hasFieldErrors("name")); }
/** * @see PersonService#savePersonAttributeType(PersonAttributeType) */ @Test public void savePersonAttributeType_shouldSetTheDateCreatedAndCreatorOnNew() 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); assertEquals(1, pat.getCreator().getId().intValue()); assertNotNull(pat.getDateCreated()); }
/** * @see PersonAttributeTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfFormatIsEmpty() { PersonAttributeType type = new PersonAttributeType(); type.setName("Zodiac"); type.setDescription("Zodiac Description"); type.setFormat(""); Errors errors = new BindException(type, "patObj"); new PersonAttributeTypeValidator().validate(type, errors); Assert.assertTrue(errors.hasFieldErrors("format")); }
/** * @see PersonAttributeTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { PersonAttributeType type = new PersonAttributeType(); type.setName("name"); type.setFormat("java.lang.String"); type.setRetireReason("retireReason"); Errors errors = new BindException(type, "patObj"); new PersonAttributeTypeValidator().validate(type, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see PersonAttributeTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfAllFieldsAreCorreect() { PersonAttributeType type = new PersonAttributeType(); type.setName("Zodiac"); type.setFormat("java.lang.String"); type.setDescription("Zodiac Description"); Errors errors = new BindException(type, "patObj"); new PersonAttributeTypeValidator().validate(type, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @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); }
/** * @see PersonAttributeTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { PersonAttributeType type = new PersonAttributeType(); type .setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); type .setFormat("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); type .setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); Errors errors = new BindException(type, "patObj"); new PersonAttributeTypeValidator().validate(type, errors); Assert.assertTrue(errors.hasFieldErrors("name")); Assert.assertTrue(errors.hasFieldErrors("format")); Assert.assertTrue(errors.hasFieldErrors("retireReason")); } }
/** * @see PersonAttributeTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfDescriptionIsNullOrEmptyOrWhitespace() { PersonAttributeType type = new PersonAttributeType(); type.setName("name"); type.setDescription(null); Errors errors = new BindException(type, "type"); new PersonAttributeTypeValidator().validate(type, errors); Assert.assertFalse(errors.hasFieldErrors("description")); type.setDescription(""); errors = new BindException(type, "type"); new PersonAttributeTypeValidator().validate(type, errors); Assert.assertFalse(errors.hasFieldErrors("description")); type.setDescription(" "); errors = new BindException(type, "type"); new PersonAttributeTypeValidator().validate(type, errors); Assert.assertFalse(errors.hasFieldErrors("description")); }
assertEquals("Birthpalce", patientViewing); pat.setName("Race Updated"); pat = service.savePersonAttributeType(pat); assertEquals("Race Updated", pat.getName());
@Test public void setValue_shouldSetPassedValueIfCouldNotBeConvertedToAttributable() throws ClassNotFoundException { PersonAttributeType type = new PersonAttributeType(); type.setFormat("org.openmrs.Location"); type.setName("Second Home"); type.setDescription("Testing Attributable domain objects"); type.setSortWeight(5.5); type.setSearchable(false); type = personService.savePersonAttributeType(type); String nonExistenceLocationUuid = "this-uuid-does-not-exist-of-course"; PersonAttribute attribute = new PersonAttribute(type, null); Assert.assertNull(attribute.getValue()); Assert.assertTrue(Attributable.class.isAssignableFrom(Context.loadClass(type.getFormat()))); resource.setValue(attribute, nonExistenceLocationUuid); Assert.assertEquals(nonExistenceLocationUuid, attribute.getValue()); }
@Test public void setValue_shouldSetProperAttributableIdIfFound() { PersonAttributeType type = new PersonAttributeType(); type.setFormat("org.openmrs.Location"); type.setName("Second Home"); type.setDescription("Testing Attributable domain objects"); type.setSortWeight(5.5); type.setSearchable(false); type = personService.savePersonAttributeType(type); //Get the first location in from the list Location location = locationService.getAllLocations().get(0); PersonAttribute attribute = new PersonAttribute(type, null); attribute.setAttributeType(type); Assert.assertNull(attribute.getValue()); resource.setValue(attribute, location.getUuid()); Assert.assertEquals(location.getUuid(), attribute.getValue()); }