Commit 45228c58 authored by Matthieu Bonnouvrier's avatar Matthieu Bonnouvrier
Browse files

Changes in db in memory config for TUs

parent 3b6e5167
......@@ -5,11 +5,8 @@ import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.*;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.references.CrossReferenceDB;
import org.junit.After;
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 org.junit.Before;
import org.junit.jupiter.api.*;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
......@@ -23,27 +20,48 @@ import static org.junit.jupiter.api.Assertions.*;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class PatientCrossReferenceDAOImplTest {
private static final String PERSISTENCE_UNIT_NAME_CONST = "PersistenceUnitTest";
private static final String PERSISTENCE_UNIT_NAME_CONST = "PersistenceUnitCrossRefTest";
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);
// }
//
// @BeforeEach
// public void initializeDatabase() {
// entityManager.getTransaction().begin();
// entityManager.getTransaction().commit();
// }
@BeforeAll
void startup() throws ParseException {
public void initializeDatabase() throws ParseException {
entityManager = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME_CONST).createEntityManager();
patientCrossReferenceDAO = new PatientCrossReferenceDAOImpl(entityManager);
entityManager.getTransaction().begin();
addTestEntitiesToDB(entityManager);
}
// @BeforeEach
// public void tata(){
// if(!entityManager.getTransaction().isActive()) {
// entityManager.getTransaction().begin();
// }
// }
// @Before
// public void toto(){
// if(!entityManager.getTransaction().isActive()) {
// entityManager.getTransaction().begin();
// entityManager.isOpen();
// }
// }
private void addTestEntitiesToDB(EntityManager entityManager) throws ParseException {
initializeDb(entityManager);
}
......@@ -51,16 +69,19 @@ class PatientCrossReferenceDAOImplTest {
/**
* Close the transaction corresponding to the test case when it is over.
*/
@After
public void commitTransaction() {
entityManager.getTransaction().commit();
}
// @After
// public void commitTransaction() {
// entityManager.getTransaction().commit();
// entityManager.clear();
// entityManager.close();
// }
/**
* Close the connection to the database after all tests are executed.
*/
@AfterClass
@AfterAll
public void closeDatabase() {
entityManager.clear();
entityManager.close();
}
......@@ -78,6 +99,7 @@ class PatientCrossReferenceDAOImplTest {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(null));
assertEquals("Patient Cannot be null", exception.getMessage());
}
@Test
......@@ -87,6 +109,7 @@ class PatientCrossReferenceDAOImplTest {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
assertEquals("The uuid of patientDB shall not be null", exception.getMessage());
}
@Test
......@@ -96,6 +119,7 @@ class PatientCrossReferenceDAOImplTest {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
assertEquals("The uuid of patientDB shall not be null", exception.getMessage());
}
@Test
......@@ -107,6 +131,7 @@ class PatientCrossReferenceDAOImplTest {
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB));
assertEquals("Search error : No X-ref for given Patient", exception.getMessage());
}
@Test
......@@ -116,6 +141,7 @@ class PatientCrossReferenceDAOImplTest {
entityIdentifier.setValue("1235");
PatientDB patientDB = patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier);
patientCrossReferenceDAO.searchForPatientAliasesWithPatientDB(patientDB);
}
@Test
......@@ -123,6 +149,7 @@ class PatientCrossReferenceDAOImplTest {
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(null));
assertEquals("The source identifier cannot be null", exception.getMessage());
}
@Test
......@@ -131,6 +158,7 @@ class PatientCrossReferenceDAOImplTest {
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The system identifier from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
......@@ -140,6 +168,7 @@ class PatientCrossReferenceDAOImplTest {
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The system identifier from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
......@@ -149,6 +178,7 @@ class PatientCrossReferenceDAOImplTest {
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The value from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
......@@ -159,6 +189,7 @@ class PatientCrossReferenceDAOImplTest {
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("The value from entityIdentifier cannot be null or empty", exception.getMessage());
}
@Test
......@@ -169,6 +200,7 @@ class PatientCrossReferenceDAOImplTest {
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("System not found", exception.getMessage());
}
@Test
......@@ -179,6 +211,7 @@ class PatientCrossReferenceDAOImplTest {
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("PatientIdentifier not found", exception.getMessage());
}
@Test
......@@ -189,6 +222,7 @@ class PatientCrossReferenceDAOImplTest {
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceDAO.searchForPatientDBWithSourceIdentifier(entityIdentifier));
assertEquals("Patient not found with with corresponding PatientIdentifier", exception.getMessage());
}
......
......@@ -19,7 +19,7 @@
<class>net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.references.CrossReferenceDB</class>
<properties>
<!-- Configuring JDBC properties -->
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:PersistenceUnitTest;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE"/>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<!-- Hibernate properties -->
......@@ -27,9 +27,37 @@
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.connection.autocommit" value="true"/>
<property name="hibernate.transaction.auto_close_session" value="true"/>
</properties>
</persistence-unit>
<persistence-unit name="PersistenceUnitCrossRefTest" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientDB</class>
<class>net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientIdentifierDB</class>
<class>net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.HierarchicDesignatorDB</class>
<class>net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientAddressDB</class>
<class>net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientPhoneNumberDB</class>
<class>net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PersonDB</class>
<class>net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PersonAddressDB</class>
<class>net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PersonPhoneNumberDB</class>
<class>net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.references.CrossReferenceDB</class>
<properties>
<!-- Configuring JDBC properties -->
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:PersistenceUnitCrossRefTest;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE"/>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<!-- Hibernate properties -->
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.connection.autocommit" value="true"/>
<property name="hibernate.transaction.auto_close_session" value="true"/>
<!-- <property name="hibernate.hibernate.hbm2ddl.auto" value="create-drop"/>-->
</properties>
</persistence-unit>
</persistence>
\ No newline at end of file
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