Search in sources :

Example 1 with MissingRequiredIdentifierException

use of org.openmrs.api.MissingRequiredIdentifierException in project openmrs-core by openmrs.

the class PatientServiceImplTest method checkPatientIdentifiers_shouldThrowMissingRequiredIdentifierGivenRequiredIdentifierTypeMissing.

@Test
public void checkPatientIdentifiers_shouldThrowMissingRequiredIdentifierGivenRequiredIdentifierTypeMissing() throws Exception {
    // given
    final PatientIdentifierType requiredIdentifierType = new PatientIdentifierType(12345);
    requiredIdentifierType.setUuid("some type uuid");
    requiredIdentifierType.setName("NameOfRequiredIdentifierType");
    final PatientIdentifierType patientIdentifierType = new PatientIdentifierType(6789);
    patientIdentifierType.setUuid("another type uuid");
    patientIdentifierType.setName("NameOfPatientIdentifierType");
    final List<PatientIdentifierType> requiredTypes = new ArrayList<>();
    requiredTypes.add(requiredIdentifierType);
    when(patientDaoMock.getPatientIdentifierTypes(any(), any(), any(), any())).thenReturn(requiredTypes);
    final Patient patientWithIdentifiers = new Patient();
    patientWithIdentifiers.addIdentifier(new PatientIdentifier("some identifier", patientIdentifierType, mock(Location.class)));
    try {
        // when
        patientService.checkPatientIdentifiers(patientWithIdentifiers);
        fail();
    // then
    } catch (MissingRequiredIdentifierException e) {
        assertTrue(e.getMessage().contains("required"));
        assertTrue(e.getMessage().contains("NameOfRequiredIdentifierType"));
    } catch (Exception e) {
        fail("Expecting MissingRequiredIdentifierException");
    }
}
Also used : MissingRequiredIdentifierException(org.openmrs.api.MissingRequiredIdentifierException) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) DuplicateIdentifierException(org.openmrs.api.DuplicateIdentifierException) APIException(org.openmrs.api.APIException) MissingRequiredIdentifierException(org.openmrs.api.MissingRequiredIdentifierException) InsufficientIdentifiersException(org.openmrs.api.InsufficientIdentifiersException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PatientServiceTest(org.openmrs.api.PatientServiceTest)

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Patient (org.openmrs.Patient)1 PatientIdentifier (org.openmrs.PatientIdentifier)1 PatientIdentifierType (org.openmrs.PatientIdentifierType)1 APIException (org.openmrs.api.APIException)1 DuplicateIdentifierException (org.openmrs.api.DuplicateIdentifierException)1 InsufficientIdentifiersException (org.openmrs.api.InsufficientIdentifiersException)1 MissingRequiredIdentifierException (org.openmrs.api.MissingRequiredIdentifierException)1 PatientServiceTest (org.openmrs.api.PatientServiceTest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1