Search in sources :

Example 26 with PersonName

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());
}
Also used : PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) HashSet(java.util.HashSet) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 27 with PersonName

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());
}
Also used : Errors(org.springframework.validation.Errors) PersonName(org.openmrs.PersonName) User(org.openmrs.User) BindException(org.springframework.validation.BindException) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 28 with PersonName

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"));
}
Also used : Errors(org.springframework.validation.Errors) PersonName(org.openmrs.PersonName) User(org.openmrs.User) BindException(org.springframework.validation.BindException) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 29 with PersonName

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);
}
Also used : PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) Provider(org.openmrs.Provider) Test(org.junit.Test)

Example 30 with PersonName

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;
}
Also used : PersonName(org.openmrs.PersonName) TreeSet(java.util.TreeSet) Person(org.openmrs.Person)

Aggregations

PersonName (org.openmrs.PersonName)115 Test (org.junit.Test)86 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)57 Patient (org.openmrs.Patient)46 Person (org.openmrs.Person)41 Date (java.util.Date)29 PatientIdentifier (org.openmrs.PatientIdentifier)24 PersonAddress (org.openmrs.PersonAddress)20 User (org.openmrs.User)19 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)17 Location (org.openmrs.Location)13 PatientIdentifierType (org.openmrs.PatientIdentifierType)13 ArrayList (java.util.ArrayList)9 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)8 PersonMergeLog (org.openmrs.person.PersonMergeLog)8 PersonAttribute (org.openmrs.PersonAttribute)7 PatientAndMatchQuality (org.openmrs.module.registrationcore.api.search.PatientAndMatchQuality)7 BindException (org.springframework.validation.BindException)7 Provider (org.openmrs.Provider)6 Errors (org.springframework.validation.Errors)6