Commit d63101f9 authored by Franck Desaize's avatar Franck Desaize
Browse files

TUs Service : 100%

parent 83bc2b89
Pipeline #262818 failed with stages
in 4 minutes and 28 seconds
......@@ -12,7 +12,7 @@ import java.util.List;
@Table(name = "pix_cross_reference", schema = "public")
@SequenceGenerator(name = "pix_cross_reference_sequence", sequenceName = "pix_cross_reference_id_seq", allocationSize = 1)
@NamedQuery(name = "CrossReferenceDB.findByPatient", query = "SELECT cr FROM CrossReferenceDB cr WHERE :patient in (cr.patients)")
@NamedQuery(name = "CrossReferenceDB.findByPatientId", query = "SELECT cr FROM CrossReferenceDB cr WHERE :uuid = id")
@NamedQuery(name = "CrossReferenceDB.findByCrossRefId", query = "SELECT cr FROM CrossReferenceDB cr WHERE :pixReference = id")
@NamedQuery(name = "CrossReferenceDB.countPatient", query = "SELECT COUNT (cr) FROM CrossReferenceDB cr WHERE :patient in (cr.patients)")
public class CrossReferenceDB {
......
......@@ -63,9 +63,8 @@ public class PatientCrossReferenceDAOImpl implements PatientCrossReferenceDAO {
if (uuid == null || uuid.isBlank()) {
throw new IllegalArgumentException("The uuid of patientDB shall not be null");
}
TypedQuery<CrossReferenceDB> queryForPatientAliases = entityManager.createNamedQuery("CrossReferenceDB.findByPatientId", CrossReferenceDB.class);
queryForPatientAliases.setParameter("patient", patientDB);
queryForPatientAliases.setParameter("uuid", patientDB.getUuid());
TypedQuery<CrossReferenceDB> queryForPatientAliases = entityManager.createNamedQuery("CrossReferenceDB.findByCrossRefId", CrossReferenceDB.class);
queryForPatientAliases.setParameter("pixReference", patientDB.getPixReference().getId());
List<CrossReferenceDB> crossReferenceDBS = queryForPatientAliases.getResultList();
if (crossReferenceDBS.isEmpty()) {
throw new SearchCrossReferenceException("Search error : No X-ref for given Patient");
......
......@@ -4,9 +4,11 @@ import net.ihe.gazelle.app.patientregistryapi.application.SearchCrossReferenceEx
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.patientregistryapi.business.PersonName;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.converter.PatientConverter;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.*;
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;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientIdentifierDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.references.CrossReferenceDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.PatientCrossReferenceDAO;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.PatientCrossReferenceDAOImpl;
......@@ -15,19 +17,19 @@ import org.junit.AfterClass;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals;
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";
......@@ -45,7 +47,7 @@ public class PatientCrossReferenceDAOImplTest {
}
@BeforeAll
public void startup() throws ParseException {
void startup() throws ParseException {
entityManager = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME_CONST).createEntityManager();
patientCrossReferenceDAO = new PatientCrossReferenceDAOImpl(entityManager);
addTestEntitiesToDB(entityManager);
......@@ -80,47 +82,53 @@ public class PatientCrossReferenceDAOImplTest {
}
@Test
void testNullPatientDB(){
void testNullPatientDB() {
PatientDB patientDB = new PatientDB();
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(null));
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(null));
assertEquals("Patient Cannot be null", exception.getMessage());
}
@Test
void testNullUUIDFromPatient(){
void testNullUUIDFromPatient() {
PatientDB patientDB = new PatientDB();
patientDB.setUuid(null);
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
assertEquals("The uuid of patientDB shall not be null", exception.getMessage());
}
@Test
void testBlankUUIDFromPatient(){
void testBlankUUIDFromPatient() {
PatientDB patientDB = new PatientDB();
patientDB.setUuid("");
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
assertEquals("The uuid of patientDB shall not be null", exception.getMessage());
}
@Test
void testEmptyCrossReference(){
void testEmptyCrossReference() {
PatientDB patientDB = new PatientDB();
patientDB.setUuid("1234");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
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));
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));
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The system identifier from entityIdentifier cannot be null or empty", exception.getMessage());
}
......@@ -128,7 +136,8 @@ public class PatientCrossReferenceDAOImplTest {
void testBlankSystemIdentifierInEntityIdentifier() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The system identifier from entityIdentifier cannot be null or empty", exception.getMessage());
}
......@@ -136,7 +145,8 @@ public class PatientCrossReferenceDAOImplTest {
void testNoValueInEntityIdentifier() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("toto");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The value from entityIdentifier cannot be null or empty", exception.getMessage());
}
......@@ -145,16 +155,18 @@ public class PatientCrossReferenceDAOImplTest {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("toto");
entityIdentifier.setValue("");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The value from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
void testNoHierarchicDesignatorDB(){
void testNoHierarchicDesignatorDB() {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("unknown-hierarchicDesignator");
entityIdentifier.setValue("test");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("System not found", exception.getMessage());
}
......@@ -163,7 +175,8 @@ public class PatientCrossReferenceDAOImplTest {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("1111");
entityIdentifier.setValue("unknown");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("PatientIdentifier not found", exception.getMessage());
}
......@@ -172,7 +185,8 @@ public class PatientCrossReferenceDAOImplTest {
EntityIdentifier entityIdentifier = new EntityIdentifier();
entityIdentifier.setSystemIdentifier("2222");
entityIdentifier.setValue("1236");
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class, () -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("Patient not found with with corresponding PatientIdentifier", exception.getMessage());
}
......@@ -252,6 +266,5 @@ public class PatientCrossReferenceDAOImplTest {
CrossReferenceDB crossReferenceDBMerged = entityManager.merge(crossReferenceDB);
}
}
}
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