Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-911 new Junit test layout #683

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
Expand Down Expand Up @@ -162,6 +166,19 @@
</plugin>
</plugins>
</build>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.8.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.drewnoakes</groupId>
Expand Down Expand Up @@ -220,6 +237,11 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/isf/OHApplicationContextAware.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Open Hospital (www.open-hospital.org)
* Copyright © 2006-2022 Informatici Senza Frontiere ([email protected])
*
* Open Hospital is a free and open source software for healthcare data management.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* https://www.gnu.org/licenses/gpl-3.0-standalone.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isf;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class OHApplicationContextAware implements ApplicationContextAware {

public static ApplicationContext applicationContext;

public OHApplicationContextAware() {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
setApplicationContext(context);
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}

}
59 changes: 59 additions & 0 deletions src/test/java/org/isf/OHCoreTestCase5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Open Hospital (www.open-hospital.org)
* Copyright © 2006-2022 Informatici Senza Frontiere ([email protected])
*
* Open Hospital is a free and open source software for healthcare data management.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* https://www.gnu.org/licenses/gpl-3.0-standalone.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.isf;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@ExtendWith(SpringExtension.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
public abstract class OHCoreTestCase5 {

@Autowired
private EntityManagerFactory entityManagerFactory;

public void cleanH2InMemoryDb() {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
List<Object[]> showTables = entityManager.createNativeQuery("SHOW TABLES").getResultList();
showTables
.stream()
.map(result -> (String) result[0])
.forEach(s -> truncateTable(s, entityManager));
entityManager.getTransaction().commit();
entityManager.close();
}

public void truncateTable(String name, EntityManager entityManager) {
entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY FALSE").executeUpdate();
entityManager.createNativeQuery("TRUNCATE TABLE " + name).executeUpdate();
entityManager.createNativeQuery("SET REFERENTIAL_INTEGRITY TRUE").executeUpdate();
}

}
38 changes: 19 additions & 19 deletions src/test/java/org/isf/patient/TestMergePatient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Open Hospital (www.open-hospital.org)
* Copyright © 2006-2021 Informatici Senza Frontiere ([email protected])
* Copyright © 2006-2022 Informatici Senza Frontiere ([email protected])
*
* Open Hospital is a free and open source software for healthcare data management.
*
Expand Down Expand Up @@ -83,31 +83,31 @@ public class TestMergePatient extends OHCoreTestCase {
private static TestWard testWard;

@Autowired
PatientIoOperations patientIoOperation;
private PatientIoOperations patientIoOperation;
@Autowired
PatientIoOperationRepository patientIoOperationRepository;
private PatientIoOperationRepository patientIoOperationRepository;
@Autowired
PatientBrowserManager patientBrowserManager;
private PatientBrowserManager patientBrowserManager;
@Autowired
ExaminationIoOperationRepository examinationIoOperationRepository;
private ExaminationIoOperationRepository examinationIoOperationRepository;
@Autowired
VisitsIoOperationRepository visitsIoOperationRepository;
private VisitsIoOperationRepository visitsIoOperationRepository;
@Autowired
TestPatientMergedEventListener testPatientMergedEventListener;
private TestPatientMergedEventListener testPatientMergedEventListener;
@Autowired
PricesListIoOperationRepository priceListIoOperationRepository;
private PricesListIoOperationRepository priceListIoOperationRepository;
@Autowired
AccountingBillIoOperationRepository accountingBillIoOperationRepository;
private AccountingBillIoOperationRepository accountingBillIoOperationRepository;
@Autowired
AdmissionTypeIoOperationRepository admissionTypeIoOperationRepository;
private AdmissionTypeIoOperationRepository admissionTypeIoOperationRepository;
@Autowired
DiseaseTypeIoOperationRepository diseaseTypeIoOperationRepository;
private DiseaseTypeIoOperationRepository diseaseTypeIoOperationRepository;
@Autowired
DiseaseIoOperationRepository diseaseIoOperationRepository;
private DiseaseIoOperationRepository diseaseIoOperationRepository;
@Autowired
AdmissionIoOperationRepository admissionIoOperationRepository;
private AdmissionIoOperationRepository admissionIoOperationRepository;
@Autowired
WardIoOperationRepository wardIoOperationRepository;
private WardIoOperationRepository wardIoOperationRepository;

@BeforeClass
public static void setUpClass() {
Expand Down Expand Up @@ -432,27 +432,27 @@ private void assertThatObsoletePatientWasDeletedAndMergedIsTheActiveOne(Patient
assertThat(mergedPatientResult.getDeleted()).isEqualTo("N");
}

private void assertThatObsoletePatientWasNotDeletedAndIsTheActiveOne(Patient obsoletePatient) throws OHException {
private void assertThatObsoletePatientWasNotDeletedAndIsTheActiveOne(Patient obsoletePatient) {
Patient obsoletePatientResult = patientIoOperationRepository.findById(obsoletePatient.getCode()).get();
assertThat(obsoletePatientResult.getDeleted()).isEqualTo("N");
}

private void assertThatVisitWasMovedFromObsoleteToMergedPatient(Visit visit, Patient mergedPatient) throws OHException {
private void assertThatVisitWasMovedFromObsoleteToMergedPatient(Visit visit, Patient mergedPatient) {
Visit visitResult = visitsIoOperationRepository.findById(visit.getVisitID()).get();
assertThat(visitResult.getPatient().getCode()).isEqualTo(mergedPatient.getCode());
}

private void assertThatVisitIsStillAssignedToObsoletePatient(Visit visit, Patient obsoletePatient) throws OHException {
private void assertThatVisitIsStillAssignedToObsoletePatient(Visit visit, Patient obsoletePatient) {
Visit visitResult = visitsIoOperationRepository.findById(visit.getVisitID()).get();
assertThat(visitResult.getPatient().getCode()).isEqualTo(obsoletePatient.getCode());
}

private void assertThatExaminationWasMovedFromObsoleteToMergedPatient(PatientExamination examination, Patient mergedPatient) throws OHException {
private void assertThatExaminationWasMovedFromObsoleteToMergedPatient(PatientExamination examination, Patient mergedPatient) {
PatientExamination patientResult = examinationIoOperationRepository.findById(examination.getPex_ID()).get();
assertThat(patientResult.getPatient().getCode()).isEqualTo(mergedPatient.getCode());
}

private void assertThatExaminationIsStillAssignedToObsoletePatient(PatientExamination patientExamination, Patient obsoletePatient) throws OHException {
private void assertThatExaminationIsStillAssignedToObsoletePatient(PatientExamination patientExamination, Patient obsoletePatient) {
PatientExamination patientResult = examinationIoOperationRepository.findById(patientExamination.getPex_ID()).get();
assertThat(patientResult.getPatient().getCode()).isEqualTo(obsoletePatient.getCode());
}
Expand Down
Loading