/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate() */ @Override public PersonAttributeType newDelegate() { return new PersonAttributeType(); }
/** * @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)); }
/** * @see PersonAttribute#getHydratedObject() */ @Test public void getHydratedObject_shouldLoadClassInFormatProperty() { PersonAttributeType type = new PersonAttributeType(); type.setFormat("org.openmrs.Concept"); PersonAttribute pa = new PersonAttribute(2); pa.setAttributeType(type); pa.setValue("5089"); Concept concept = (Concept) pa.getHydratedObject(); Assert.assertEquals(5089, concept.getConceptId().intValue()); }
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 PersonAttributeTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfNameIsNull() { PersonAttributeType type = new PersonAttributeType(); Errors errors = new BindException(type, "patObj"); new PersonAttributeTypeValidator().validate(type, errors); Assert.assertTrue(errors.hasFieldErrors("name")); }
/** * @see PersonAttribute#equalsContent(PersonAttribute) */ @Test public void equalsContent_shouldReturnTrueIfAttributeTypeValueAndVoidStatusAreTheSame() { PersonAttribute pa = new PersonAttribute(2); // a different personAttributeid than below pa.setAttributeType(new PersonAttributeType(1)); pa.setValue("1"); pa.setVoided(false); PersonAttribute other = new PersonAttribute(1); // a different personAttributeid than above pa.setAttributeType(new PersonAttributeType(1)); pa.setValue("1"); pa.setVoided(false); Assert.assertTrue(pa.equalsContent(other)); }
/** * @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 Person#addAttribute(PersonAttribute) */ @Test public void addAttribute_shouldNotSaveAnAttributeWithABlankStringValue() { Person p = new Person(); // make sure there are no initial attributes Assert.assertEquals("There should not be any attributes", 0, p.getAttributes().size()); PersonAttribute pa1 = new PersonAttribute(); pa1.setValue(""); pa1.setAttributeType(new PersonAttributeType(1)); pa1.setVoided(false); p.addAttribute(pa1); // make sure the attribute was not added Assert.assertEquals("There should not be any attributes", 0, p.getAttributes().size()); }
/** * @see Person#addAttribute(PersonAttribute) */ @Test public void addAttribute_shouldNotSaveAnAttributeWithANullValue() { Person p = new Person(); // make sure there are no initial attributes Assert.assertEquals("There should not be any attributes", 0, p.getAttributes().size()); PersonAttribute pa1 = new PersonAttribute(); pa1.setValue(null); pa1.setAttributeType(new PersonAttributeType(1)); pa1.setVoided(false); p.addAttribute(pa1); // make sure the attribute was not added Assert.assertEquals("There should not be any attributes", 0, p.getAttributes().size()); }
/** * @see PersonAttribute#getHydratedObject() */ @Test public void getHydratedObject_shouldStillLoadClassInFormatPropertyIfNotAttributable() { PersonAttributeType type = new PersonAttributeType(); type.setFormat("java.lang.String"); PersonAttribute pa = new PersonAttribute(2); pa.setAttributeType(type); pa.setValue("lalapalooza"); String value = (String) pa.getHydratedObject(); Assert.assertEquals("lalapalooza", value); }
/** * @see PersonAttribute#getHydratedObject() */ @Test public void getHydratedObject_shouldLoadUserClassInFormatProperty() { PersonAttributeType type = new PersonAttributeType(); type.setFormat("org.openmrs.User"); PersonAttribute pa = new PersonAttribute(2); pa.setAttributeType(type); pa.setValue("1"); Object value = pa.getHydratedObject(); Assert.assertTrue("should load user class in format property", (value instanceof User)); }
/** * @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_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 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()); }
PersonAttributeType attributeType = new PersonAttributeType(1); pa1.setAttributeType(attributeType); pa1.setVoided(false);
pa1.setAttributeType(new PersonAttributeType(1)); pa1.setDateCreated(new Date()); pa1.setVoided(false); pa2.setAttributeType(new PersonAttributeType(2)); pa2.setVoided(false);
/** * @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")); }