Commit eafab500 authored by Matthieu Bonnouvrier's avatar Matthieu Bonnouvrier
Browse files

Add TUs

parent d63101f9
Pipeline #262933 canceled with stages
in 3 minutes and 33 seconds
......@@ -64,9 +64,12 @@ public class PatientCrossReferenceDAOImpl implements PatientCrossReferenceDAO {
throw new IllegalArgumentException("The uuid of patientDB shall not be null");
}
TypedQuery<CrossReferenceDB> queryForPatientAliases = entityManager.createNamedQuery("CrossReferenceDB.findByCrossRefId", CrossReferenceDB.class);
System.out.println("searchForPatientAliasesWithPatientDB");
System.out.println(patientDB.getPixReference());
System.out.println(patientDB.getPixReference().getId());
queryForPatientAliases.setParameter("pixReference", patientDB.getPixReference().getId());
List<CrossReferenceDB> crossReferenceDBS = queryForPatientAliases.getResultList();
if (crossReferenceDBS.isEmpty()) {
if (crossReferenceDBS.isEmpty() || crossReferenceDBS.get(0).getPatients().isEmpty()) {
throw new SearchCrossReferenceException("Search error : No X-ref for given Patient");
}
return crossReferenceDBS;
......
......@@ -2,9 +2,6 @@ package net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.serv
import net.ihe.gazelle.app.patientregistryapi.application.SearchCrossReferenceException;
import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.app.patientregistryapi.business.GenderCode;
import net.ihe.gazelle.app.patientregistryapi.business.Patient;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.converter.PatientConverter;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.GenderCodeDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.HierarchicDesignatorDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientDB;
......@@ -22,7 +19,6 @@ import org.junit.jupiter.api.TestInstance;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
......@@ -32,239 +28,262 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class PatientCrossReferenceDAOImplTest {
private static final String PERSISTENCE_UNIT_NAME_CONST = "PersistenceUnitTest";
private PatientCrossReferenceDAO patientCrossReferenceDAO;
private EntityManager entityManager;
/**
* database init
*/
@BeforeEach
public void initializeDatabase() {
entityManager.getTransaction().begin();
entityManager.getTransaction().commit();
}
@BeforeAll
void startup() throws ParseException {
entityManager = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME_CONST).createEntityManager();
patientCrossReferenceDAO = new PatientCrossReferenceDAOImpl(entityManager);
addTestEntitiesToDB(entityManager);
System.out.println("tempo");
}
private static void addTestEntitiesToDB(EntityManager entityManager) throws ParseException {
initializeDb(entityManager);
}
/**
* Close the transaction corresponding to the test case when it is over.
*/
@After
public void commitTransaction() {
entityManager.getTransaction().commit();
}
/**
* Close the connection to the database after all tests are executed.
*/
@AfterClass
public void closeDatabase() {
entityManager.close();
}
@Test
void testNullEntityManager() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new PatientCrossReferenceDAOImpl(null));
assertEquals("EntityManager cannot be null", exception.getMessage());
}
@Test
void testNullPatientDB() {
PatientDB patientDB = new PatientDB();
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(null));
assertEquals("Patient Cannot be null", exception.getMessage());
}
@Test
void testNullUUIDFromPatient() {
PatientDB patientDB = new PatientDB();
patientDB.setUuid(null);
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
assertEquals("The uuid of patientDB shall not be null", exception.getMessage());
}
@Test
void testBlankUUIDFromPatient() {
PatientDB patientDB = new PatientDB();
patientDB.setUuid("");
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
assertEquals("The uuid of patientDB shall not be null", exception.getMessage());
}
@Test
void testEmptyCrossReference() {
PatientDB patientDB = new PatientDB();
patientDB.setUuid("1234");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
assertEquals("No PatientAliases found with given patient", exception.getMessage());
}
@Test
void testNullEntityIdentifier() {
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(null));
assertEquals("The source identifier cannot be null", exception.getMessage());
}
@Test
void testNoSystemIdentifierInEntityIdentifier() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The system identifier from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
void testBlankSystemIdentifierInEntityIdentifier() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The system identifier from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
void testNoValueInEntityIdentifier() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("toto");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The value from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
void testBlankValueInEntityIdentifier() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("toto");
entityIdentifier.setValue("");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The value from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
void testNoHierarchicDesignatorDB() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("unknown-hierarchicDesignator");
entityIdentifier.setValue("test");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("System not found", exception.getMessage());
}
@Test
void testNoPatientIdentifierDB() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("1111");
entityIdentifier.setValue("unknown");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("PatientIdentifier not found", exception.getMessage());
}
@Test
void testNoPatientDB() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("2222");
entityIdentifier.setValue("1236");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("Patient not found with with corresponding PatientIdentifier", exception.getMessage());
}
@Test
void testAllValid() throws SearchCrossReferenceException {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("1111");
entityIdentifier.setValue("1235");
PatientDB patientDB = patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier);
System.out.println("test");
//TODO assert
}
private static void initializeDb(EntityManager entityManager) {
HierarchicDesignatorDB hierarchicDesignatorDB = new HierarchicDesignatorDB();
hierarchicDesignatorDB.setUniversalID("1111");
hierarchicDesignatorDB.setUniversalIDType("ISO");
HierarchicDesignatorDB hierarchicDesignatorDB2 = entityManager.merge(hierarchicDesignatorDB);
HierarchicDesignatorDB hierarchicDesignatorDB3 = new HierarchicDesignatorDB();
hierarchicDesignatorDB3.setUniversalID("2222");
hierarchicDesignatorDB3.setUniversalIDType("ISO");
HierarchicDesignatorDB hierarchicDesignatorDB4 = entityManager.merge(hierarchicDesignatorDB3);
HierarchicDesignatorDB hierarchicDesignatorDB5 = new HierarchicDesignatorDB();
hierarchicDesignatorDB5.setUniversalID("3333");
hierarchicDesignatorDB5.setUniversalIDType("ISO");
HierarchicDesignatorDB hierarchicDesignatorDB6 = entityManager.merge(hierarchicDesignatorDB5);
PatientIdentifierDB patientIdentifierDB = new PatientIdentifierDB();
patientIdentifierDB.setDomain(hierarchicDesignatorDB2);
patientIdentifierDB.setIdentifier("1235");
PatientIdentifierDB patientIdentifierDBmerged = entityManager.merge(patientIdentifierDB);
PatientIdentifierDB patientIdentifierDB2 = new PatientIdentifierDB();
patientIdentifierDB2.setDomain(hierarchicDesignatorDB4);
patientIdentifierDB2.setIdentifier("1236");
PatientIdentifierDB patientIdentifierDB2merged = entityManager.merge(patientIdentifierDB2);
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
PatientDB patient1 = new PatientDB();
patient1.setUuid("1235");
patient1.setStillActive(true);
patient1.setGenderCode(GenderCodeDB.F);
patient1.setLastName("Dupont");
List<PatientIdentifierDB> patientIdentifierDBS = new ArrayList<>();
patientIdentifierDBS.add(patientIdentifierDBmerged);
patient1.setPatientIdentifiers(patientIdentifierDBS);
PatientDB patient1m = entityManager.merge(patient1);
PatientDB patient2 = new PatientDB();
patient2.setUuid("9999");
patient2.setStillActive(false);
patient2.setGenderCode(GenderCodeDB.M);
patient2.setLastName("Martin");
List<PatientIdentifierDB> patientIdentifierDBS2 = new ArrayList<>();
patientIdentifierDBS2.add(patientIdentifierDB2merged);
patient2.setPatientIdentifiers(patientIdentifierDBS2);
PatientDB patient2m = entityManager.merge(patient2);
Patient patient3 = new Patient();
patient3.setUuid("1111");
patient3.setActive(false);
patient3.setGender(GenderCode.MALE);
PatientDB patient3m = entityManager.merge(PatientConverter.toPatientDB(patient3));
List<PatientDB> patientDBS = new ArrayList<>();
patientDBS.add(patient1m);
patientDBS.add(patient2m);
patientDBS.add(patient3m);
CrossReferenceDB crossReferenceDB = new CrossReferenceDB();
crossReferenceDB.setLastModifier("fde");
crossReferenceDB.setPatients(patientDBS);
entityManager.persist(crossReferenceDB);
CrossReferenceDB crossReferenceDBMerged = entityManager.merge(crossReferenceDB);
}
private static final String PERSISTENCE_UNIT_NAME_CONST = "PersistenceUnitTest";
private PatientCrossReferenceDAO patientCrossReferenceDAO;
private EntityManager entityManager;
/**
* database init
*/
@BeforeEach
public void initializeDatabase() {
entityManager.getTransaction().begin();
entityManager.getTransaction().commit();
}
@BeforeAll
void startup() throws ParseException {
entityManager = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME_CONST).createEntityManager();
patientCrossReferenceDAO = new PatientCrossReferenceDAOImpl(entityManager);
addTestEntitiesToDB(entityManager);
System.out.println("tempo");
}
private static void addTestEntitiesToDB(EntityManager entityManager) throws ParseException {
initializeDb(entityManager);
}
/**
* Close the transaction corresponding to the test case when it is over.
*/
@After
public void commitTransaction() {
entityManager.getTransaction().commit();
}
/**
* Close the connection to the database after all tests are executed.
*/
@AfterClass
public void closeDatabase() {
entityManager.close();
}
@Test
void testNullEntityManager() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> new PatientCrossReferenceDAOImpl(null));
assertEquals("EntityManager cannot be null", exception.getMessage());
}
@Test
void testNullPatientDB() {
PatientDB patientDB = new PatientDB();
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(null));
assertEquals("Patient Cannot be null", exception.getMessage());
}
@Test
void testNullUUIDFromPatient() {
PatientDB patientDB = new PatientDB();
patientDB.setUuid(null);
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
assertEquals("The uuid of patientDB shall not be null", exception.getMessage());
}
@Test
void testBlankUUIDFromPatient() {
PatientDB patientDB = new PatientDB();
patientDB.setUuid("");
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
assertEquals("The uuid of patientDB shall not be null", exception.getMessage());
}
@Test
void testEmptyCrossReference() throws SearchCrossReferenceException {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("3333");
entityIdentifier.setValue("7777");
PatientDB patientDB = patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier);
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
assertEquals("Search error : No X-ref for given Patient", exception.getMessage());
}
@Test
void testAllValid3() throws SearchCrossReferenceException {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("1111");
entityIdentifier.setValue("1235");
PatientDB patientDB = patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier);
patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB);
}
@Test
void testNullEntityIdentifier() {
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(null));
assertEquals("The source identifier cannot be null", exception.getMessage());
}
@Test
void testNoSystemIdentifierInEntityIdentifier() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The system identifier from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
void testBlankSystemIdentifierInEntityIdentifier() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The system identifier from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
void testNoValueInEntityIdentifier() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("toto");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The value from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
void testBlankValueInEntityIdentifier() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("toto");
entityIdentifier.setValue("");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The value from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
void testNoHierarchicDesignatorDB() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("unknown-hierarchicDesignator");
entityIdentifier.setValue("test");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("System not found", exception.getMessage());
}
@Test
void testNoPatientIdentifierDB() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("1111");
entityIdentifier.setValue("unknown");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("PatientIdentifier not found", exception.getMessage());
}
@Test
void testNoPatientDB() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("2222");
entityIdentifier.setValue("1236");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("Patient not found with with corresponding PatientIdentifier", exception.getMessage());
}
private static void initializeDb(EntityManager entityManager) {
HierarchicDesignatorDB hierarchicDesignatorDB = new HierarchicDesignatorDB();
hierarchicDesignatorDB.setUniversalID("1111");
hierarchicDesignatorDB.setUniversalIDType("ISO");
HierarchicDesignatorDB hierarchicDesignatorDB2 = entityManager.merge(hierarchicDesignatorDB);
HierarchicDesignatorDB hierarchicDesignatorDB3 = new HierarchicDesignatorDB();
hierarchicDesignatorDB3.setUniversalID("2222");
hierarchicDesignatorDB3.setUniversalIDType("ISO");
HierarchicDesignatorDB hierarchicDesignatorDB4 = entityManager.merge(hierarchicDesignatorDB3);
HierarchicDesignatorDB hierarchicDesignatorDB5 = new HierarchicDesignatorDB();
hierarchicDesignatorDB5.setUniversalID("3333");
hierarchicDesignatorDB5.setUniversalIDType("ISO");
HierarchicDesignatorDB hierarchicDesignatorDB6 = entityManager.merge(hierarchicDesignatorDB5);
PatientIdentifierDB patientIdentifierDB = new PatientIdentifierDB();
patientIdentifierDB.setDomain(hierarchicDesignatorDB2);
patientIdentifierDB.setIdentifier("1235");
PatientIdentifierDB patientIdentifierDBmerged = entityManager.merge(patientIdentifierDB);
PatientIdentifierDB patientIdentifierDB2 = new PatientIdentifierDB();
patientIdentifierDB2.setDomain(hierarchicDesignatorDB4);
patientIdentifierDB2.setIdentifier("1236");
PatientIdentifierDB patientIdentifierDB2merged = entityManager.merge(patientIdentifierDB2);
PatientIdentifierDB patientIdentifierDB3 = new PatientIdentifierDB();
patientIdentifierDB3.setDomain(hierarchicDesignatorDB6);
patientIdentifierDB3.setIdentifier("7777");
PatientIdentifierDB patientIdentifierDB3merged = entityManager.merge(patientIdentifierDB3);
PatientDB patient1 = new PatientDB();
patient1.setUuid("1235");
patient1.setStillActive(true);
patient1.setGenderCode(GenderCodeDB.F);
patient1.setLastName("Dupont");
List<PatientIdentifierDB> patientIdentifierDBS = new ArrayList<>();
patientIdentifierDBS.add(patientIdentifierDBmerged);
patient1.setPatientIdentifiers(patientIdentifierDBS);
PatientDB patient1m = entityManager.merge(patient1);
PatientDB patient2 = new PatientDB();
patient2.setUuid("9999");
patient2.setStillActive(false);
patient2.setGenderCode(GenderCodeDB.M);
patient2.setLastName("Martin");
List<PatientIdentifierDB> patientIdentifierDBS2 = new ArrayList<>();
patientIdentifierDBS2.add(patientIdentifierDB2merged);
patient2.setPatientIdentifiers(patientIdentifierDBS2);
PatientDB patient2m = entityManager.merge(patient2);
PatientDB patient3 = new PatientDB();
patient3.setUuid("7777");
patient3.setStillActive(false);
patient3.setGenderCode(GenderCodeDB.M);
patient2.setLastName("Noah");
List<PatientIdentifierDB> patientIdentifierDBS3 = new ArrayList<>();
patientIdentifierDBS3.add(patientIdentifierDB3merged);
patient3.setPatientIdentifiers(patientIdentifierDBS3);
PatientDB patient3m = entityManager.merge(patient3);
List<PatientDB> patientDBS = new ArrayList<>();
patientDBS.add(patient1m);
patientDBS.add(patient2m);
CrossReferenceDB crossReferenceDB = new CrossReferenceDB();
crossReferenceDB.setLastModifier("fde");
crossReferenceDB.setPatients(patientDBS);
entityManager.persist(crossReferenceDB);
CrossReferenceDB crossReferenceDBMerged = entityManager.merge(crossReferenceDB);
patient1m.setPixReference(crossReferenceDBMerged);
entityManager.merge(patient1m);
patient2m.setPixReference(crossReferenceDBMerged);
entityManager.merge(patient2m);