diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6585c8ce5..7452b237a7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -55,11 +55,11 @@ jobs: path: ${{ github.workspace }}/omod/target - name: run db and web containers run: | - docker-compose -f docker/docker-compose-refqa.yml up -d + docker compose -f docker/docker-compose-refqa.yml up -d - name: wait for openmrs instance to start run: while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:8080/openmrs/login.htm)" != "200" ]]; do sleep 1; done - name: Run End to End tests run: mvn verify --batch-mode -P e2e-test --file pom.xml - name: Stop db and web containers if: always() - run: docker-compose -f "docker/docker-compose-refqa.yml" down + run: docker compose -f "docker/docker-compose-refqa.yml" down diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImpl.java index f8a4941bd2..2c1b7f5651 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImpl.java @@ -22,7 +22,6 @@ import java.util.Optional; import ca.uhn.fhir.rest.param.StringAndListParam; -import lombok.AccessLevel; import lombok.Setter; import org.hibernate.Criteria; import org.hibernate.transform.DistinctRootEntityResultTransformer; @@ -38,7 +37,7 @@ import org.springframework.stereotype.Component; @Component -@Setter(AccessLevel.PACKAGE) +@Setter public class FhirConceptDaoImpl extends BaseFhirDao implements FhirConceptDao { @Autowired diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConceptServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConceptServiceImpl.java index e916afe8c2..41ad8751ce 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConceptServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConceptServiceImpl.java @@ -12,7 +12,6 @@ import java.util.List; import java.util.Optional; -import lombok.AccessLevel; import lombok.Setter; import org.openmrs.Concept; import org.openmrs.ConceptMap; @@ -26,7 +25,7 @@ @Component @Transactional -@Setter(AccessLevel.PACKAGE) +@Setter public class FhirConceptServiceImpl implements FhirConceptService { @Autowired diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConceptSourceServiceImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConceptSourceServiceImpl.java index 1dc5c469af..822db07960 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConceptSourceServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/impl/FhirConceptSourceServiceImpl.java @@ -14,7 +14,6 @@ import java.util.Collection; import java.util.Optional; -import lombok.AccessLevel; import lombok.Setter; import org.openmrs.ConceptSource; import org.openmrs.Duration; @@ -28,7 +27,7 @@ @Component @Transactional -@Setter(AccessLevel.PACKAGE) +@Setter public class FhirConceptSourceServiceImpl implements FhirConceptSourceService { @Autowired diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationValueTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationValueTranslatorImpl.java index 1088c5bcc9..7d68368796 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationValueTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/ObservationValueTranslatorImpl.java @@ -50,8 +50,9 @@ public Type toFhirResource(@Nonnull Obs obs) { // IMPORTANT boolean values are stored as a coded value, so for this to // work, we must check for a boolean value before a general coded value - if (obs.getValueBoolean() != null) { - return new BooleanType(obs.getValueBoolean()); + Boolean valueBoolean = getValueBoolean(obs); + if (valueBoolean != null) { + return new BooleanType(valueBoolean); } else if (obs.getValueCoded() != null) { return conceptTranslator.toFhirResource(obs.getValueCoded()); } else if (obs.getValueDrug() != null) { @@ -99,11 +100,25 @@ public Obs toOpenmrsType(@Nonnull Obs obs, @Nonnull Type resource) { } else if (resource instanceof Quantity) { obs.setValueNumeric(((Quantity) resource).getValue().doubleValue()); } else if (resource instanceof BooleanType) { - obs.setValueBoolean(((BooleanType) resource).getValue()); + setValueBoolean(obs, ((BooleanType) resource).getValue()); } else if (resource instanceof StringType) { obs.setValueText(((StringType) resource).getValue()); } return obs; } + + /** + * @return the valueBoolean of the given obs + */ + protected Boolean getValueBoolean(Obs obs) { + return obs.getValueBoolean(); + } + + /** + * sets the valueBoolean property of the given obs to the given value + */ + protected void setValueBoolean(Obs obs, Boolean valueBoolean) { + obs.setValueBoolean(valueBoolean); + } } diff --git a/api/src/test/java/org/openmrs/module/fhir2/MockedCalendarFactoryConfiguration.java b/api/src/test/java/org/openmrs/module/fhir2/BaseFhirContextSensitiveTest.java similarity index 50% rename from api/src/test/java/org/openmrs/module/fhir2/MockedCalendarFactoryConfiguration.java rename to api/src/test/java/org/openmrs/module/fhir2/BaseFhirContextSensitiveTest.java index 36e2d2b379..7f6be376be 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/MockedCalendarFactoryConfiguration.java +++ b/api/src/test/java/org/openmrs/module/fhir2/BaseFhirContextSensitiveTest.java @@ -9,19 +9,16 @@ */ package org.openmrs.module.fhir2; -import org.mockito.Mockito; -import org.openmrs.module.fhir2.api.util.LocalDateTimeFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; +import org.junit.Before; +import org.openmrs.module.fhir2.api.util.FhirGlobalPropertyHolder; +import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.springframework.test.context.ContextConfiguration; -@Configuration -public class MockedCalendarFactoryConfiguration { +@ContextConfiguration(classes = { TestFhirSpringConfiguration.class }, inheritLocations = false) +public abstract class BaseFhirContextSensitiveTest extends BaseModuleContextSensitiveTest { - @Bean - @Primary - public LocalDateTimeFactory getCalendarFactory() { - return Mockito.mock(LocalDateTimeFactory.class); + @Before + public void setupBaseFhirContextSensitive() { + FhirGlobalPropertyHolder.reset(); } - } diff --git a/api/src/test/java/org/openmrs/module/fhir2/MockedGlobalPropertyServiceConfiguration.java b/api/src/test/java/org/openmrs/module/fhir2/MockedGlobalPropertyServiceConfiguration.java deleted file mode 100644 index 985e9b746e..0000000000 --- a/api/src/test/java/org/openmrs/module/fhir2/MockedGlobalPropertyServiceConfiguration.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.fhir2; - -import static org.mockito.Mockito.when; - -import org.mockito.Mockito; -import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -@Configuration -public class MockedGlobalPropertyServiceConfiguration { - - @Bean - @Primary - public FhirGlobalPropertyService getFhirGlobalPropertyService() { - FhirGlobalPropertyService globalPropertyService = Mockito.mock(FhirGlobalPropertyService.class); - when(globalPropertyService.getGlobalProperty("default_locale", "en_GB")).thenReturn("en_GB"); - return globalPropertyService; - } -} diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirAllergyIntoleranceDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirAllergyIntoleranceDaoImplTest.java index 31f05aa79c..ffa8e8ff7a 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirAllergyIntoleranceDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirAllergyIntoleranceDaoImplTest.java @@ -14,25 +14,19 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; -import org.hibernate.SessionFactory; import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; import org.openmrs.Allergen; import org.openmrs.AllergenType; import org.openmrs.Allergy; import org.openmrs.AllergyReaction; import org.openmrs.Concept; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; +import org.openmrs.module.fhir2.api.dao.FhirAllergyIntoleranceDao; import org.openmrs.module.fhir2.api.dao.FhirConceptDao; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirAllergyIntoleranceDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirAllergyIntoleranceDaoImplTest extends BaseFhirContextSensitiveTest { private static final String ALLERGY_INTOLERANCE_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirAllergyIntoleranceDaoImplTest_initial_data.xml"; @@ -43,22 +37,13 @@ public class FhirAllergyIntoleranceDaoImplTest extends BaseModuleContextSensitiv private static final String CODED_REACTION_UUID = "5087AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; @Autowired - @Qualifier("sessionFactory") - private SessionFactory sessionFactory; - - @Mock - private FhirGlobalPropertyService globalPropertyService; - - private FhirAllergyIntoleranceDaoImpl allergyDao; + private FhirAllergyIntoleranceDao allergyDao; @Autowired private FhirConceptDao conceptDao; @Before public void setup() throws Exception { - allergyDao = new FhirAllergyIntoleranceDaoImpl(); - allergyDao.setSessionFactory(sessionFactory); - allergyDao.setGlobalPropertyService(globalPropertyService); executeDataSet(ALLERGY_INTOLERANCE_INITIAL_DATA_XML); } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImplTest.java index c5c5193c7a..3697d234b3 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImplTest.java @@ -29,15 +29,12 @@ import org.openmrs.ConceptSource; import org.openmrs.api.ConceptService; import org.openmrs.api.context.Context; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.api.dao.FhirConceptDao; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirConceptDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirConceptDaoImplTest extends BaseFhirContextSensitiveTest { private static final String CONCEPT_DATA_XML = "org/openmrs/api/include/ConceptServiceTest-initialConcepts.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConceptSourceDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConceptSourceDaoImplTest.java index 6883624917..bd942e8a53 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConceptSourceDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConceptSourceDaoImplTest.java @@ -28,15 +28,12 @@ import org.junit.Test; import org.openmrs.ConceptSource; import org.openmrs.api.ConceptService; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirTestConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.model.FhirConceptSource; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirConceptSourceDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirConceptSourceDaoImplTest extends BaseFhirContextSensitiveTest { private static final String CONCEPT_SOURCE_FHIR_DATA = "org/openmrs/module/fhir2/api/dao/impl/FhirConceptSourceDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_Test.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_Test.java index 298e6755d3..fb300d705c 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_Test.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirConditionDaoImpl_Test.java @@ -26,14 +26,11 @@ import org.openmrs.ConditionVerificationStatus; import org.openmrs.api.ConceptService; import org.openmrs.api.PatientService; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirConditionDaoImpl_Test extends BaseModuleContextSensitiveTest { +public class FhirConditionDaoImpl_Test extends BaseFhirContextSensitiveTest { private static final String CONDITION_UUID = "2cc6880e-2c46-15e4-9038-a6c5e4d22fb7"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImplTest.java index bb8b8d2fdb..40aef82582 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirContactPointMapDaoImplTest.java @@ -26,15 +26,12 @@ import org.openmrs.api.LocationService; import org.openmrs.api.PersonService; import org.openmrs.api.ProviderService; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.api.FhirContactPointMapService; import org.openmrs.module.fhir2.model.FhirContactPointMap; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirContactPointMapDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirContactPointMapDaoImplTest extends BaseFhirContextSensitiveTest { @Autowired private SessionFactory sessionFactory; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirDiagnosticReportDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirDiagnosticReportDaoImplTest.java index 0ef6228617..bfe08bb2a1 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirDiagnosticReportDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirDiagnosticReportDaoImplTest.java @@ -23,15 +23,12 @@ import org.openmrs.api.ConceptService; import org.openmrs.api.ObsService; import org.openmrs.api.PatientService; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.model.FhirDiagnosticReport; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirDiagnosticReportDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirDiagnosticReportDaoImplTest extends BaseFhirContextSensitiveTest { private static final String DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirDiagnosticReportDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImplTest.java index c3a8601f1e..2a68af9819 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEncounterDaoImplTest.java @@ -29,16 +29,13 @@ import org.openmrs.Encounter; import org.openmrs.Order; import org.openmrs.api.context.Context; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirEncounterDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirEncounterDaoImplTest extends BaseFhirContextSensitiveTest { private static final String ENCOUNTER_UUID = "430bbb70-6a9c-4e1e-badb-9d1034b1b5e9"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEpisodeOfCareDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEpisodeOfCareDaoImplTest.java index 65813cbd2a..bf53a7ba0b 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEpisodeOfCareDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirEpisodeOfCareDaoImplTest.java @@ -18,14 +18,11 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.PatientProgram; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirEpisodeOfCareDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirEpisodeOfCareDaoImplTest extends BaseFhirContextSensitiveTest { private static final String ENCOUNTER_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirEpisodeOfCareDaoImpl_2_2Test_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirGroupDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirGroupDaoImplTest.java index 0914eac0bd..223b97062d 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirGroupDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirGroupDaoImplTest.java @@ -19,14 +19,11 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Cohort; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirGroupDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirGroupDaoImplTest extends BaseFhirContextSensitiveTest { private static final String COHORT_UUID = "1d64befb-3b2e-48e5-85f5-353d43e23e46"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirLocationDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirLocationDaoImplTest.java index 6e334353d9..f7af89d5ca 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirLocationDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirLocationDaoImplTest.java @@ -13,27 +13,22 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.mockito.Mockito.when; import java.util.List; -import org.hibernate.SessionFactory; import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; import org.openmrs.Location; import org.openmrs.LocationAttribute; import org.openmrs.LocationAttributeType; import org.openmrs.LocationTag; import org.openmrs.api.LocationService; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.customdatatype.datatype.FreeTextDatatype; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; +import org.openmrs.module.fhir2.api.dao.FhirLocationDao; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirLocationDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirLocationDaoImplTest extends BaseFhirContextSensitiveTest { private static final String LOCATION_UUID = "c0938432-1691-11df-97a5-7038c432"; @@ -47,20 +42,14 @@ public class FhirLocationDaoImplTest extends BaseModuleContextSensitiveTest { private static final String LOCATION_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirLocationDaoImplTest_initial_data.xml"; - private FhirLocationDaoImpl fhirLocationDao; - @Autowired - @Qualifier("sessionFactory") - private SessionFactory sessionFactory; + private FhirLocationDao fhirLocationDao; - @Mock - private LocationService locationService; + @Autowired + LocationService locationService; @Before public void setup() throws Exception { - fhirLocationDao = new FhirLocationDaoImpl(); - fhirLocationDao.setLocationService(locationService); - fhirLocationDao.setSessionFactory(sessionFactory); executeDataSet(LOCATION_INITIAL_DATA_XML); } @@ -94,8 +83,9 @@ public void getActiveAttributesByLocationAndAttributeTypeUuid_shouldReturnLocati public void getLocationAttributeTypeByUuid_shouldReturnAttributeType() { LocationAttributeType locationAttributeType = new LocationAttributeType(); locationAttributeType.setUuid(LOCATION_ATTRIBUTE_TYPE_UUID); - - when(locationService.getLocationAttributeTypeByUuid(LOCATION_ATTRIBUTE_TYPE_UUID)).thenReturn(locationAttributeType); + locationAttributeType.setName("Some Attribute"); + locationAttributeType.setDatatypeClassname(FreeTextDatatype.class.getName()); + locationService.saveLocationAttributeType(locationAttributeType); LocationAttributeType result = fhirLocationDao.getLocationAttributeTypeByUuid(LOCATION_ATTRIBUTE_TYPE_UUID); @@ -108,8 +98,7 @@ public void saveLocationTag_shouldSaveTag() { LocationTag locationTag = new LocationTag(); locationTag.setUuid(LOCATION_TAG_UUID); locationTag.setName(LOCATION_TAG_NAME); - - when(locationService.saveLocationTag(locationTag)).thenReturn(locationTag); + locationService.saveLocationTag(locationTag); LocationTag result = fhirLocationDao.saveLocationTag(locationTag); @@ -121,8 +110,7 @@ public void getLocationTagByName_shouldGetTag() { LocationTag locationTag = new LocationTag(); locationTag.setUuid(LOCATION_TAG_UUID); locationTag.setName(LOCATION_TAG_NAME); - - when(locationService.getLocationTagByName(LOCATION_TAG_NAME)).thenReturn(locationTag); + locationService.saveLocationTag(locationTag); LocationTag result = fhirLocationDao.getLocationTagByName(LOCATION_TAG_NAME); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationDaoImplTest.java index 611470c886..6a3b81f76e 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationDaoImplTest.java @@ -23,15 +23,12 @@ import org.openmrs.Concept; import org.openmrs.Drug; import org.openmrs.DrugIngredient; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.api.dao.FhirConceptDao; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirMedicationDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirMedicationDaoImplTest extends BaseFhirContextSensitiveTest { private static final String MEDICATION_UUID = "1085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImplTest.java index 28192ea838..d7a6666834 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImplTest.java @@ -31,16 +31,13 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.DrugOrder; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirMedicationRequestDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirMedicationRequestDaoImplTest extends BaseFhirContextSensitiveTest { private static final String DRUG_ORDER_UUID = "6d0ae116-707a-4629-9850-f15206e63ab0"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest.java index ff96f9f0aa..941feba293 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest.java @@ -21,16 +21,13 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Obs; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirObservationDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirObservationDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirObservationDaoImplTest extends BaseFhirContextSensitiveTest { private static final String OBS_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplPatientIdentifierTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplPatientIdentifierTest.java index 43b0059d81..cbfea9b1e7 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplPatientIdentifierTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplPatientIdentifierTest.java @@ -18,13 +18,10 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.PatientIdentifierType; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirPatientDaoImplPatientIdentifierTest extends BaseModuleContextSensitiveTest { +public class FhirPatientDaoImplPatientIdentifierTest extends BaseFhirContextSensitiveTest { private static final String PATIENT_IDENTIFIER_TYPE_NAME = "Test Identifier Type"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest.java index 104cf71a7f..93f6dcc404 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest.java @@ -24,15 +24,12 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Patient; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirPatientDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirPatientDaoImplTest extends BaseFhirContextSensitiveTest { private static final String PATIENT_UUID = "256ccf6d-6b41-455c-9be2-51ff4386ae76"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPatientIdentifierSystemDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPatientIdentifierSystemDaoImplTest.java index 87617f1604..621cf022b9 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPatientIdentifierSystemDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPatientIdentifierSystemDaoImplTest.java @@ -24,15 +24,12 @@ import org.junit.Test; import org.openmrs.PatientIdentifierType; import org.openmrs.api.PatientService; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.api.FhirPatientIdentifierSystemService; import org.openmrs.module.fhir2.model.FhirPatientIdentifierSystem; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirPatientIdentifierSystemDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirPatientIdentifierSystemDaoImplTest extends BaseFhirContextSensitiveTest { private FhirPatientIdentifierSystemDaoImpl dao; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPersonDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPersonDaoImplTest.java index 94b2820c9f..20381d8f48 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPersonDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPersonDaoImplTest.java @@ -24,14 +24,11 @@ import org.openmrs.Person; import org.openmrs.PersonAttribute; import org.openmrs.api.context.Context; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirPersonDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirPersonDaoImplTest extends BaseFhirContextSensitiveTest { private static final String PERSON_UUID = "61b38324-e2fd-4feb-95b7-9e9a2a4400df"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPractitionerDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPractitionerDaoImplTest.java index 778af68f93..565b427278 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPractitionerDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirPractitionerDaoImplTest.java @@ -19,14 +19,11 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.ProviderAttribute; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirPractitionerDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirPractitionerDaoImplTest extends BaseFhirContextSensitiveTest { private static final String PRACTITIONER_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirPractitionerDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirRelatedPersonDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirRelatedPersonDaoImplTest.java index 34cf96d728..b2d6d59ed5 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirRelatedPersonDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirRelatedPersonDaoImplTest.java @@ -18,14 +18,11 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Relationship; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirRelatedPersonDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirRelatedPersonDaoImplTest extends BaseFhirContextSensitiveTest { private static final String RELATIONSHIP_UUID = "c3c91630-8563-481b-8efa-48e10c139a3d"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java index 4132a482be..50498d49f6 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestDaoImplTest.java @@ -20,14 +20,11 @@ import org.junit.Test; import org.openmrs.OrderType; import org.openmrs.TestOrder; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirServiceRequestDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirServiceRequestDaoImplTest extends BaseFhirContextSensitiveTest { private static final String TEST_ORDER_UUID = "7d96f25c-4949-4f72-9931-d808fbc226de"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest.java index 4280ccc006..a92cb2e11d 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest.java @@ -10,7 +10,13 @@ package org.openmrs.module.fhir2.api.dao.impl; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; import java.time.LocalDateTime; import java.time.Month; @@ -24,18 +30,15 @@ import org.openmrs.Concept; import org.openmrs.api.ConceptService; import org.openmrs.api.db.hibernate.HibernateConceptDAO; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.model.FhirReference; import org.openmrs.module.fhir2.model.FhirTask; import org.openmrs.module.fhir2.model.FhirTaskInput; import org.openmrs.module.fhir2.model.FhirTaskOutput; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirTaskDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirTaskDaoImplTest extends BaseFhirContextSensitiveTest { private static final String TASK_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirUserDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirUserDaoImplTest.java index 17a42f7e4e..64aaa63c6e 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirUserDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirUserDaoImplTest.java @@ -17,14 +17,11 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.User; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirUserDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirUserDaoImplTest extends BaseFhirContextSensitiveTest { private static final String USER_NAME = "firstaccount"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirVisitDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirVisitDaoImplTest.java index 0c7e08cd21..7b8c76cf0f 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirVisitDaoImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirVisitDaoImplTest.java @@ -18,14 +18,11 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Visit; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirVisitDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirVisitDaoImplTest extends BaseFhirContextSensitiveTest { private static final String VISIT_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirVisitDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirClientServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirClientServiceImplTest.java index 7f7edd451b..198e08df9d 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirClientServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirClientServiceImplTest.java @@ -18,11 +18,9 @@ import ca.uhn.fhir.rest.client.api.IGenericClient; import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; public class FhirClientServiceImplTest { - @Mock private static final String R3_URL = "https://demo.openmrs.org/openmrs/ws/fhir2/R3"; private static final String R4_URL = "https://demo.openmrs.org/openmrs/ws/fhir2/R4"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirImmunizationServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirImmunizationServiceImplTest.java index dc44b33a31..4d6e2d47e6 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirImmunizationServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirImmunizationServiceImplTest.java @@ -13,7 +13,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hl7.fhir.r4.model.Patient.SP_IDENTIFIER; -import static org.mockito.Mockito.when; import static org.openmrs.module.fhir2.FhirConstants.ENCOUNTER; import static org.openmrs.module.fhir2.FhirConstants.PATIENT; import static org.openmrs.module.fhir2.FhirConstants.PRACTITIONER; @@ -43,17 +42,15 @@ import org.junit.Test; import org.openmrs.Obs; import org.openmrs.Provider; +import org.openmrs.api.AdministrationService; import org.openmrs.api.ObsService; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; import org.openmrs.module.fhir2.api.util.ImmunizationObsGroupHelper; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; +import org.springframework.beans.factory.annotation.Qualifier; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class FhirImmunizationServiceImplTest extends BaseModuleContextSensitiveTest { +public class FhirImmunizationServiceImplTest extends BaseFhirContextSensitiveTest { private static final String IMMUNIZATIONS_METADATA_XML = "org/openmrs/module/fhir2/Immunization_metadata.xml"; @@ -68,21 +65,21 @@ public class FhirImmunizationServiceImplTest extends BaseModuleContextSensitiveT private ObsService obsService; @Autowired - private FhirGlobalPropertyService globalPropertyService; + @Qualifier("adminService") + private AdministrationService administrationService; @Autowired private ImmunizationObsGroupHelper helper; @Before public void setup() throws Exception { - when(globalPropertyService.getGlobalProperty(FhirConstants.IMMUNIZATIONS_ENCOUNTER_TYPE_PROPERTY)) - .thenReturn("29c02aff-9a93-46c9-bf6f-48b552fcb1fa"); - when(globalPropertyService.getGlobalProperty(FhirConstants.ADMINISTERING_ENCOUNTER_ROLE_PROPERTY)) - .thenReturn("546cce2d-6d58-4097-ba92-206c1a2a0462"); - executeDataSet(IMMUNIZATIONS_METADATA_XML); executeDataSet(IMMUNIZATIONS_INITIAL_DATA_XML); executeDataSet(PRACTITIONER_INITIAL_DATA_XML); + administrationService.setGlobalProperty(FhirConstants.IMMUNIZATIONS_ENCOUNTER_TYPE_PROPERTY, + "29c02aff-9a93-46c9-bf6f-48b552fcb1fa"); + administrationService.setGlobalProperty(FhirConstants.ADMINISTERING_ENCOUNTER_ROLE_PROPERTY, + "546cce2d-6d58-4097-ba92-206c1a2a0462"); } /** diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/AllergyIntoleranceSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/AllergyIntoleranceSearchQueryTest.java index 36abad6bce..8db03f83f5 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/AllergyIntoleranceSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/AllergyIntoleranceSearchQueryTest.java @@ -23,12 +23,9 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.hamcrest.Matchers.not; -import static org.mockito.Mockito.when; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import ca.uhn.fhir.model.api.Include; @@ -48,18 +45,16 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Allergy; +import org.openmrs.api.AdministrationService; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; import org.openmrs.module.fhir2.api.dao.FhirAllergyIntoleranceDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.AllergyIntoleranceTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; +import org.springframework.beans.factory.annotation.Qualifier; -@ContextConfiguration(classes = { TestFhirSpringConfiguration.class }, inheritLocations = false) -public class AllergyIntoleranceSearchQueryTest extends BaseModuleContextSensitiveTest { +public class AllergyIntoleranceSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String ALLERGY_INTOLERANCE_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirAllergyIntoleranceDaoImplTest_initial_data.xml"; @@ -121,8 +116,6 @@ public class AllergyIntoleranceSearchQueryTest extends BaseModuleContextSensitiv private static final int END_INDEX = 10; - private static final Map SEVERITY_CONCEPT_UUIDS = new HashMap<>(); - @Autowired private FhirAllergyIntoleranceDao allergyDao; @@ -136,27 +129,16 @@ public class AllergyIntoleranceSearchQueryTest extends BaseModuleContextSensitiv private SearchQuery> searchQuery; @Autowired - private FhirGlobalPropertyService globalPropertyService; + @Qualifier("adminService") + private AdministrationService administrationService; @Before public void setup() throws Exception { executeDataSet(ALLERGY_INTOLERANCE_INITIAL_DATA_XML); - } - - @Before - public void setupMocks() { - initSeverityData(); - - when(globalPropertyService.getGlobalProperties(FhirConstants.GLOBAL_PROPERTY_MILD, - FhirConstants.GLOBAL_PROPERTY_MODERATE, FhirConstants.GLOBAL_PROPERTY_SEVERE, - FhirConstants.GLOBAL_PROPERTY_OTHER)).thenReturn(SEVERITY_CONCEPT_UUIDS); - } - - private void initSeverityData() { - SEVERITY_CONCEPT_UUIDS.put(FhirConstants.GLOBAL_PROPERTY_MILD, SEVERITY_MILD_CONCEPT_UUID); - SEVERITY_CONCEPT_UUIDS.put(FhirConstants.GLOBAL_PROPERTY_MODERATE, SEVERITY_MODERATE_CONCEPT_UUID); - SEVERITY_CONCEPT_UUIDS.put(FhirConstants.GLOBAL_PROPERTY_SEVERE, SEVERITY_SEVERE_CONCEPT_UUID); - SEVERITY_CONCEPT_UUIDS.put(FhirConstants.GLOBAL_PROPERTY_OTHER, SEVERITY_NULL_CONCEPT_UUID); + administrationService.setGlobalProperty(FhirConstants.GLOBAL_PROPERTY_MILD, SEVERITY_MILD_CONCEPT_UUID); + administrationService.setGlobalProperty(FhirConstants.GLOBAL_PROPERTY_MODERATE, SEVERITY_MODERATE_CONCEPT_UUID); + administrationService.setGlobalProperty(FhirConstants.GLOBAL_PROPERTY_SEVERE, SEVERITY_SEVERE_CONCEPT_UUID); + administrationService.setGlobalProperty(FhirConstants.GLOBAL_PROPERTY_OTHER, SEVERITY_NULL_CONCEPT_UUID); } private List get(IBundleProvider results) { diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/ConditionSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/ConditionSearchQueryTest.java index 78dd6219e6..bc43437942 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/ConditionSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/ConditionSearchQueryTest.java @@ -24,12 +24,10 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Mockito.when; import static org.openmrs.test.OpenmrsMatchers.hasId; import static org.openmrs.test.OpenmrsMatchers.hasUuid; -import java.time.LocalDateTime; -import java.time.Month; +import java.util.Date; import java.util.HashSet; import java.util.List; @@ -47,24 +45,22 @@ import ca.uhn.fhir.rest.param.TokenAndListParam; import ca.uhn.fhir.rest.param.TokenOrListParam; import ca.uhn.fhir.rest.param.TokenParam; +import org.apache.commons.lang.time.DateUtils; import org.hamcrest.Matchers; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.Patient; import org.junit.Before; import org.junit.Test; import org.openmrs.Condition; +import org.openmrs.api.ConditionService; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirConditionDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.ConditionTranslator; -import org.openmrs.module.fhir2.api.util.LocalDateTimeFactory; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class ConditionSearchQueryTest extends BaseModuleContextSensitiveTest { +public class ConditionSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String CONDITION_UUID = "604953c5-b5c6-4e1e-be95-e37d8f392046"; @@ -143,7 +139,7 @@ public class ConditionSearchQueryTest extends BaseModuleContextSensitiveTest { private SearchQuery, ConditionTranslator, SearchQueryInclude> searchQuery; @Autowired - private LocalDateTimeFactory localDateTimeFactory; + ConditionService conditionService; @Before public void setup() { @@ -649,12 +645,15 @@ public void searchForConditions_shouldReturnConditionByUnboundedOnsetDate() { @Test public void searchForConditions_shouldReturnConditionByOnsetAgeLessThanHour() { + Condition condition = conditionService.getConditionByUuid(CONDITION_UUID); + Date onsetDate = DateUtils.addMinutes(new Date(), -45); + condition.setOnsetDate(onsetDate); + conditionService.saveCondition(condition); + QuantityOrListParam orList = new QuantityOrListParam(); - orList.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 1.5, "", "h")); + orList.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 1, "", "h")); QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); - when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 19, 10, 0)); - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, onsetAgeParam); @@ -670,12 +669,15 @@ public void searchForConditions_shouldReturnConditionByOnsetAgeLessThanHour() { @Test public void searchForConditions_shouldReturnConditionByOnsetAgeEqualHour() { + Condition condition = conditionService.getConditionByUuid(CONDITION_UUID); + Date onsetDate = DateUtils.addHours(new Date(), -3); + condition.setOnsetDate(onsetDate); + conditionService.saveCondition(condition); + QuantityOrListParam orList = new QuantityOrListParam(); orList.addOr(new QuantityParam(ParamPrefixEnum.EQUAL, 3, "", "h")); QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); - when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 22, 0, 0)); - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, onsetAgeParam); @@ -691,14 +693,17 @@ public void searchForConditions_shouldReturnConditionByOnsetAgeEqualHour() { @Test public void searchForConditions_shouldReturnConditionByOnsetAgeIntervalDay() { + Condition condition = conditionService.getConditionByUuid(CONDITION_UUID); + Date onsetDate = DateUtils.addDays(new Date(), -9); + condition.setOnsetDate(onsetDate); + conditionService.saveCondition(condition); + QuantityOrListParam orListLower = new QuantityOrListParam(); QuantityOrListParam orListUpper = new QuantityOrListParam(); orListLower.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 11, "", "d")); orListUpper.addOr(new QuantityParam(ParamPrefixEnum.GREATERTHAN, 8, "", "d")); QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orListLower).addAnd(orListUpper); - when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 22, 22, 0, 0)); - SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, onsetAgeParam); @@ -719,7 +724,7 @@ public void searchForConditions_shouldReturnConditionByOnsetAgeOrWeekMonthYear() orList.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 2, "", "wk")); QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); - when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 22, 0, 0)); + //when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 22, 0, 0)); SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, onsetAgeParam); @@ -738,7 +743,7 @@ public void searchForConditions_shouldReturnConditionByOnsetAgeExceptionForWrong orList.addOr(new QuantityParam(ParamPrefixEnum.LESSTHAN, 1.5, "", "WRONG_UNIT")); QuantityAndListParam onsetAgeParam = new QuantityAndListParam().addAnd(orList); - when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 19, 10, 0)); + //when(localDateTimeFactory.now()).thenReturn(LocalDateTime.of(2020, Month.MARCH, 13, 19, 10, 0)); SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, onsetAgeParam); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/DiagnosticReportSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/DiagnosticReportSearchQueryTest.java index 6ecce7fa1c..fce59dd699 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/DiagnosticReportSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/DiagnosticReportSearchQueryTest.java @@ -54,18 +54,15 @@ import org.hl7.fhir.r4.model.Patient; import org.junit.Before; import org.junit.Test; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirDiagnosticReportDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.DiagnosticReportTranslator; import org.openmrs.module.fhir2.model.FhirDiagnosticReport; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class DiagnosticReportSearchQueryTest extends BaseModuleContextSensitiveTest { +public class DiagnosticReportSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirDiagnosticReportDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/EncounterSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/EncounterSearchQueryTest.java index 82bd189e25..de39849113 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/EncounterSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/EncounterSearchQueryTest.java @@ -54,17 +54,14 @@ import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.ServiceRequest; import org.junit.Test; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirEncounterDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.EncounterTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class EncounterSearchQueryTest extends BaseModuleContextSensitiveTest { +public class EncounterSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String ENC_UUID = "eec646cb-c847-45a7-98bc-91c8c4f70add"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/GroupSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/GroupSearchQueryTest.java index 1764b9e2c5..0bf235051c 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/GroupSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/GroupSearchQueryTest.java @@ -28,17 +28,14 @@ import org.hl7.fhir.r4.model.Practitioner; import org.junit.Before; import org.junit.Test; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirGroupDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.GroupTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class GroupSearchQueryTest extends BaseModuleContextSensitiveTest { +public class GroupSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String COHORT_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirCohortDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/LocationSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/LocationSearchQueryTest.java index 0551004315..eb0ff3f44f 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/LocationSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/LocationSearchQueryTest.java @@ -48,19 +48,16 @@ import org.hl7.fhir.r4.model.Location; import org.junit.Before; import org.junit.Test; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirLocationDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.LocationTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.openmrs.test.SkipBaseSetup; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; @SkipBaseSetup -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class LocationSearchQueryTest extends BaseModuleContextSensitiveTest { +public class LocationSearchQueryTest extends BaseFhirContextSensitiveTest { public static final String LOCATION_UUID = "5db6ae3c-867e-45a0-a1ce-f86219b64e1c"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/MedicationRequestSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/MedicationRequestSearchQueryTest.java index 6f79e60069..1339bbddc5 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/MedicationRequestSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/MedicationRequestSearchQueryTest.java @@ -44,15 +44,13 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.DrugOrder; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.FhirTestConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirMedicationRequestDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.MedicationRequestTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; /* * Notes on test data: @@ -70,8 +68,7 @@ * Total numbers of non-voided, non-discontinued orders = (10 - 2) + (5 - 2) = 11 * Total number of active orders (non-voided, non-discontunue, not stopped and not expired) = (10 - 5) + (5 - 5) = 5 */ -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class MedicationRequestSearchQueryTest extends BaseModuleContextSensitiveTest { +public class MedicationRequestSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String MEDICATION_REQUEST_DATA_XMLS = "org/openmrs/module/fhir2/api/dao/impl/FhirMedicationRequestDaoImpl_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/MedicationSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/MedicationSearchQueryTest.java index 2448ef0e0f..8ed6fe0814 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/MedicationSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/MedicationSearchQueryTest.java @@ -38,17 +38,14 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Drug; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirMedicationDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.MedicationTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class MedicationSearchQueryTest extends BaseModuleContextSensitiveTest { +public class MedicationSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String MEDICATION_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirMedicationDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/ObservationSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/ObservationSearchQueryTest.java index b34f3a541a..f501e6932e 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/ObservationSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/ObservationSearchQueryTest.java @@ -69,19 +69,16 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Obs; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.FhirTestConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirEncounterDao; import org.openmrs.module.fhir2.api.dao.FhirObservationDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.ObservationTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class ObservationSearchQueryTest extends BaseModuleContextSensitiveTest { +public class ObservationSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String OBS_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirObservationDaoImplTest_initial_data_suppl.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/PatientSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/PatientSearchQueryTest.java index 39477c348e..57d3f13c89 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/PatientSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/PatientSearchQueryTest.java @@ -28,7 +28,6 @@ import static org.hamcrest.Matchers.startsWith; import static org.hl7.fhir.r4.model.Patient.SP_FAMILY; import static org.hl7.fhir.r4.model.Patient.SP_GIVEN; -import static org.mockito.Mockito.when; import static org.openmrs.module.fhir2.matchers.FhirMatchers.isDeceased; import java.util.HashMap; @@ -58,18 +57,14 @@ import org.hl7.fhir.r4.model.ServiceRequest; import org.junit.Before; import org.junit.Test; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; import org.openmrs.module.fhir2.api.dao.FhirPatientDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.PatientTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class PatientSearchQueryTest extends BaseModuleContextSensitiveTest { +public class PatientSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String[] PATIENT_SEARCH_DATA_FILES = { "org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest_initial_data.xml", @@ -148,9 +143,6 @@ public class PatientSearchQueryTest extends BaseModuleContextSensitiveTest { @Autowired private SearchQueryInclude searchQueryInclude; - @Autowired - private FhirGlobalPropertyService globalPropertyService; - @Autowired private SearchQuery> searchQuery; @@ -161,15 +153,6 @@ public void setup() throws Exception { } } - @Before - public void setupMocks() { - SEVERITY_CONCEPT_UUIDS.put(FhirConstants.GLOBAL_PROPERTY_SEVERE, SEVERITY_SEVERE_CONCEPT_UUID); - - when(globalPropertyService.getGlobalProperties(FhirConstants.GLOBAL_PROPERTY_MILD, - FhirConstants.GLOBAL_PROPERTY_MODERATE, FhirConstants.GLOBAL_PROPERTY_SEVERE, - FhirConstants.GLOBAL_PROPERTY_OTHER)).thenReturn(SEVERITY_CONCEPT_UUIDS); - } - private IBundleProvider search(SearchParameterMap theParams) { return searchQuery.getQueryResults(theParams, dao, translator, searchQueryInclude); } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/PersonSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/PersonSearchQueryTest.java index 57f37f3619..2688e4b706 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/PersonSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/PersonSearchQueryTest.java @@ -60,17 +60,14 @@ import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; import org.junit.Test; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirPersonDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.PersonTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class PersonSearchQueryTest extends BaseModuleContextSensitiveTest { +public class PersonSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String ADDRESS_SEARCH_FILE = "org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest_address_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/PractitionerSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/PractitionerSearchQueryTest.java index 1ee311ba75..12db416dfc 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/PractitionerSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/PractitionerSearchQueryTest.java @@ -46,17 +46,14 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Provider; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirPractitionerDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.PractitionerTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class PractitionerSearchQueryTest extends BaseModuleContextSensitiveTest { +public class PractitionerSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String PRACTITIONER_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirPractitionerDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/RelatedPersonSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/RelatedPersonSearchQueryTest.java index 14d70c5906..a173554f76 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/RelatedPersonSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/RelatedPersonSearchQueryTest.java @@ -51,17 +51,14 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Relationship; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirRelatedPersonDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.RelatedPersonTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class RelatedPersonSearchQueryTest extends BaseModuleContextSensitiveTest { +public class RelatedPersonSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String RELATIONSHIP_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirRelatedPersonDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java index eb88447973..46fd096e10 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/ServiceRequestSearchQueryTest.java @@ -46,18 +46,15 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.TestOrder; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.FhirTestConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirServiceRequestDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.ServiceRequestTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class ServiceRequestSearchQueryTest extends BaseModuleContextSensitiveTest { +public class ServiceRequestSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String TEST_ORDER_INITIAL_DATA = "org/openmrs/module/fhir2/api/dao/impl/FhirServiceRequestTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/TaskSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/TaskSearchQueryTest.java index 0eafbe65b0..f7951270ad 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/TaskSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/TaskSearchQueryTest.java @@ -48,18 +48,15 @@ import org.hl7.fhir.r4.model.Task; import org.junit.Before; import org.junit.Test; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirTaskDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.TaskTranslator; import org.openmrs.module.fhir2.model.FhirTask; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class TaskSearchQueryTest extends BaseModuleContextSensitiveTest { +public class TaskSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String TASK_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirTaskDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/UserSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/UserSearchQueryTest.java index 45498be2ff..0b50973908 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/UserSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/UserSearchQueryTest.java @@ -48,17 +48,14 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.User; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirUserDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.PractitionerTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class UserSearchQueryTest extends BaseModuleContextSensitiveTest { +public class UserSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String USER_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirUserDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/ValueSetSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/ValueSetSearchQueryTest.java index 18eb8b5ed5..5da33aecbb 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/ValueSetSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/ValueSetSearchQueryTest.java @@ -28,17 +28,14 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Concept; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirConceptDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.ValueSetTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class ValueSetSearchQueryTest extends BaseModuleContextSensitiveTest { +public class ValueSetSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String CONCEPT_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirConceptDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/search/VisitSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/VisitSearchQueryTest.java index c8d8cc47a2..d19a97a8fe 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/search/VisitSearchQueryTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/search/VisitSearchQueryTest.java @@ -41,17 +41,14 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Visit; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.dao.FhirVisitDao; import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; import org.openmrs.module.fhir2.api.translators.EncounterTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class VisitSearchQueryTest extends BaseModuleContextSensitiveTest { +public class VisitSearchQueryTest extends BaseFhirContextSensitiveTest { private static final String VISIT_INITIAL_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirVisitDaoImplTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/DurationUnitTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/DurationUnitTranslatorImplTest.java index c02d38033d..165c06733b 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/DurationUnitTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/DurationUnitTranslatorImplTest.java @@ -19,14 +19,11 @@ import org.junit.Test; import org.openmrs.Concept; import org.openmrs.api.ConceptService; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.api.translators.DurationUnitTranslator; -import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class DurationUnitTranslatorImplTest extends BaseModuleContextSensitiveTest { +public class DurationUnitTranslatorImplTest extends BaseFhirContextSensitiveTest { private static final String DURATION_UNIT_CONCEPT_DATA = "org/openmrs/module/fhir2/mapping/FhirDurationUnitTranslatorTest_initial_data.xml"; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EncounterPeriodTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EncounterPeriodTranslatorImplTest.java index 5167c86c33..11a13e4192 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EncounterPeriodTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/EncounterPeriodTranslatorImplTest.java @@ -16,7 +16,6 @@ import java.util.Date; -import junit.framework.TestCase; import org.hl7.fhir.r4.model.Period; import org.junit.Before; import org.junit.Test; @@ -26,7 +25,7 @@ import org.openmrs.module.fhir2.api.translators.EncounterPeriodTranslator; @RunWith(MockitoJUnitRunner.class) -public class EncounterPeriodTranslatorImplTest extends TestCase { +public class EncounterPeriodTranslatorImplTest { private EncounterPeriodTranslator encounterPeriodTranslator; diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationCategoryTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationCategoryTranslatorImplTest.java index 60d7f5d827..db0b8e5661 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationCategoryTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationCategoryTranslatorImplTest.java @@ -13,21 +13,16 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; -import org.hibernate.SessionFactory; import org.hl7.fhir.r4.model.CodeableConcept; import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; import org.openmrs.Concept; import org.openmrs.ConceptClass; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; -import org.openmrs.module.fhir2.api.mappings.ObservationCategoryMap; -import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; +import org.openmrs.module.fhir2.api.translators.ObservationCategoryTranslator; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -@ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) -public class ObservationCategoryTranslatorImplTest extends BaseModuleContextSensitiveTest { +public class ObservationCategoryTranslatorImplTest extends BaseFhirContextSensitiveTest { private final String OBSERVATION_CATEGORY_CONCEPT_CLASS_DATA = "org/openmrs/module/fhir2/mapping/FhirObservationCategoryTest_initial_data.xml"; @@ -37,27 +32,17 @@ public class ObservationCategoryTranslatorImplTest extends BaseModuleContextSens private final String EXAM_CONCEPT_CLASS_UUID = "8d491a9a-c2cc-11de-8d13-0010c6dffd0f"; - @Mock - private ObservationCategoryMap categoryMap; - - @Autowired - private SessionFactory sessionFactory; - private Concept concept; private CodeableConcept codeableConcept; - private ObservationCategoryTranslatorImpl observationCategoryTranslator; + @Autowired + ObservationCategoryTranslator observationCategoryTranslator; @Before public void setup() throws Exception { - observationCategoryTranslator = new ObservationCategoryTranslatorImpl(); - categoryMap = new ObservationCategoryMap(); - concept = new Concept(); - categoryMap.setSessionFactory(sessionFactory); - observationCategoryTranslator.setCategoryMap(categoryMap); - executeDataSet(OBSERVATION_CATEGORY_CONCEPT_CLASS_DATA); + concept = new Concept(); } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationValueTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationValueTranslatorImplTest.java index 335c05dace..bbb1d200b4 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationValueTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationValueTranslatorImplTest.java @@ -15,11 +15,9 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.openmrs.module.fhir2.FhirConstants.RX_NORM_SYSTEM_URI; import static org.openmrs.module.fhir2.FhirConstants.UCUM_SYSTEM_URI; -import static org.powermock.api.mockito.PowerMockito.mockStatic; import java.util.Date; @@ -35,37 +33,73 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.Concept; -import org.openmrs.ConceptDatatype; import org.openmrs.ConceptNumeric; import org.openmrs.Obs; import org.openmrs.api.ConceptService; -import org.openmrs.api.context.Context; -import org.openmrs.module.fhir2.api.translators.ConceptTranslator; -import org.powermock.core.classloader.annotations.PrepareOnlyThisForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.openmrs.module.fhir2.api.dao.FhirConceptSourceDao; +import org.openmrs.module.fhir2.api.dao.impl.FhirConceptDaoImpl; +import org.openmrs.module.fhir2.api.dao.impl.FhirConceptSourceDaoImpl; +import org.openmrs.module.fhir2.api.impl.FhirConceptServiceImpl; +import org.openmrs.module.fhir2.api.impl.FhirConceptSourceServiceImpl; -@RunWith(PowerMockRunner.class) -@PrepareOnlyThisForTest({ Context.class }) +@RunWith(MockitoJUnitRunner.class) public class ObservationValueTranslatorImplTest { private static final String CONCEPT_VALUE_UUID = "12345-abcde-54321"; private static final String OBS_STRING = "An ingenious observation"; - @Mock - private ConceptTranslator conceptTranslator; + private ConceptTranslatorImpl conceptTranslator; @Mock private ObservationQuantityCodingTranslatorImpl quantityCodingTranslator; + @Mock + ConceptService conceptService; + private Obs obs; private ObservationValueTranslatorImpl obsValueTranslator; @Before public void setup() { - obsValueTranslator = new ObservationValueTranslatorImpl(); + FhirConceptDaoImpl fhirConceptDao = new FhirConceptDaoImpl(); + fhirConceptDao.setConceptService(conceptService); + FhirConceptServiceImpl fhirConceptService = new FhirConceptServiceImpl(); + fhirConceptService.setDao(fhirConceptDao); + FhirConceptSourceDao fhirConceptSourceDao = new FhirConceptSourceDaoImpl(); + FhirConceptSourceServiceImpl fhirConceptSourceService = new FhirConceptSourceServiceImpl(); + fhirConceptSourceService.setDao(fhirConceptSourceDao); + conceptTranslator = new ConceptTranslatorImpl(); + conceptTranslator.setConceptService(fhirConceptService); + conceptTranslator.setConceptSourceService(fhirConceptSourceService); + obsValueTranslator = new ObservationValueTranslatorImpl() { + + @Override + protected Boolean getValueBoolean(Obs obs) { + if (obs.getValueCoded() != null) { + if (obs.getValueCoded().equals(conceptService.getTrueConcept())) { + return true; + } else if (obs.getValueCoded().equals(conceptService.getFalseConcept())) { + return false; + } + } + return null; + } + + @Override + protected void setValueBoolean(Obs obs, Boolean valueBoolean) { + if (valueBoolean == Boolean.TRUE) { + obs.setValueCoded(conceptService.getTrueConcept()); + } else if (valueBoolean == Boolean.FALSE) { + obs.setValueCoded(conceptService.getFalseConcept()); + } else { + obs.setValueCoded(null); + } + } + }; obsValueTranslator.setConceptTranslator(conceptTranslator); obsValueTranslator.setQuantityCodingTranslator(quantityCodingTranslator); @@ -78,15 +112,12 @@ public void toFhirResource_shouldConvertObsWithCodedValueToCodeableConcept() { concept.setUuid(CONCEPT_VALUE_UUID); obs.setValueCoded(concept); - CodeableConcept codeableConcept = new CodeableConcept(); - codeableConcept.setId(CONCEPT_VALUE_UUID); - when(conceptTranslator.toFhirResource(concept)).thenReturn(codeableConcept); - Type result = obsValueTranslator.toFhirResource(obs); assertThat(result, notNullValue()); assertThat(result, instanceOf(CodeableConcept.class)); - assertThat(result.getId(), equalTo(CONCEPT_VALUE_UUID)); + CodeableConcept codeableConceptResult = (CodeableConcept) result; + assertThat(codeableConceptResult.getCodingFirstRep().getCode(), equalTo(CONCEPT_VALUE_UUID)); } @Test @@ -171,20 +202,13 @@ public void toFhirResource_shouldConvertObsWithCommonUCUMUnitsToQuantityWithUCUM @Test public void toFhirResource_shouldConvertObsWithBooleanValueToBoolean() { - mockStatic(Context.class); Concept trueConcept = new Concept(); trueConcept.setId(1046); - ConceptService conceptService = mock(ConceptService.class); - when(Context.getConceptService()).thenReturn(conceptService); when(conceptService.getTrueConcept()).thenReturn(trueConcept); - ConceptDatatype booleanDatatype = mock(ConceptDatatype.class); - when(booleanDatatype.isBoolean()).thenReturn(true); - Concept obsConcept = new Concept(); - obsConcept.setDatatype(booleanDatatype); obs.setConcept(obsConcept); - obs.setValueBoolean(true); + obs.setValueCoded(conceptService.getTrueConcept()); Type result = obsValueTranslator.toFhirResource(obs); @@ -214,11 +238,11 @@ public void toFhirResource_shouldReturnNullIfObsIsNull() { @Test public void toOpenmrsType_shouldConvertCodeableConceptToConcept() { CodeableConcept codeableConcept = new CodeableConcept(); - codeableConcept.setId(CONCEPT_VALUE_UUID); + codeableConcept.addCoding(new Coding(null, CONCEPT_VALUE_UUID, CONCEPT_VALUE_UUID)); Concept concept = new Concept(); concept.setUuid(CONCEPT_VALUE_UUID); - when(conceptTranslator.toOpenmrsType(codeableConcept)).thenReturn(concept); + when(conceptService.getConceptByUuid(CONCEPT_VALUE_UUID)).thenReturn(concept); Obs result = obsValueTranslator.toOpenmrsType(obs, codeableConcept); @@ -262,18 +286,11 @@ public void toOpenmrsType_shouldConvertQuantityToNumericValue() { @Test public void toOpenmrsType_shouldConvertBooleanToBooleanValue() { - mockStatic(Context.class); Concept trueConcept = new Concept(); trueConcept.setId(1046); - ConceptService conceptService = mock(ConceptService.class); - when(Context.getConceptService()).thenReturn(conceptService); when(conceptService.getTrueConcept()).thenReturn(trueConcept); - ConceptDatatype booleanDatatype = mock(ConceptDatatype.class); - when(booleanDatatype.isBoolean()).thenReturn(true); Concept obsConcept = new Concept(); - obsConcept.setDatatype(booleanDatatype); - obs.setConcept(obsConcept); BooleanType booleanType = new BooleanType(); @@ -282,7 +299,7 @@ public void toOpenmrsType_shouldConvertBooleanToBooleanValue() { Obs result = obsValueTranslator.toOpenmrsType(obs, booleanType); assertThat(result, notNullValue()); - assertThat(result.getValueBoolean(), is(true)); + assertThat(result.getValueCoded(), is(conceptService.getTrueConcept())); } @Test diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PersonNameTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PersonNameTranslatorImplTest.java index b266838e9f..5cea644188 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PersonNameTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PersonNameTranslatorImplTest.java @@ -16,26 +16,18 @@ import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Arrays; -import java.util.Collections; import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.HumanName; import org.hl7.fhir.r4.model.StringType; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.PersonName; -import org.openmrs.api.AdministrationService; -import org.openmrs.api.context.ServiceContext; -import org.openmrs.layout.name.NameSupport; -import org.openmrs.layout.name.NameTemplate; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.serialization.SerializationException; -import org.openmrs.serialization.SimpleXStreamSerializer; +@RunWith(MockitoJUnitRunner.class) public class PersonNameTranslatorImplTest { private static final String PERSON_NAME_UUID = "123456-abcdef-123456"; @@ -163,44 +155,6 @@ public void shouldOnlyCreateOneExtensionForExtensibleAttributes() { assertThat(extension.getExtension().size(), greaterThan(1)); } - @Test - public void shouldUseDefaultNameTemplateToSetNameText() throws SerializationException { - AdministrationService administrationService = mock(AdministrationService.class); - ServiceContext.getInstance().setAdministrationService(administrationService); - when(administrationService.getGlobalProperty("layout.name.format")).thenReturn("test"); - - NameSupport nameSupportInstance = new NameSupport(); - NameTemplate customNameTemplate = new SimpleXStreamSerializer() - .deserialize("\n" + " test\n" - + " Test Name Format\n" + " \n" - + " \n" - + " \n" - + " \n" + " \n" - + " \n" + " \n" - + " \n" - + " \n" + " \n" - + " \n" + " givenName\n" + " familyName\n" - + " middleName\n" + " \n" + " \n" - + " givenName\n" + " familyName\n" - + " \n" + "", - NameTemplate.class); - nameSupportInstance.setLayoutTemplates(Collections.singletonList(customNameTemplate)); - nameSupportInstance.setSpecialTokens(Arrays.asList("prefix", "givenName", "middleName", "familyNamePrefix", - "familyNameSuffix", "familyName2", "familyName", "degree")); - - PersonName name = new PersonName(); - name.setGivenName(PERSON_GIVEN_NAME); - name.setMiddleName(PERSON_MIDDLE_NAME); - name.setFamilyName(PERSON_FAMILY_NAME); - - HumanName fhirName = personNameTranslator.toFhirResource(name); - - assertThat(fhirName, notNullValue()); - assertThat(fhirName.getTextElement(), notNullValue()); - assertThat(fhirName.getTextElement().getValue(), - equalTo(PERSON_GIVEN_NAME + " " + PERSON_FAMILY_NAME + " " + PERSON_MIDDLE_NAME)); - } - @Test public void shouldConvertHumanNameToPersonName() { HumanName name = new HumanName(); diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ValueSetTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ValueSetTranslatorImplTest.java index 41699bf26b..e1394d810d 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ValueSetTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ValueSetTranslatorImplTest.java @@ -20,11 +20,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.Optional; import org.hl7.fhir.r4.model.ValueSet; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.Concept; import org.openmrs.ConceptDescription; import org.openmrs.ConceptMap; @@ -33,18 +34,15 @@ import org.openmrs.ConceptReferenceTerm; import org.openmrs.ConceptSet; import org.openmrs.ConceptSource; -import org.openmrs.api.ConceptService; -import org.openmrs.api.context.ServiceContext; import org.openmrs.module.fhir2.FhirTestConstants; import org.openmrs.module.fhir2.api.FhirConceptSourceService; import org.openmrs.module.fhir2.model.FhirConceptSource; +@RunWith(MockitoJUnitRunner.class) public class ValueSetTranslatorImplTest { private static final String CONCEPT_UUID = "0f97e14e-cdc2-49ac-9255-b5126f8a5147"; - private ConceptService conceptService; - private FhirConceptSourceService conceptSourceService; private Concept concept; @@ -53,7 +51,6 @@ public class ValueSetTranslatorImplTest { @Before public void setup() { - conceptService = mock(ConceptService.class); conceptSourceService = mock(FhirConceptSourceService.class); concept = mock(Concept.class); valueSetTranslator.setConceptSourceService(conceptSourceService); @@ -61,9 +58,6 @@ public void setup() { @Test public void shouldTranslateConceptSetToValueSet() { - when(conceptService.getDefaultConceptMapType()).thenReturn(new ConceptMapType()); - ServiceContext.getInstance().setConceptService(conceptService); - ConceptName conceptName = new ConceptName(); conceptName.setName("test"); @@ -84,8 +78,6 @@ public void shouldTranslateConceptSetToValueSet() { when(conceptMap.getConceptReferenceTerm()).thenReturn(conceptReferenceTerm); when(conceptMap.getConceptMapType()).thenReturn(conceptMapType); when(conceptReferenceTerm.getConceptSource()).thenReturn(conceptSource); - when(conceptReferenceTerm.getCode()).thenReturn("1000-1"); - when(conceptSource.getName()).thenReturn("LOINC"); concept1.addConceptMapping(conceptMap); FhirConceptSource loinc = new FhirConceptSource(); @@ -93,7 +85,6 @@ public void shouldTranslateConceptSetToValueSet() { loincConceptSource.setName("LOINC"); loinc.setConceptSource(loincConceptSource); loinc.setUrl(FhirTestConstants.LOINC_SYSTEM_URL); - when(conceptSourceService.getFhirConceptSource(loincConceptSource)).thenReturn(Optional.of(loinc)); ConceptSet conceptSet = new ConceptSet(); conceptSet.setConceptSet(concept); diff --git a/api/src/test/java/org/openmrs/module/fhir2/providers/BaseFhirProvenanceResourceTest.java b/api/src/test/java/org/openmrs/module/fhir2/providers/BaseFhirProvenanceResourceTest.java index f03341f5d5..441dbead3c 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/providers/BaseFhirProvenanceResourceTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/providers/BaseFhirProvenanceResourceTest.java @@ -9,34 +9,17 @@ */ package org.openmrs.module.fhir2.providers; -import static org.mockito.Mockito.when; - import java.util.Arrays; import java.util.Date; import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.DomainResource; -import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.Provenance; -import org.hl7.fhir.r4.model.Reference; -import org.mockito.Mock; -import org.openmrs.User; import org.openmrs.module.fhir2.FhirConstants; -import org.openmrs.module.fhir2.api.translators.PractitionerReferenceTranslator; public abstract class BaseFhirProvenanceResourceTest { - private static final String PRACTITIONER_UUID = "2ffb1a5f-bcd3-4243-8f40-78edc2642789"; - - private static final String AGENT_TYPE_CODE = "author"; - - private static final String AGENT_TYPE_DISPLAY = "Author"; - - private static final String AGENT_ROLE_CODE = "AUT"; - - private static final String AGENT_ROLE_DISPLAY = "author"; - private static final String UPDATE = "Update"; private static final String REVISE = "revise"; @@ -45,9 +28,6 @@ public abstract class BaseFhirProvenanceResourceTest { private static final String CREATE_DISPLAY = "create"; - @Mock - private PractitionerReferenceTranslator practitionerReferenceTranslator; - public void setProvenanceResources(T resource) { resource.setContained(Arrays.asList(onCreateDataOperation(), onUpdateDataOperation())); } @@ -58,8 +38,7 @@ private Provenance onUpdateDataOperation() { coding.setDisplay(REVISE); coding.setSystem(FhirConstants.FHIR_TERMINOLOGY_DATA_OPERATION); - return new Provenance().setActivity(new CodeableConcept().addCoding(coding)).setRecorded(new Date()) - .addAgent(addAgent()); + return new Provenance().setActivity(new CodeableConcept().addCoding(coding)).setRecorded(new Date()); } private Provenance onCreateDataOperation() { @@ -68,32 +47,7 @@ private Provenance onCreateDataOperation() { coding.setDisplay(CREATE_DISPLAY); coding.setSystem(FhirConstants.FHIR_TERMINOLOGY_DATA_OPERATION); - return new Provenance().setActivity(new CodeableConcept().addCoding(coding)).setRecorded(new Date()) - .addAgent(addAgent()); - } - - private Provenance.ProvenanceAgentComponent addAgent() { - User user = new User(); - user.setUuid(PRACTITIONER_UUID); - Practitioner practitioner = new Practitioner(); - practitioner.setId(PRACTITIONER_UUID); - when(practitionerReferenceTranslator.toFhirResource(user)).thenReturn(createPractitionerReference()); - return new Provenance.ProvenanceAgentComponent().setType(addAgentType()).addRole(addAgentRole()) - .setWho(practitionerReferenceTranslator.toFhirResource(user)); - } - - private CodeableConcept addAgentType() { - return new CodeableConcept().addCoding(new Coding().setCode(AGENT_TYPE_CODE) - .setSystem(FhirConstants.FHIR_TERMINOLOGY_PROVENANCE_PARTICIPANT_TYPE).setDisplay(AGENT_TYPE_DISPLAY)); - } - - private CodeableConcept addAgentRole() { - return new CodeableConcept().addCoding(new Coding().setCode(AGENT_ROLE_CODE) - .setSystem(FhirConstants.FHIR_TERMINOLOGY_PARTICIPATION_TYPE).setDisplay(AGENT_ROLE_DISPLAY)); - } - - private Reference createPractitionerReference() { - return new Reference().setReference(FhirConstants.PRACTITIONER + "/" + PRACTITIONER_UUID); + return new Provenance().setActivity(new CodeableConcept().addCoding(coding)).setRecorded(new Date()); } } diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/BaseFhirIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/BaseFhirIntegrationTest.java index 0c2dc0b8a1..06fe70a903 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/BaseFhirIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/BaseFhirIntegrationTest.java @@ -41,6 +41,7 @@ import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IDomainResource; import org.junit.Before; +import org.openmrs.module.fhir2.api.util.FhirGlobalPropertyHolder; import org.openmrs.module.fhir2.web.servlet.FhirRestServlet; import org.openmrs.web.test.BaseModuleWebContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; @@ -86,6 +87,7 @@ public abstract class BaseFhirIntegrationTest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +