use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class ProviderValidatorTest method validate_shouldBeValidIfIdentifierIsNotSet.
/**
* @see ProviderValidator#validate(Object, Errors)
*/
@Test
public void validate_shouldBeValidIfIdentifierIsNotSet() {
// given
provider.setIdentifier(null);
Person person = new Person();
Set<PersonName> personNames = new HashSet<>(1);
PersonName personName = new PersonName();
personName.setFamilyName("name");
personNames.add(personName);
person.setNames(personNames);
provider.setPerson(person);
// when
providerValidator.validate(provider, errors);
// then
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class UserValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see UserValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
User user = new User();
user.setUsername("test");
user.setSystemId("systemId");
user.setRetireReason("retireReason");
user.setPerson(new Person(999));
user.getPerson().addName(new PersonName("Users", "Need", "People"));
user.getPerson().setGender("F");
Errors errors = new BindException(user, "user");
validator.validate(user, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class UserValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see UserValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
User user = new User();
user.setUsername(STRING_WITH_LENGTH_GREATER_THAN_50);
user.setSystemId(STRING_WITH_LENGTH_GREATER_THAN_50);
user.setRetireReason(STRING_WITH_LENGTH_GREATER_THAN_50);
user.setPerson(new Person(999));
user.getPerson().addName(new PersonName(STRING_WITH_LENGTH_GREATER_THAN_50, STRING_WITH_LENGTH_GREATER_THAN_50, STRING_WITH_LENGTH_GREATER_THAN_50));
user.getPerson().setGender(STRING_WITH_LENGTH_GREATER_THAN_50);
Errors errors = new BindException(user, "user");
validator.validate(user, errors);
Assert.assertTrue(errors.hasFieldErrors("username"));
Assert.assertTrue(errors.hasFieldErrors("systemId"));
Assert.assertTrue(errors.hasFieldErrors("retireReason"));
Assert.assertTrue(errors.hasFieldErrors("person.names[0].givenName"));
Assert.assertTrue(errors.hasFieldErrors("person.names[0].middleName"));
Assert.assertTrue(errors.hasFieldErrors("person.names[0].familyName"));
Assert.assertTrue(errors.hasFieldErrors("person.gender"));
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class ProviderByPersonNameComparatorTest method compareProvidersByPersonName_shouldNotFailIfProvider1HasNoAssociatedPerson.
@Test
public void compareProvidersByPersonName_shouldNotFailIfProvider1HasNoAssociatedPerson() {
Provider provider1 = new Provider();
Person person2 = new Person();
person2.addName(new PersonName("givenName", "middleName", "familyName"));
Provider provider2 = new Provider();
provider2.setPerson(person2);
int actualValue = new ProviderByPersonNameComparator().compare(provider1, provider2);
Assert.assertTrue("Expected a positive value but it was: " + actualValue, actualValue > 0);
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class EncounterServiceTest method newPerson.
private Person newPerson(String name) {
Person person = new Person();
Set<PersonName> personNames = new TreeSet<>();
PersonName personName = new PersonName();
personName.setFamilyName(name);
personNames.add(personName);
person.setNames(personNames);
return person;
}
Aggregations