From 5cff367bfc394334d3bf171a72aa7e028e4d030b Mon Sep 17 00:00:00 2001 From: Jonathan Percival Date: Fri, 29 Mar 2024 16:13:03 -0600 Subject: [PATCH] Various test fixes and updates --- .../cqf/ruler/cdshooks/CdsHooksConfig.java | 8 ++- .../cqf/ruler/devtools/DevToolsConfig.java | 5 +- .../dstu3/CacheValueSetsProviderIT.java | 70 +++++++++---------- .../devtools/dstu3/CodeSystemProviderIT.java | 4 +- .../devtools/r4/CacheValueSetsProviderIT.java | 7 +- .../devtools/r4/CodeSystemProviderIT.java | 4 +- .../cqf/ruler/security/SecurityConfig.java | 6 +- 7 files changed, 54 insertions(+), 50 deletions(-) diff --git a/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/CdsHooksConfig.java b/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/CdsHooksConfig.java index c19cd294a..dcc4d12d0 100644 --- a/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/CdsHooksConfig.java +++ b/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/CdsHooksConfig.java @@ -1,6 +1,7 @@ package org.opencds.cqf.ruler.cdshooks; import org.opencds.cqf.external.annotations.OnR4Condition; +import org.opencds.cqf.external.cr.StarterCrR4Config; import org.opencds.cqf.ruler.cdshooks.providers.ProviderConfiguration; import org.opencds.cqf.ruler.cdshooks.r4.CdsHooksServlet; import org.springframework.beans.factory.annotation.Autowired; @@ -12,31 +13,32 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import ca.uhn.fhir.cr.config.dstu3.CrDstu3Config; -import ca.uhn.fhir.cr.config.r4.CrR4Config; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.cache.IResourceChangeListenerRegistry; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; @Configuration @ConditionalOnProperty(prefix = "hapi.fhir.cdshooks", name = "enabled", havingValue = "true", matchIfMissing = true) -@Import({ CrR4Config.class, CrDstu3Config.class }) +@Import({ StarterCrR4Config.class }) public class CdsHooksConfig { @Autowired AutowireCapableBeanFactory beanFactory; @Bean + @Conditional(OnR4Condition.class) public CdsHooksProperties cdsHooksProperties() { return new CdsHooksProperties(); } @Bean + @Conditional(OnR4Condition.class) public ProviderConfiguration providerConfiguration(CdsHooksProperties cdsProperties) { return new ProviderConfiguration(cdsProperties); } @Bean + @Conditional(OnR4Condition.class) public CdsServicesCache cdsServiceInterceptor(IResourceChangeListenerRegistry resourceChangeListenerRegistry, DaoRegistry daoRegistry) { CdsServicesCache listener = new CdsServicesCache(daoRegistry); diff --git a/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/DevToolsConfig.java b/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/DevToolsConfig.java index 15b19dba6..b6c89052c 100644 --- a/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/DevToolsConfig.java +++ b/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/DevToolsConfig.java @@ -2,6 +2,7 @@ import org.opencds.cqf.external.annotations.OnDSTU3Condition; import org.opencds.cqf.external.annotations.OnR4Condition; +import org.opencds.cqf.external.cr.CrCommonConfig; import org.opencds.cqf.external.cr.PostInitProviderRegisterer; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; @@ -11,8 +12,6 @@ import org.springframework.context.annotation.Lazy; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.cr.config.dstu3.CrDstu3Config; -import ca.uhn.fhir.cr.config.r4.CrR4Config; import ca.uhn.fhir.rest.server.provider.ResourceProviderFactory; /** @@ -31,7 +30,7 @@ */ @Configuration @ConditionalOnProperty(prefix = "hapi.fhir.devtools", name = "enabled", havingValue = "true", matchIfMissing = true) -@Import({ CrR4Config.class, CrDstu3Config.class }) +@Import({ CrCommonConfig.class }) public class DevToolsConfig { @Bean diff --git a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CacheValueSetsProviderIT.java b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CacheValueSetsProviderIT.java index 21195f4c0..92ee89b4c 100644 --- a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CacheValueSetsProviderIT.java +++ b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CacheValueSetsProviderIT.java @@ -24,16 +24,15 @@ import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import ca.uhn.fhir.rest.api.QualifiedParamList; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.StringAndListParam; -import org.springframework.test.annotation.DirtiesContext; @DirtiesContext -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - classes = { DevToolsConfig.class }, - properties = { "hapi.fhir.fhir_version=dstu3" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { + DevToolsConfig.class }, properties = { "hapi.fhir.fhir_version=dstu3", "hapi.fhir.cr.enabled=true" }) class CacheValueSetsProviderIT extends RestIntegrationTest { @Autowired private CacheValueSetsProvider cacheValueSetsProvider; @@ -127,36 +126,36 @@ void testCacheValueSetsNoCompose() throws Exception { // assertTrue(resultingValueSet.getVersion().endsWith("-cached")); } -// TODO Get help with this.... -// @Test -// void testCacheValueSetsExpandAndAddConcepts() throws Exception { -// Endpoint endpoint = uploadLocalServerEndpoint(); -// RequestDetails details = Mockito.mock(RequestDetails.class); -// ValueSet vs = -// uploadValueSet("valueset/valueset-buprenorphine-and-methadone-medications.json"); -// vs.getCompose().getInclude().forEach(include -> { -// assertFalse(include.hasConcept()); -// }); -// StringAndListParam stringAndListParam = -// getStringAndListParamFromValueSet(vs); -// -// IGenericClient localClient = getClient(); -// localClient.operation().onServer().named("updateCodeSystems").withNoParameters(Parameters.class).execute(); -// Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, -// endpoint.getIdElement(), stringAndListParam, null, null); -// assertTrue(outcomeResource instanceof Bundle); -// Bundle resultBundle = (Bundle) outcomeResource; -// assertEquals(1, resultBundle.getEntry().size()); -// BundleEntryComponent entry = resultBundle.getEntry().get(0); -// assertTrue(entry.getResponse().getLocation().startsWith("ValueSet/" + -// vs.getIdElement().getIdPart())); -// assertEquals("200 OK", entry.getResponse().getStatus()); -// ValueSet resultingValueSet = -// localClient.read().resource(ValueSet.class).withId(vs.getIdElement()).execute(); -// resultingValueSet.getCompose().getInclude().forEach(include -> { -// assertTrue(include.hasConcept()); -// }); -// } + // TODO Get help with this.... + // @Test + // void testCacheValueSetsExpandAndAddConcepts() throws Exception { + // Endpoint endpoint = uploadLocalServerEndpoint(); + // RequestDetails details = Mockito.mock(RequestDetails.class); + // ValueSet vs = + // uploadValueSet("valueset/valueset-buprenorphine-and-methadone-medications.json"); + // vs.getCompose().getInclude().forEach(include -> { + // assertFalse(include.hasConcept()); + // }); + // StringAndListParam stringAndListParam = + // getStringAndListParamFromValueSet(vs); + // + // IGenericClient localClient = getClient(); + // localClient.operation().onServer().named("updateCodeSystems").withNoParameters(Parameters.class).execute(); + // Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, + // endpoint.getIdElement(), stringAndListParam, null, null); + // assertTrue(outcomeResource instanceof Bundle); + // Bundle resultBundle = (Bundle) outcomeResource; + // assertEquals(1, resultBundle.getEntry().size()); + // BundleEntryComponent entry = resultBundle.getEntry().get(0); + // assertTrue(entry.getResponse().getLocation().startsWith("ValueSet/" + + // vs.getIdElement().getIdPart())); + // assertEquals("200 OK", entry.getResponse().getStatus()); + // ValueSet resultingValueSet = + // localClient.read().resource(ValueSet.class).withId(vs.getIdElement()).execute(); + // resultingValueSet.getCompose().getInclude().forEach(include -> { + // assertTrue(include.hasConcept()); + // }); + // } @Test void testCacheValueSetsAlreadyExpanded() throws Exception { @@ -205,7 +204,8 @@ private ValueSet uploadValueSet(String location) throws IOException { private Endpoint uploadLocalServerEndpoint() throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader( - Objects.requireNonNull(CacheValueSetsProvider.class.getResourceAsStream("endpoint/LocalServerEndpoint.json")))); + Objects.requireNonNull( + CacheValueSetsProvider.class.getResourceAsStream("endpoint/LocalServerEndpoint.json")))); String resourceString = reader.lines().collect(Collectors.joining(System.lineSeparator())); reader.close(); // Don't want to update during loading because need to setAddress first diff --git a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CodeSystemProviderIT.java b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CodeSystemProviderIT.java index 23ed20dec..6c63ecfd6 100644 --- a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CodeSystemProviderIT.java +++ b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CodeSystemProviderIT.java @@ -30,13 +30,13 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import org.springframework.test.annotation.DirtiesContext; @DirtiesContext @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { - DevToolsConfig.class }, properties = { "hapi.fhir.fhir_version=dstu3" }) + DevToolsConfig.class }, properties = { "hapi.fhir.fhir_version=dstu3", "hapi.fhir.cr.enabled=true" }) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) class CodeSystemProviderIT extends RestIntegrationTest { private final Logger log = LoggerFactory.getLogger(CodeSystemProviderIT.class); diff --git a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CacheValueSetsProviderIT.java b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CacheValueSetsProviderIT.java index fcd312bd0..0bd62143b 100644 --- a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CacheValueSetsProviderIT.java +++ b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CacheValueSetsProviderIT.java @@ -24,16 +24,16 @@ import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import ca.uhn.fhir.rest.api.QualifiedParamList; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.StringAndListParam; -import org.springframework.test.annotation.DirtiesContext; @DirtiesContext @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { DevToolsConfig.class }, properties = { - "hapi.fhir.fhir_version=r4"}) + "hapi.fhir.fhir_version=r4", "hapi.fhir.cr.enabled=true" }) class CacheValueSetsProviderIT extends RestIntegrationTest { @Autowired private CacheValueSetsProvider cacheValueSetsProvider; @@ -206,7 +206,8 @@ private ValueSet uploadValueSet(String location) throws IOException { private Endpoint uploadLocalServerEndpoint() throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader( - Objects.requireNonNull(CacheValueSetsProvider.class.getResourceAsStream("endpoint/LocalServerEndpoint.json")))); + Objects.requireNonNull( + CacheValueSetsProvider.class.getResourceAsStream("endpoint/LocalServerEndpoint.json")))); String resourceString = reader.lines().collect(Collectors.joining(System.lineSeparator())); reader.close(); // Don't want to update during loading because need to setAddress first diff --git a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CodeSystemProviderIT.java b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CodeSystemProviderIT.java index 0b9a32ec4..d0d613169 100644 --- a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CodeSystemProviderIT.java +++ b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CodeSystemProviderIT.java @@ -30,14 +30,14 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import org.springframework.test.annotation.DirtiesContext; @DirtiesContext @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { DevToolsConfig.class }, properties = { - "hapi.fhir.fhir_version=r4"}) + "hapi.fhir.fhir_version=r4", "hapi.fhir.cr.enabled=true" }) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) class CodeSystemProviderIT extends RestIntegrationTest { private final Logger log = LoggerFactory.getLogger(CodeSystemProviderIT.class); diff --git a/plugin/security/src/main/java/org/opencds/cqf/ruler/security/SecurityConfig.java b/plugin/security/src/main/java/org/opencds/cqf/ruler/security/SecurityConfig.java index 364abf91c..612e88ba2 100644 --- a/plugin/security/src/main/java/org/opencds/cqf/ruler/security/SecurityConfig.java +++ b/plugin/security/src/main/java/org/opencds/cqf/ruler/security/SecurityConfig.java @@ -1,5 +1,7 @@ package org.opencds.cqf.ruler.security; +import org.opencds.cqf.external.annotations.OnDSTU3Condition; +import org.opencds.cqf.external.annotations.OnR4Condition; import org.opencds.cqf.ruler.api.MetadataExtender; import org.opencds.cqf.ruler.security.interceptor.AuthenticationInterceptor; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -23,14 +25,14 @@ public AuthenticationInterceptor authenticationInterceptor() { } @Bean - @Conditional(org.opencds.cqf.external.annotations.OnR4Condition.class) + @Conditional(OnR4Condition.class) @ConditionalOnProperty(prefix = "hapi.fhir.security.oauth", name = "enabled", havingValue = "true") public MetadataExtender oAuthProviderR4() { return new org.opencds.cqf.ruler.security.r4.OAuthProvider(); } @Bean - @Conditional(org.opencds.cqf.external.annotations.OnDSTU3Condition.class) + @Conditional(OnDSTU3Condition.class) @ConditionalOnProperty(prefix = "hapi.fhir.security.oauth", name = "enabled", havingValue = "true") public MetadataExtender oAuthProviderDstu3() { return new org.opencds.cqf.ruler.security.dstu3.OAuthProvider();