Skip to content

Commit

Permalink
Various test fixes and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival committed Mar 29, 2024
1 parent 72d1b21 commit 5cff367
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<org.hl7.fhir.r4.model.CapabilityStatement> 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<org.hl7.fhir.dstu3.model.CapabilityStatement> oAuthProviderDstu3() {
return new org.opencds.cqf.ruler.security.dstu3.OAuthProvider();
Expand Down

0 comments on commit 5cff367

Please sign in to comment.