Search in sources :

Example 1 with DuplicateIdentifierException

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

the class PatientServiceImplTest method checkPatientIdentifiers_shouldThrowDuplicateIdentifierGivenDuplicateIdentifiers.

@Test
public void checkPatientIdentifiers_shouldThrowDuplicateIdentifierGivenDuplicateIdentifiers() throws Exception {
    // given
    final Integer equalIdentifierTypeId = 12345;
    final String equalIdentifierTypeName = "TypeName";
    final String equalIdentifier = "Identifier1";
    final PatientIdentifierType identifierType = new PatientIdentifierType(equalIdentifierTypeId);
    identifierType.setName(equalIdentifierTypeName);
    final PatientIdentifierType sameIdentifierType = new PatientIdentifierType(equalIdentifierTypeId);
    sameIdentifierType.setName(equalIdentifierTypeName);
    when(patientDaoMock.getPatientIdentifierTypes(any(), any(), any(), any())).thenReturn(new ArrayList<>());
    final Patient patientWithIdentifiers = new Patient();
    final PatientIdentifier patientIdentifier = new PatientIdentifier("some identifier", identifierType, mock(Location.class));
    patientIdentifier.setIdentifier(equalIdentifier);
    patientWithIdentifiers.addIdentifier(patientIdentifier);
    final PatientIdentifier patientIdentifierSameType = new PatientIdentifier("some identifier", sameIdentifierType, mock(Location.class));
    patientIdentifierSameType.setIdentifier(equalIdentifier);
    patientWithIdentifiers.addIdentifier(patientIdentifierSameType);
    // when
    try {
        patientService.checkPatientIdentifiers(patientWithIdentifiers);
        // then
        fail();
    } catch (DuplicateIdentifierException e) {
        assertNotNull(e.getPatientIdentifier());
        assertTrue(e.getMessage().contains("Identifier1 id type #: 12345"));
    }
}
Also used : DuplicateIdentifierException(org.openmrs.api.DuplicateIdentifierException) Patient(org.openmrs.Patient) Matchers.anyString(org.mockito.Matchers.anyString) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PatientServiceTest(org.openmrs.api.PatientServiceTest)

Aggregations

Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Location (org.openmrs.Location)1 Patient (org.openmrs.Patient)1 PatientIdentifier (org.openmrs.PatientIdentifier)1 PatientIdentifierType (org.openmrs.PatientIdentifierType)1 DuplicateIdentifierException (org.openmrs.api.DuplicateIdentifierException)1 PatientServiceTest (org.openmrs.api.PatientServiceTest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1