Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 11040327 authored by Wylem Bars's avatar Wylem Bars

PATREG-33 | Add Tests for Identifier and Domain criterion as well as Multiple with AND/OR

parent 3668545b
package net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search;
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.app.patientregistryapi.business.Patient;
import net.ihe.gazelle.app.patientregistryapi.business.PatientSearchCriterionKey;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.DomainDAOImpl;
......@@ -8,6 +9,7 @@ import net.ihe.gazelle.app.patientregistryservice.application.PatientCreationExc
import net.ihe.gazelle.app.patientregistryservice.application.PatientDAO;
import net.ihe.gazelle.app.patientregistryservice.application.PatientDeleteException;
import net.ihe.gazelle.lib.searchmodelapi.business.SearchCriteria;
import net.ihe.gazelle.lib.searchmodelapi.business.SearchCriteriaLogicalOperator;
import net.ihe.gazelle.lib.searchmodelapi.business.exception.SearchException;
import net.ihe.gazelle.lib.searchmodelapi.business.searchcriterion.SearchCriterion;
import net.ihe.gazelle.lib.searchmodelapi.business.searchcriterion.StringSearchCriterion;
......@@ -19,7 +21,8 @@ import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class PatientSearchDAOTest {
......@@ -56,7 +59,6 @@ public class PatientSearchDAOTest {
entityManager.close();
}
/**
* Test Patient search on UUID with a unique patient in DB.
*/
......@@ -76,7 +78,7 @@ public class PatientSearchDAOTest {
assertNotNull(retrievedPatients);
assertEquals(1, retrievedPatients.size());
assertTrue(patient.equals(retrievedPatients.get(0)), "Returned patient shall be equal to the one fed !");
assertEquals(patient, retrievedPatients.get(0), "Returned patient shall be equal to the one fed !");
patientDAO.deletePatient(retrievedPatients.get(0));
}
......@@ -107,7 +109,7 @@ public class PatientSearchDAOTest {
assertNotNull(retrievedPatients);
assertEquals(1, retrievedPatients.size());
assertTrue(patient.equals(retrievedPatients.get(0)), "Returned patient shall be equal to the one fed !");
assertEquals(patient, retrievedPatients.get(0), "Returned patient shall be equal to the one fed !");
}
/**
......@@ -138,4 +140,193 @@ public class PatientSearchDAOTest {
assertNotNull(retrievedPatients);
assertEquals(0, retrievedPatients.size());
}
/**
* Test Patient search on Identifier with a unique patient in DB.
*/
@Test
public void patient_search_identifier_unique_patient() throws SearchException, PatientCreationException, PatientDeleteException {
Patient patient = new Patient();
String uuid = "test-uuid0";
String identifier = "test-identifier";
patient.setUuid(uuid);
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setValue(identifier);
patient.addIdentifier(entityIdentifier);
patientDAO.createPatient(patient);
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.IDENTIFIER);
searchCriterion.setValue(identifier);
searchCriteria.addSearchCriterion(searchCriterion);
List<Patient> retrievedPatients = patientSearchDAO.search(searchCriteria);
assertNotNull(retrievedPatients);
assertEquals(1, retrievedPatients.size());
assertEquals(patient, retrievedPatients.get(0), "Returned patient shall be equal to the one fed !");
patientDAO.deletePatient(retrievedPatients.get(0));
}
/**
* Test Patient search on Identifier with multiple patients in DB.
*/
@Test
public void patient_search_identifier_multiple_patient() throws SearchException, PatientCreationException, PatientDeleteException {
Patient patient = new Patient();
String uuid = "test-uuid0";
patient.setUuid(uuid);
String identifier = "test-identifier";
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setValue(identifier);
patient.addIdentifier(entityIdentifier);
patientDAO.createPatient(patient);
Patient patient1 = new Patient();
String uuid1 = "test-uuid1";
patient1.setUuid(uuid1);
EntityIdentifier entityIdentifier1 = new EntityIdentifier();
entityIdentifier1.setValue("tutu");
patient1.addIdentifier(entityIdentifier1);
patientDAO.createPatient(patient1);
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.IDENTIFIER);
searchCriterion.setValue(identifier);
searchCriteria.addSearchCriterion(searchCriterion);
List<Patient> retrievedPatients = patientSearchDAO.search(searchCriteria);
patientDAO.deletePatient(patient);
patientDAO.deletePatient(patient1);
assertNotNull(retrievedPatients);
assertEquals(1, retrievedPatients.size());
assertEquals(patient, retrievedPatients.get(0), "Returned patient shall be equal to the one fed !");
}
/**
* Test Patient search on Identifier with no match in DB.
*/
@Test
public void patient_search_no_match_identifier() throws SearchException, PatientCreationException, PatientDeleteException {
Patient patient = new Patient();
String uuid = "test-uuid0";
String identifier = "test-identifier";
patient.setUuid(uuid);
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setValue(identifier);
patient.addIdentifier(entityIdentifier);
patientDAO.createPatient(patient);
Patient patient1 = new Patient();
String uuid1 = "test-uuid1";
patient1.setUuid(uuid1);
patient1.addIdentifier(entityIdentifier);
patientDAO.createPatient(patient1);
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.IDENTIFIER);
searchCriterion.setValue("Tralalilalere");
searchCriteria.addSearchCriterion(searchCriterion);
List<Patient> retrievedPatients = patientSearchDAO.search(searchCriteria);
patientDAO.deletePatient(patient);
patientDAO.deletePatient(patient1);
assertNotNull(retrievedPatients);
assertEquals(0, retrievedPatients.size());
}
/**
* Test Patient search on Identifier AND UUID with multiple patients in DB.
*/
@Test
public void patientSearchIdentifierAndUUIDMultiplePatient() throws SearchException, PatientCreationException, PatientDeleteException {
Patient patient = new Patient();
String uuid = "test-uuid0";
String identifier = "test-identifier";
patient.setUuid(uuid);
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setValue(identifier);
patient.addIdentifier(entityIdentifier);
patientDAO.createPatient(patient);
Patient patient1 = new Patient();
String uuid1 = "test-uuid1";
patient1.setUuid(uuid1);
EntityIdentifier entityIdentifier1 = new EntityIdentifier();
entityIdentifier1.setValue(identifier);
patient1.addIdentifier(entityIdentifier1);
patientDAO.createPatient(patient1);
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue(uuid);
SearchCriterion searchCriterion1 = new StringSearchCriterion(PatientSearchCriterionKey.IDENTIFIER);
searchCriterion1.setValue(identifier);
searchCriteria.addSearchCriterion(searchCriterion);
searchCriteria.addSearchCriterion(searchCriterion1);
searchCriteria.setLogicalOperator(SearchCriteriaLogicalOperator.AND);
List<Patient> retrievedPatients = patientSearchDAO.search(searchCriteria);
patientDAO.deletePatient(patient);
patientDAO.deletePatient(patient1);
assertNotNull(retrievedPatients);
assertEquals(1, retrievedPatients.size());
assertEquals(patient, retrievedPatients.get(0), "Returned patient shall be equal to the one fed !");
}
/**
* Test Patient search on Identifier OR UUID with multiple patients in DB.
*/
@Test
public void patientSearchIdentifierOrUUIDMultiplePatient() throws SearchException, PatientCreationException, PatientDeleteException {
Patient patient = new Patient();
String uuid = "test-uuid0";
String identifier = "test-identifier";
patient.setUuid(uuid);
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setValue(identifier);
patient.addIdentifier(entityIdentifier);
patientDAO.createPatient(patient);
Patient patient1 = new Patient();
String uuid1 = "test-uuid1";
patient1.setUuid(uuid1);
EntityIdentifier entityIdentifier1 = new EntityIdentifier();
entityIdentifier1.setValue("tutu");
patient1.addIdentifier(entityIdentifier1);
patientDAO.createPatient(patient1);
Patient patient2 = new Patient();
String uuid2 = "test-uuid2";
patient2.setUuid(uuid2);
EntityIdentifier entityIdentifier2 = new EntityIdentifier();
entityIdentifier1.setValue("tutu");
patient2.addIdentifier(entityIdentifier2);
patientDAO.createPatient(patient2);
SearchCriteria searchCriteria = new SearchCriteria();
SearchCriterion searchCriterion = new StringSearchCriterion(PatientSearchCriterionKey.UUID);
searchCriterion.setValue(uuid1);
SearchCriterion searchCriterion1 = new StringSearchCriterion(PatientSearchCriterionKey.IDENTIFIER);
searchCriterion1.setValue(identifier);
searchCriteria.addSearchCriterion(searchCriterion);
searchCriteria.addSearchCriterion(searchCriterion1);
searchCriteria.setLogicalOperator(SearchCriteriaLogicalOperator.OR);
List<Patient> retrievedPatients = patientSearchDAO.search(searchCriteria);
patientDAO.deletePatient(patient);
patientDAO.deletePatient(patient1);
assertNotNull(retrievedPatients);
assertEquals(2, retrievedPatients.size());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment