diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookActivatesPreExistingSubscriptionsR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookActivatesPreExistingSubscriptionsR4Test.java index e78e26d8a94..c8383e05398 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookActivatesPreExistingSubscriptionsR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookActivatesPreExistingSubscriptionsR4Test.java @@ -4,19 +4,29 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.provider.r4.BaseResourceProviderR4Test; import ca.uhn.fhir.jpa.subscription.SubscriptionTestUtil; +import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionMatcherInterceptor; import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.test.utilities.JettyUtil; import com.google.common.collect.Lists; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r4.model.*; -import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; +import org.hl7.fhir.r4.model.CodeableConcept; +import org.hl7.fhir.r4.model.Coding; +import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.Observation; +import org.hl7.fhir.r4.model.Subscription; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -29,8 +39,6 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; -import ca.uhn.fhir.test.utilities.JettyUtil; - public class RestHookActivatesPreExistingSubscriptionsR4Test extends BaseResourceProviderR4Test { private static final Logger ourLog = LoggerFactory.getLogger(RestHookActivatesPreExistingSubscriptionsR4Test.class); @@ -38,20 +46,25 @@ public class RestHookActivatesPreExistingSubscriptionsR4Test extends BaseResourc private static RestfulServer ourListenerRestServer; private static String ourListenerServerBase; private static Server ourListenerServer; - private static List ourUpdatedObservations = Collections.synchronizedList(Lists.newArrayList()); - private static List ourContentTypes = Collections.synchronizedList(new ArrayList<>()); - private static List ourHeaders = Collections.synchronizedList(new ArrayList<>()); + private static final List ourUpdatedObservations = Collections.synchronizedList(Lists.newArrayList()); + private static final List ourContentTypes = Collections.synchronizedList(new ArrayList<>()); + private static final List ourHeaders = Collections.synchronizedList(new ArrayList<>()); @Autowired private SubscriptionTestUtil mySubscriptionTestUtil; + @Autowired + private SubscriptionMatcherInterceptor mySubscriptionMatcherInterceptor; @AfterEach public void afterUnregisterRestHookListener() { mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); + myDaoConfig.clearSupportedSubscriptionTypesForUnitTest(); } @BeforeEach public void beforeSetSubscriptionActivatingInterceptor() { + myDaoConfig.addSupportedSubscriptionType(org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType.RESTHOOK); + mySubscriptionMatcherInterceptor.startIfNeeded(); mySubscriptionLoader.doSyncSubscriptionsForUnitTest(); } diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherR5Test.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherR5Test.java index 4f3886f67a8..cfd37c44f68 100644 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherR5Test.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherR5Test.java @@ -244,18 +244,6 @@ public class InMemoryResourceMatcherR5Test { assertTrue(result.matched()); } - @Test - public void testTodayTomorrow() { - Observation futureObservation = new Observation(); - Instant nextWeek = Instant.now().plus(Duration.ofDays(1)); - futureObservation.setEffective(new DateTimeType(Date.from(nextWeek))); - ResourceIndexedSearchParams searchParams = extractDateSearchParam(futureObservation); - - InMemoryMatchResult result = myInMemoryResourceMatcher.match("date=gt" + BaseDateTimeDt.TODAY_DATE_CONSTANT, futureObservation, searchParams); - assertTrue(result.supported(), result.getUnsupportedReason()); - assertTrue(result.matched()); - } - @Test public void testTodayYesterday() { Observation futureObservation = new Observation(); diff --git a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionMatcherInterceptor.java b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionMatcherInterceptor.java index 0ac57d42dec..2b7adf3f0dd 100644 --- a/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionMatcherInterceptor.java +++ b/hapi-fhir-jpaserver-subscription/src/main/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionMatcherInterceptor.java @@ -13,8 +13,8 @@ import ca.uhn.fhir.jpa.subscription.match.matcher.matching.IResourceModifiedCons import ca.uhn.fhir.jpa.subscription.match.matcher.subscriber.SubscriptionMatchingSubscriber; import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedJsonMessage; import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; -import ca.uhn.fhir.rest.server.util.CompositeInterceptorBroadcaster; import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.server.util.CompositeInterceptorBroadcaster; import com.google.common.annotations.VisibleForTesting; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -51,7 +51,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; @Interceptor public class SubscriptionMatcherInterceptor implements IResourceModifiedConsumer { - private Logger ourLog = LoggerFactory.getLogger(SubscriptionMatcherInterceptor.class); + private static final Logger ourLog = LoggerFactory.getLogger(SubscriptionMatcherInterceptor.class); @Autowired private FhirContext myFhirContext; @Autowired @@ -72,6 +72,10 @@ public class SubscriptionMatcherInterceptor implements IResourceModifiedConsumer @EventListener(classes = {ContextRefreshedEvent.class}) public void startIfNeeded() { + if (myDaoConfig.getSupportedSubscriptionTypes().isEmpty()) { + ourLog.debug("Subscriptions are disabled on this server. Skipping {} channel creation.", SubscriptionMatchingSubscriber.SUBSCRIPTION_MATCHING_CHANNEL_NAME); + return; + } if (myMatchingChannel == null) { myMatchingChannel = mySubscriptionChannelFactory.newMatchingSendingChannel(SubscriptionMatchingSubscriber.SUBSCRIPTION_MATCHING_CHANNEL_NAME, null); }