Search in sources :

Example 11 with PersonMergeLog

use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.

the class PersonServiceTest method savePersonMergeLog_shouldSetDateCreatedIfNull.

/**
 * @see PersonService#savePersonMergeLog(PersonMergeLog)
 */
@Test
public void savePersonMergeLog_shouldSetDateCreatedIfNull() throws Exception {
    PersonMergeLog personMergeLog = getTestPersonMergeLog();
    personMergeLog.setDateCreated(null);
    PersonMergeLog persisted = Context.getPersonService().savePersonMergeLog(personMergeLog);
    Assert.assertNotNull("dateCreated has not been set", persisted.getDateCreated());
}
Also used : PersonMergeLog(org.openmrs.person.PersonMergeLog) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 12 with PersonMergeLog

use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.

the class PersonServiceTest method savePersonMergeLog_shouldRequireLoser.

/**
 * @see PersonService#savePersonMergeLog(PersonMergeLog)
 */
@Test(expected = APIException.class)
public void savePersonMergeLog_shouldRequireLoser() throws Exception {
    PersonMergeLog personMergeLog = getTestPersonMergeLog();
    personMergeLog.setLoser(null);
    Context.getPersonService().savePersonMergeLog(personMergeLog);
}
Also used : PersonMergeLog(org.openmrs.person.PersonMergeLog) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 13 with PersonMergeLog

use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.

the class PersonMergeLogValidator method validate.

/**
 * Checks the form object for any inconsistencies/errors
 *
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should fail validation if personMergeLogData is null
 * @should fail validation if winner is null
 * @should fail validation if loser is null
 * @should pass validation if all fields are correct
 * @should pass validation if field lengths are correct
 * @should fail validation if field lengths are not correct
 */
@Override
public void validate(Object obj, Errors errors) {
    PersonMergeLog personMergeLog = (PersonMergeLog) obj;
    if (personMergeLog == null) {
        errors.rejectValue("persnMergeLog", "error.general");
    } else {
        ValidationUtils.rejectIfEmpty(errors, "personMergeLogData", "error.null");
        ValidationUtils.rejectIfEmpty(errors, "winner", "error.null");
        ValidationUtils.rejectIfEmpty(errors, "loser", "error.null");
        ValidateUtil.validateFieldLengths(errors, obj.getClass(), "voidReason");
    }
}
Also used : PersonMergeLog(org.openmrs.person.PersonMergeLog)

Example 14 with PersonMergeLog

use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.

the class PersonMergeLogValidatorTest method validate_shouldPassValidationIfAllFieldsAreCorrect.

/**
 * @see PersonMergeLogValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfAllFieldsAreCorrect() {
    PersonMergeLog personMergeLog = new PersonMergeLog();
    personMergeLog.setWinner(new Person());
    personMergeLog.setLoser(new Person());
    personMergeLog.setPersonMergeLogData(new PersonMergeLogData());
    PersonMergeLogValidator validator = new PersonMergeLogValidator();
    Errors errors = new BindException(personMergeLog, "personMergeLog");
    validator.validate(personMergeLog, errors);
    Assert.assertFalse(errors.hasFieldErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PersonMergeLog(org.openmrs.person.PersonMergeLog) Person(org.openmrs.Person) PersonMergeLogData(org.openmrs.person.PersonMergeLogData) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with PersonMergeLog

use of org.openmrs.person.PersonMergeLog in project openmrs-core by openmrs.

the class PersonMergeLogValidatorTest method validate_shouldFailValidationIfLoserIsNull.

/**
 * @see PersonMergeLogValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfLoserIsNull() {
    PersonMergeLog personMergeLog = new PersonMergeLog();
    personMergeLog.setWinner(new Person());
    personMergeLog.setPersonMergeLogData(new PersonMergeLogData());
    PersonMergeLogValidator validator = new PersonMergeLogValidator();
    Errors errors = new BindException(personMergeLog, "personMergeLog");
    validator.validate(personMergeLog, errors);
    Assert.assertTrue(errors.hasFieldErrors("loser"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PersonMergeLog(org.openmrs.person.PersonMergeLog) Person(org.openmrs.Person) PersonMergeLogData(org.openmrs.person.PersonMergeLogData) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

PersonMergeLog (org.openmrs.person.PersonMergeLog)41 Test (org.junit.Test)37 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)37 Patient (org.openmrs.Patient)18 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)18 Person (org.openmrs.Person)9 PersonName (org.openmrs.PersonName)8 PersonMergeLogData (org.openmrs.person.PersonMergeLogData)8 Date (java.util.Date)6 BindException (org.springframework.validation.BindException)6 Errors (org.springframework.validation.Errors)6 GregorianCalendar (java.util.GregorianCalendar)4 Location (org.openmrs.Location)2 Obs (org.openmrs.Obs)2 PatientIdentifier (org.openmrs.PatientIdentifier)2 PersonAddress (org.openmrs.PersonAddress)2 PersonAttribute (org.openmrs.PersonAttribute)2 ArrayList (java.util.ArrayList)1 Encounter (org.openmrs.Encounter)1 PatientIdentifierType (org.openmrs.PatientIdentifierType)1