From 01ba8008b5195517d0b158cc9d04e57907471c5d Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 20 Dec 2024 09:26:48 -0500 Subject: [PATCH 01/10] Remove unnecessary and invalid mocks --- .../api/search/PatientSearchQueryTest.java | 70 +++++++++---------- 1 file changed, 33 insertions(+), 37 deletions(-) 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 39477c348..61fe995e8 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 @@ -9,34 +9,6 @@ */ package org.openmrs.module.fhir2.api.search; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.anyOf; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.everyItem; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -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; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortSpec; @@ -58,6 +30,7 @@ import org.hl7.fhir.r4.model.ServiceRequest; import org.junit.Before; import org.junit.Test; +import org.openmrs.api.AdministrationService; import org.openmrs.module.fhir2.FhirConstants; import org.openmrs.module.fhir2.TestFhirSpringConfiguration; import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; @@ -66,8 +39,36 @@ import org.openmrs.module.fhir2.api.translators.PatientTranslator; 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; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.everyItem; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +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.openmrs.module.fhir2.matchers.FhirMatchers.isDeceased; + @ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) public class PatientSearchQueryTest extends BaseModuleContextSensitiveTest { @@ -150,6 +151,10 @@ public class PatientSearchQueryTest extends BaseModuleContextSensitiveTest { @Autowired private FhirGlobalPropertyService globalPropertyService; + + @Autowired + @Qualifier("adminService") + private AdministrationService administrationService; @Autowired private SearchQuery> searchQuery; @@ -161,15 +166,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); } From d7037386de3b351fe4e935d37b4d22bea80e2b88 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 20 Dec 2024 12:24:22 -0500 Subject: [PATCH 02/10] Additional fixes to mocked context sensitive tests --- .../api/dao/impl/FhirConceptDaoImpl.java | 3 +- .../api/impl/FhirConceptServiceImpl.java | 3 +- .../impl/FhirConceptSourceServiceImpl.java | 3 +- .../impl/ObservationValueTranslatorImpl.java | 21 +++- .../MockedCalendarFactoryConfiguration.java | 27 ---- ...kedGlobalPropertyServiceConfiguration.java | 30 ----- .../FhirAllergyIntoleranceDaoImplTest.java | 16 +-- .../api/dao/impl/FhirLocationDaoImplTest.java | 29 ++--- .../api/impl/FhirClientServiceImplTest.java | 2 - .../impl/FhirImmunizationServiceImplTest.java | 16 +-- .../AllergyIntoleranceSearchQueryTest.java | 31 ++--- .../api/search/ConditionSearchQueryTest.java | 36 +++--- .../api/search/PatientSearchQueryTest.java | 56 ++++----- .../ObservationValueTranslatorImplTest.java | 87 +++++++------ .../web/servlet/FhirRestServletTest.java | 119 +++++++++--------- 15 files changed, 211 insertions(+), 268 deletions(-) delete mode 100644 api/src/test/java/org/openmrs/module/fhir2/MockedCalendarFactoryConfiguration.java delete mode 100644 api/src/test/java/org/openmrs/module/fhir2/MockedGlobalPropertyServiceConfiguration.java 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 f8a4941bd..2c1b7f565 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 e916afe8c..41ad8751c 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 1dc5c469a..822db0796 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 1088c5bcc..7d6836879 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/MockedCalendarFactoryConfiguration.java deleted file mode 100644 index 36e2d2b37..000000000 --- a/api/src/test/java/org/openmrs/module/fhir2/MockedCalendarFactoryConfiguration.java +++ /dev/null @@ -1,27 +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 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; - -@Configuration -public class MockedCalendarFactoryConfiguration { - - @Bean - @Primary - public LocalDateTimeFactory getCalendarFactory() { - return Mockito.mock(LocalDateTimeFactory.class); - } - -} 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 985e9b746..000000000 --- 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 31f05aa79..e5db4b87c 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,21 +14,18 @@ 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.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) @@ -43,22 +40,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/FhirLocationDaoImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/dao/impl/FhirLocationDaoImplTest.java index 6e334353d..e9020a8e9 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,23 +13,21 @@ 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.customdatatype.datatype.FreeTextDatatype; import org.openmrs.module.fhir2.TestFhirSpringConfiguration; +import org.openmrs.module.fhir2.api.dao.FhirLocationDao; 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) @@ -47,20 +45,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 +86,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 +101,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 +113,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/impl/FhirClientServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirClientServiceImplTest.java index 7f7edd451..198e08df9 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 dc44b33a3..6780386cb 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,13 +42,14 @@ 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.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.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; @ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) @@ -68,21 +68,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 36abad6bc..6a27867cf 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,14 +45,15 @@ import org.junit.Before; import org.junit.Test; import org.openmrs.Allergy; +import org.openmrs.api.AdministrationService; 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.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; @ContextConfiguration(classes = { TestFhirSpringConfiguration.class }, inheritLocations = false) @@ -121,8 +119,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 +132,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 78dd6219e..8c936dd03 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,18 +45,19 @@ 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.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; @@ -143,7 +142,7 @@ public class ConditionSearchQueryTest extends BaseModuleContextSensitiveTest { private SearchQuery, ConditionTranslator, SearchQueryInclude> searchQuery; @Autowired - private LocalDateTimeFactory localDateTimeFactory; + ConditionService conditionService; @Before public void setup() { @@ -649,12 +648,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 +672,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 +696,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 +727,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 +746,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/PatientSearchQueryTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/search/PatientSearchQueryTest.java index 61fe995e8..688c3fa49 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 @@ -9,6 +9,33 @@ */ package org.openmrs.module.fhir2.api.search; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.everyItem; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +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.openmrs.module.fhir2.matchers.FhirMatchers.isDeceased; + +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; import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortSpec; @@ -42,33 +69,6 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.anyOf; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.everyItem; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -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.openmrs.module.fhir2.matchers.FhirMatchers.isDeceased; - @ContextConfiguration(classes = TestFhirSpringConfiguration.class, inheritLocations = false) public class PatientSearchQueryTest extends BaseModuleContextSensitiveTest { @@ -151,7 +151,7 @@ public class PatientSearchQueryTest extends BaseModuleContextSensitiveTest { @Autowired private FhirGlobalPropertyService globalPropertyService; - + @Autowired @Qualifier("adminService") private AdministrationService administrationService; 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 335c05dac..bbb1d200b 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/omod/src/test/java/org/openmrs/module/fhir2/web/servlet/FhirRestServletTest.java b/omod/src/test/java/org/openmrs/module/fhir2/web/servlet/FhirRestServletTest.java index 5d7c01bd1..8629ce6f3 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/web/servlet/FhirRestServletTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/web/servlet/FhirRestServletTest.java @@ -14,6 +14,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import java.io.IOException; import java.io.PrintWriter; @@ -23,63 +28,59 @@ import org.mockito.MockitoAnnotations; import org.openmrs.util.OpenmrsClassLoader; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - public class FhirRestServletTest { - - @Mock - private HttpServletRequest mockRequest; - - @Mock - private HttpServletResponse mockResponse; - - @Mock - private ServletConfig mockServletConfig; - - @Mock - private PrintWriter mockWriter; - - private TestableFhirRestServlet servlet; - - @Before - public void setUp() throws ServletException, IOException { - MockitoAnnotations.initMocks(this); - - servlet = new TestableFhirRestServlet(); - - when(mockServletConfig.getServletContext()).thenReturn(mock(javax.servlet.ServletContext.class)); - when(mockResponse.getWriter()).thenReturn(mockWriter); - - servlet.init(mockServletConfig); - } - - @Test - public void testServiceSetsContextClassLoader() throws ServletException, IOException { - // setup - when(mockRequest.getMethod()).thenReturn("GET"); - when(mockRequest.getRequestURI()).thenReturn("/fhir"); - - ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader(); - - assertNotEquals("ContextClassLoader should not be OpenmrsClassLoader initially", - OpenmrsClassLoader.getInstance().getClass().getName(), initialClassLoader.getClass().getName()); - - // replay - servlet.service(mockRequest, mockResponse); - - // Verify - ClassLoader newClassLoader = Thread.currentThread().getContextClassLoader(); - - assertEquals("ContextClassLoader should be OpenmrsClassLoader after service method", - OpenmrsClassLoader.getInstance().getClass().getName(), newClassLoader.getClass().getName()); - } - - class TestableFhirRestServlet extends FhirRestServlet { - @Override - public void initialize() { - } - } -} \ No newline at end of file + + @Mock + private HttpServletRequest mockRequest; + + @Mock + private HttpServletResponse mockResponse; + + @Mock + private ServletConfig mockServletConfig; + + @Mock + private PrintWriter mockWriter; + + private TestableFhirRestServlet servlet; + + @Before + public void setUp() throws ServletException, IOException { + MockitoAnnotations.initMocks(this); + + servlet = new TestableFhirRestServlet(); + + when(mockServletConfig.getServletContext()).thenReturn(mock(javax.servlet.ServletContext.class)); + when(mockResponse.getWriter()).thenReturn(mockWriter); + + servlet.init(mockServletConfig); + } + + @Test + public void testServiceSetsContextClassLoader() throws ServletException, IOException { + // setup + when(mockRequest.getMethod()).thenReturn("GET"); + when(mockRequest.getRequestURI()).thenReturn("/fhir"); + + ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader(); + + assertNotEquals("ContextClassLoader should not be OpenmrsClassLoader initially", + OpenmrsClassLoader.getInstance().getClass().getName(), initialClassLoader.getClass().getName()); + + // replay + servlet.service(mockRequest, mockResponse); + + // Verify + ClassLoader newClassLoader = Thread.currentThread().getContextClassLoader(); + + assertEquals("ContextClassLoader should be OpenmrsClassLoader after service method", + OpenmrsClassLoader.getInstance().getClass().getName(), newClassLoader.getClass().getName()); + } + + class TestableFhirRestServlet extends FhirRestServlet { + + @Override + public void initialize() { + } + } +} From d0632907d3657607d1d6622daf73df5f443cf1a7 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 20 Dec 2024 12:58:31 -0500 Subject: [PATCH 03/10] Additional fixes to mocked context sensitive tests --- .../EncounterPeriodTranslatorImplTest.java | 3 +- ...ObservationCategoryTranslatorImplTest.java | 20 ++------ .../impl/PersonNameTranslatorImplTest.java | 5 +- .../impl/ValueSetTranslatorImplTest.java | 15 ++---- .../BaseFhirProvenanceResourceTest.java | 50 +------------------ 5 files changed, 13 insertions(+), 80 deletions(-) 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 5167c86c3..11a13e419 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 60d7f5d82..c2f674fc6 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,15 +13,13 @@ 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.module.fhir2.api.translators.ObservationCategoryTranslator; import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @@ -37,27 +35,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/PersonNameTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/PersonNameTranslatorImplTest.java index b266838e9..e96aeb9b0 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 @@ -27,15 +27,17 @@ 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"; @@ -166,7 +168,6 @@ public void shouldOnlyCreateOneExtensionForExtensibleAttributes() { @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(); 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 41699bf26..e1394d810 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 f03341f5d..441dbead3 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()); } } From 7f58602626a46108fbd87cacad1312eaafbc11db Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 20 Dec 2024 13:16:52 -0500 Subject: [PATCH 04/10] Additional fixes to mocked context sensitive tests --- .../impl/PersonNameTranslatorImplTest.java | 47 ------------------- 1 file changed, 47 deletions(-) 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 e96aeb9b0..5cea64418 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,11 +16,6 @@ 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; @@ -30,12 +25,7 @@ import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; import org.openmrs.PersonName; -import org.openmrs.api.AdministrationService; -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 { @@ -165,43 +155,6 @@ public void shouldOnlyCreateOneExtensionForExtensibleAttributes() { assertThat(extension.getExtension().size(), greaterThan(1)); } - @Test - public void shouldUseDefaultNameTemplateToSetNameText() throws SerializationException { - AdministrationService administrationService = mock(AdministrationService.class); - 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(); From 66f7a5fea9be7068a4f7466d650f0980f26d390a Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 20 Dec 2024 13:56:03 -0500 Subject: [PATCH 05/10] Refactor all context sensitive tests to extend a base class that resets the static global property holder --- .../fhir2/BaseFhirContextSensitiveTest.java | 24 +++++++++++++++++++ .../FhirAllergyIntoleranceDaoImplTest.java | 7 ++---- .../api/dao/impl/FhirConceptDaoImplTest.java | 7 ++---- .../impl/FhirConceptSourceDaoImplTest.java | 7 ++---- .../dao/impl/FhirConditionDaoImpl_Test.java | 7 ++---- .../impl/FhirContactPointMapDaoImplTest.java | 7 ++---- .../impl/FhirDiagnosticReportDaoImplTest.java | 7 ++---- .../dao/impl/FhirEncounterDaoImplTest.java | 7 ++---- .../impl/FhirEpisodeOfCareDaoImplTest.java | 7 ++---- .../api/dao/impl/FhirGroupDaoImplTest.java | 7 ++---- .../api/dao/impl/FhirLocationDaoImplTest.java | 7 ++---- .../dao/impl/FhirMedicationDaoImplTest.java | 7 ++---- .../FhirMedicationRequestDaoImplTest.java | 7 ++---- .../dao/impl/FhirObservationDaoImplTest.java | 7 ++---- ...irPatientDaoImplPatientIdentifierTest.java | 7 ++---- .../api/dao/impl/FhirPatientDaoImplTest.java | 7 ++---- ...hirPatientIdentifierSystemDaoImplTest.java | 7 ++---- .../api/dao/impl/FhirPersonDaoImplTest.java | 7 ++---- .../dao/impl/FhirPractitionerDaoImplTest.java | 7 ++---- .../impl/FhirRelatedPersonDaoImplTest.java | 7 ++---- .../impl/FhirServiceRequestDaoImplTest.java | 7 ++---- .../api/dao/impl/FhirTaskDaoImplTest.java | 15 +++++++----- .../api/dao/impl/FhirUserDaoImplTest.java | 7 ++---- .../api/dao/impl/FhirVisitDaoImplTest.java | 7 ++---- .../impl/FhirImmunizationServiceImplTest.java | 7 ++---- .../AllergyIntoleranceSearchQueryTest.java | 7 ++---- .../api/search/ConditionSearchQueryTest.java | 7 ++---- .../DiagnosticReportSearchQueryTest.java | 7 ++---- .../api/search/EncounterSearchQueryTest.java | 7 ++---- .../api/search/GroupSearchQueryTest.java | 7 ++---- .../api/search/LocationSearchQueryTest.java | 7 ++---- .../MedicationRequestSearchQueryTest.java | 7 ++---- .../api/search/MedicationSearchQueryTest.java | 7 ++---- .../search/ObservationSearchQueryTest.java | 7 ++---- .../api/search/PatientSearchQueryTest.java | 17 ++----------- .../api/search/PersonSearchQueryTest.java | 7 ++---- .../search/PractitionerSearchQueryTest.java | 7 ++---- .../search/RelatedPersonSearchQueryTest.java | 7 ++---- .../search/ServiceRequestSearchQueryTest.java | 7 ++---- .../fhir2/api/search/TaskSearchQueryTest.java | 7 ++---- .../fhir2/api/search/UserSearchQueryTest.java | 7 ++---- .../api/search/ValueSetSearchQueryTest.java | 7 ++---- .../api/search/VisitSearchQueryTest.java | 7 ++---- .../impl/DurationUnitTranslatorImplTest.java | 7 ++---- ...ObservationCategoryTranslatorImplTest.java | 7 ++---- 45 files changed, 119 insertions(+), 231 deletions(-) create mode 100644 api/src/test/java/org/openmrs/module/fhir2/BaseFhirContextSensitiveTest.java diff --git a/api/src/test/java/org/openmrs/module/fhir2/BaseFhirContextSensitiveTest.java b/api/src/test/java/org/openmrs/module/fhir2/BaseFhirContextSensitiveTest.java new file mode 100644 index 000000000..7f6be376b --- /dev/null +++ b/api/src/test/java/org/openmrs/module/fhir2/BaseFhirContextSensitiveTest.java @@ -0,0 +1,24 @@ +/* + * 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 org.junit.Before; +import org.openmrs.module.fhir2.api.util.FhirGlobalPropertyHolder; +import org.openmrs.test.BaseModuleContextSensitiveTest; +import org.springframework.test.context.ContextConfiguration; + +@ContextConfiguration(classes = { TestFhirSpringConfiguration.class }, inheritLocations = false) +public abstract class BaseFhirContextSensitiveTest extends BaseModuleContextSensitiveTest { + + @Before + public void setupBaseFhirContextSensitive() { + FhirGlobalPropertyHolder.reset(); + } +} 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 e5db4b87c..ffa8e8ff7 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 @@ -21,15 +21,12 @@ import org.openmrs.Allergy; import org.openmrs.AllergyReaction; import org.openmrs.Concept; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; +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.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"; 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 c5c5193c7..3697d234b 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 688362491..bd942e8a5 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 298e6755d..fb300d705 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 bb8b8d2fd..40aef8258 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 0ef622861..bfe08bb2a 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 c3a8601f1..2a68af981 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 65813cbd2..bf53a7ba0 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 0914eac0b..223b97062 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 e9020a8e9..f7af89d5c 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 @@ -24,14 +24,11 @@ import org.openmrs.LocationTag; import org.openmrs.api.LocationService; import org.openmrs.customdatatype.datatype.FreeTextDatatype; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.api.dao.FhirLocationDao; -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 FhirLocationDaoImplTest extends BaseModuleContextSensitiveTest { +public class FhirLocationDaoImplTest extends BaseFhirContextSensitiveTest { private static final String LOCATION_UUID = "c0938432-1691-11df-97a5-7038c432"; 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 611470c88..6a3b81f76 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 28192ea83..d7a666683 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 ff96f9f0a..941feba29 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 43b0059d8..cbfea9b1e 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 104cf71a7..93f6dcc40 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 87617f160..621cf022b 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 94b2820c9..20381d8f4 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 778af68f9..565b42727 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 34cf96d72..b2d6d59ed 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 4132a482b..50498d49f 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 4280ccc00..a92cb2e11 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 17a42f7e4..64aaa63c6 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 0c7e08cd2..7b8c76cf0 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/FhirImmunizationServiceImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/impl/FhirImmunizationServiceImplTest.java index 6780386cb..4d6e2d47e 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 @@ -44,16 +44,13 @@ 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.util.ImmunizationObsGroupHelper; -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 FhirImmunizationServiceImplTest extends BaseModuleContextSensitiveTest { +public class FhirImmunizationServiceImplTest extends BaseFhirContextSensitiveTest { private static final String IMMUNIZATIONS_METADATA_XML = "org/openmrs/module/fhir2/Immunization_metadata.xml"; 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 6a27867cf..8db03f83f 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 @@ -46,18 +46,15 @@ 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.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.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -@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"; 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 8c936dd03..bc4343794 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 @@ -53,17 +53,14 @@ 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.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"; 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 6ecce7fa1..fce59dd69 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 82bd189e2..de3984911 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 1764b9e2c..0bf235051 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 055100431..eb0ff3f44 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 6f79e6006..1339bbddc 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 2448ef0e0..8ed6fe081 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 b34f3a541..f501e6932 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 688c3fa49..57d3f13c8 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 @@ -57,20 +57,14 @@ import org.hl7.fhir.r4.model.ServiceRequest; import org.junit.Before; import org.junit.Test; -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.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.beans.factory.annotation.Qualifier; -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", @@ -149,13 +143,6 @@ public class PatientSearchQueryTest extends BaseModuleContextSensitiveTest { @Autowired private SearchQueryInclude searchQueryInclude; - @Autowired - private FhirGlobalPropertyService globalPropertyService; - - @Autowired - @Qualifier("adminService") - private AdministrationService administrationService; - @Autowired private SearchQuery> searchQuery; 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 57f37f361..2688e4b70 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 1ee311ba7..12db416df 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 14d70c590..a173554f7 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 eb8844797..46fd096e1 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 0eafbe65b..f7951270a 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 45498be2f..0b5097390 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 18eb8b5ed..5da33aecb 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 c8d8cc47a..d19a97a8f 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 c02d38033..165c06733 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/ObservationCategoryTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/ObservationCategoryTranslatorImplTest.java index c2f674fc6..db0b8e566 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 @@ -18,14 +18,11 @@ import org.junit.Test; import org.openmrs.Concept; import org.openmrs.ConceptClass; -import org.openmrs.module.fhir2.TestFhirSpringConfiguration; +import org.openmrs.module.fhir2.BaseFhirContextSensitiveTest; import org.openmrs.module.fhir2.api.translators.ObservationCategoryTranslator; -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 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"; From d736f9d2e989707a949be3ac194fada7afe706af Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 20 Dec 2024 14:27:45 -0500 Subject: [PATCH 06/10] Fix issues with mocking and test conflicts in omod project --- .../RequireAuthenticationInterceptor.java | 5 +++- .../RequireAuthenticationInterceptorTest.java | 30 +++++++++---------- .../web/servlet/FhirRestServletTest.java | 17 +++-------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/omod/src/main/java/org/openmrs/module/fhir2/web/authentication/RequireAuthenticationInterceptor.java b/omod/src/main/java/org/openmrs/module/fhir2/web/authentication/RequireAuthenticationInterceptor.java index a10e452ca..78898856c 100644 --- a/omod/src/main/java/org/openmrs/module/fhir2/web/authentication/RequireAuthenticationInterceptor.java +++ b/omod/src/main/java/org/openmrs/module/fhir2/web/authentication/RequireAuthenticationInterceptor.java @@ -25,7 +25,7 @@ public class RequireAuthenticationInterceptor { @Hook(Pointcut.SERVER_INCOMING_REQUEST_PRE_PROCESSED) public boolean ensureUserAuthenticated(HttpServletRequest request, HttpServletResponse response) throws IOException { if (!(request.getRequestURI().contains("/.well-known") || request.getRequestURI().endsWith("/metadata")) - && !Context.isAuthenticated()) { + && !isAuthenticated()) { // This sends 401 error if not authenticated response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Not authenticated"); return false; @@ -33,4 +33,7 @@ public boolean ensureUserAuthenticated(HttpServletRequest request, HttpServletRe return true; } + protected boolean isAuthenticated() { + return Context.isAuthenticated(); + } } diff --git a/omod/src/test/java/org/openmrs/module/fhir2/web/authentication/RequireAuthenticationInterceptorTest.java b/omod/src/test/java/org/openmrs/module/fhir2/web/authentication/RequireAuthenticationInterceptorTest.java index a3983ebc6..02ebfd914 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/web/authentication/RequireAuthenticationInterceptorTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/web/authentication/RequireAuthenticationInterceptorTest.java @@ -11,40 +11,25 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.mockito.Mockito.when; import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.openmrs.api.context.Context; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; -@RunWith(PowerMockRunner.class) -@PrepareForTest(Context.class) public class RequireAuthenticationInterceptorTest { - private RequireAuthenticationInterceptor interceptor; - private MockHttpServletRequest request; private MockHttpServletResponse response; @Before public void setup() throws ServletException { - interceptor = new RequireAuthenticationInterceptor(); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); - - PowerMockito.mockStatic(Context.class); - when(Context.isAuthenticated()).thenReturn(false); - } @Test @@ -53,6 +38,7 @@ public void ensureUserAuthenticated_shouldReturnTrueGivenWellKnownUri() throws E request.setRequestURI("/.well-known"); // replay and verify + RequireAuthenticationInterceptor interceptor = getInterceptorForTesting(true); assertThat(interceptor.ensureUserAuthenticated(request, response), is(true)); } @@ -62,6 +48,7 @@ public void ensureUserAuthenticated_shouldReturnTrueGivenMetadataUri() throws Ex request.setRequestURI("/metadata"); // replay and verify + RequireAuthenticationInterceptor interceptor = getInterceptorForTesting(true); assertThat(interceptor.ensureUserAuthenticated(request, response), is(true)); } @@ -71,6 +58,7 @@ public void ensureUserAuthenticated_shouldReturnFalseGivenUserIsNotAuthenticated request.setRequestURI("/ws/fhir2/R4/Someresource"); // replay and verify + RequireAuthenticationInterceptor interceptor = getInterceptorForTesting(false); assertThat(interceptor.ensureUserAuthenticated(request, response), is(false)); assertThat(response.getErrorMessage(), is("Not authenticated")); assertThat(response.getStatus(), is(HttpServletResponse.SC_UNAUTHORIZED)); @@ -80,9 +68,19 @@ public void ensureUserAuthenticated_shouldReturnFalseGivenUserIsNotAuthenticated public void ensureUserAuthenticated_shouldReturnTrueGivenUserIsAuthenticated() throws Exception { // setup request.setRequestURI("/ws/fhir2/R4/Someresource"); - when(Context.isAuthenticated()).thenReturn(true); // replay and verify + RequireAuthenticationInterceptor interceptor = getInterceptorForTesting(true); assertThat(interceptor.ensureUserAuthenticated(request, response), is(true)); } + + public RequireAuthenticationInterceptor getInterceptorForTesting(boolean isUserAuthenticated) { + return new RequireAuthenticationInterceptor() { + + @Override + protected boolean isAuthenticated() { + return isUserAuthenticated; + } + }; + } } diff --git a/omod/src/test/java/org/openmrs/module/fhir2/web/servlet/FhirRestServletTest.java b/omod/src/test/java/org/openmrs/module/fhir2/web/servlet/FhirRestServletTest.java index 8629ce6f3..03f959f0f 100644 --- a/omod/src/test/java/org/openmrs/module/fhir2/web/servlet/FhirRestServletTest.java +++ b/omod/src/test/java/org/openmrs/module/fhir2/web/servlet/FhirRestServletTest.java @@ -10,7 +10,7 @@ package org.openmrs.module.fhir2.web.servlet; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -62,19 +62,10 @@ public void testServiceSetsContextClassLoader() throws ServletException, IOExcep when(mockRequest.getMethod()).thenReturn("GET"); when(mockRequest.getRequestURI()).thenReturn("/fhir"); - ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader(); - - assertNotEquals("ContextClassLoader should not be OpenmrsClassLoader initially", - OpenmrsClassLoader.getInstance().getClass().getName(), initialClassLoader.getClass().getName()); - - // replay + Thread.currentThread().setContextClassLoader(null); + assertNull(Thread.currentThread().getContextClassLoader()); servlet.service(mockRequest, mockResponse); - - // Verify - ClassLoader newClassLoader = Thread.currentThread().getContextClassLoader(); - - assertEquals("ContextClassLoader should be OpenmrsClassLoader after service method", - OpenmrsClassLoader.getInstance().getClass().getName(), newClassLoader.getClass().getName()); + assertEquals(OpenmrsClassLoader.getInstance(), Thread.currentThread().getContextClassLoader()); } class TestableFhirRestServlet extends FhirRestServlet { From 4bd869095f95adc155c0fe6f6587db181d98c4aa Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 20 Dec 2024 15:11:07 -0500 Subject: [PATCH 07/10] Fix incorrect integration test --- ...upFhirResourceProviderIntegrationTest.java | 7 ++--- .../FhirCohortDaoImplTest_initial_data.xml | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/GroupFhirResourceProviderIntegrationTest.java b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/GroupFhirResourceProviderIntegrationTest.java index 7908b5624..3bb0a8a06 100644 --- a/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/GroupFhirResourceProviderIntegrationTest.java +++ b/integration-tests/src/test/java/org/openmrs/module/fhir2/providers/r4/GroupFhirResourceProviderIntegrationTest.java @@ -45,8 +45,6 @@ public class GroupFhirResourceProviderIntegrationTest extends BaseFhirR4Integrat private static final String COHORT_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirCohortDaoImplTest_initial_data.xml"; - private static final String PATIENT_DATA_XML = "org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest_initial_data.xml"; - private static final String JSON_CREATE_GROUP_DOCUMENT = "org/openmrs/module/fhir2/providers/GroupWebTest_create.json"; private static final String XML_CREATE_GROUP_DOCUMENT = "org/openmrs/module/fhir2/providers/GroupWebTest_create.xml"; @@ -63,7 +61,6 @@ public class GroupFhirResourceProviderIntegrationTest extends BaseFhirR4Integrat @Override public void setup() throws Exception { super.setup(); - executeDataSet(PATIENT_DATA_XML); executeDataSet(COHORT_DATA_XML); } @@ -387,7 +384,7 @@ public void shouldReturnNotFoundWhenDeletingNonExistentGroup() throws Exception @Test public void shouldReturnCountForGroupAsJson() throws Exception { - MockHttpServletResponse response = get("/Group?_summary=count").accept(FhirMediaTypes.JSON).go(); + MockHttpServletResponse response = get("/Group").accept(FhirMediaTypes.JSON).go(); assertThat(response, isOk()); assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString())); @@ -402,7 +399,7 @@ public void shouldReturnCountForGroupAsJson() throws Exception { @Test public void shouldReturnCountForGroupAsXml() throws Exception { - MockHttpServletResponse response = get("/Group?_summary=count").accept(FhirMediaTypes.XML).go(); + MockHttpServletResponse response = get("/Group").accept(FhirMediaTypes.XML).go(); assertThat(response, isOk()); assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString())); diff --git a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirCohortDaoImplTest_initial_data.xml b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirCohortDaoImplTest_initial_data.xml index 4527f4c00..55759daa8 100644 --- a/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirCohortDaoImplTest_initial_data.xml +++ b/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirCohortDaoImplTest_initial_data.xml @@ -9,6 +9,37 @@ graphic logo is a trademark of OpenMRS Inc. --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 53aa3c2891678ce976c6fa2a32c8cb156333008f Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 20 Dec 2024 15:29:04 -0500 Subject: [PATCH 08/10] Reset cached GPs in base fhir integration test --- .../java/org/openmrs/module/fhir2/BaseFhirIntegrationTest.java | 2 ++ 1 file changed, 2 insertions(+) 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 0c2dc0b8a..06fe70a90 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 Date: Fri, 20 Dec 2024 15:50:57 -0500 Subject: [PATCH 09/10] Attempt to fix e2e tests. Temporarily disable integration tests. --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e6585c8ce..0df6bb8ac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: - name: Build with Maven id: build_with_maven run: | - mvn clean verify --batch-mode -P integration-test --file pom.xml + mvn clean install -DskipTests --file pom.xml - uses: actions/upload-artifact@v4 with: name: build_artifact @@ -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 From acc9584fbccb41ebc413d3d29cb317e77b607313 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Fri, 20 Dec 2024 16:16:27 -0500 Subject: [PATCH 10/10] Re-enable integration tests --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0df6bb8ac..7452b237a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: - name: Build with Maven id: build_with_maven run: | - mvn clean install -DskipTests --file pom.xml + mvn clean verify --batch-mode -P integration-test --file pom.xml - uses: actions/upload-artifact@v4 with: name: build_artifact