From 46c04488deb03a9b8e5d91077184d734da993847 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 19 Aug 2017 19:14:52 -0400 Subject: [PATCH] Use correct verb for rest hook notifications --- ...scriptionDeliveringRestHookSubscriber.java | 60 +++-- .../subscription/RestHookTestDstu2Test.java | 41 ++-- .../subscription/RestHookTestDstu3Test.java | 215 +++++++++--------- ...rceptorRegisteredToDaoConfigDstu2Test.java | 40 ++-- ...rceptorRegisteredToDaoConfigDstu3Test.java | 40 ++-- .../subscription/r4/RestHookTestR4Test.java | 60 ++--- ...nterceptorRegisteredToDaoConfigR4Test.java | 40 ++-- .../main/webapp/WEB-INF/templates/home.html | 4 +- src/changes/changes.xml | 5 + 9 files changed, 252 insertions(+), 253 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionDeliveringRestHookSubscriber.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionDeliveringRestHookSubscriber.java index a775efa8ca7..e90d11cb5e1 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionDeliveringRestHookSubscriber.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionDeliveringRestHookSubscriber.java @@ -34,7 +34,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; -import org.springframework.messaging.SubscribableChannel; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -44,10 +43,36 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class SubscriptionDeliveringRestHookSubscriber extends BaseSubscriptionSubscriber { private Logger ourLog = LoggerFactory.getLogger(SubscriptionDeliveringRestHookSubscriber.class); - public SubscriptionDeliveringRestHookSubscriber(IFhirResourceDao theSubscriptionDao, ConcurrentHashMap theIdToSubscription, Subscription.SubscriptionChannelType theChannelType, BaseSubscriptionInterceptor theSubscriptionInterceptor) { + public SubscriptionDeliveringRestHookSubscriber(IFhirResourceDao theSubscriptionDao, ConcurrentHashMap theIdToSubscription, Subscription.SubscriptionChannelType theChannelType, BaseSubscriptionInterceptor theSubscriptionInterceptor) { super(theSubscriptionDao, theIdToSubscription, theChannelType, theSubscriptionInterceptor); } + protected void deliverPayload(ResourceDeliveryMessage theMsg, IBaseResource theSubscription, EncodingEnum thePayloadType, IGenericClient theClient) { + IBaseResource payloadResource = theMsg.getPayoad(); + + IClientExecutable operation; + switch (theMsg.getOperationType()) { + case CREATE: + operation = theClient.update().resource(payloadResource); + break; + case UPDATE: + operation = theClient.update().resource(payloadResource); + break; + case DELETE: + operation = theClient.delete().resourceById(theMsg.getPayloadId()); + break; + default: + ourLog.warn("Ignoring delivery message of type: {}", theMsg.getOperationType()); + return; + } + + operation.encoded(thePayloadType); + + ourLog.info("Delivering {} rest-hook payload {} for {}", theMsg.getOperationType(), payloadResource.getIdElement().toUnqualified().getValue(), theSubscription.getIdElement().toUnqualifiedVersionless().getValue()); + + operation.execute(); + } + @Override public void handleMessage(Message theMessage) throws MessagingException { if (!(theMessage.getPayload() instanceof ResourceDeliveryMessage)) { @@ -89,37 +114,8 @@ public class SubscriptionDeliveringRestHookSubscriber extends BaseSubscriptionSu } } - msg = massage(msg); - - IBaseResource payloadResource = msg.getPayoad(); - IClientExecutable operation; - switch (msg.getOperationType()) { - case CREATE: - operation = client.create().resource(payloadResource); - break; - case UPDATE: - operation = client.update().resource(payloadResource); - break; - case DELETE: - operation = client.delete().resourceById(msg.getPayloadId()); - break; - default: - ourLog.warn("Ignoring delivery message of type: {}", msg.getOperationType()); - return; - } - - operation.encoded(payloadType); - - ourLog.info("Delivering {} rest-hook payload {} for {}", msg.getOperationType(), payloadResource.getIdElement().toUnqualified().getValue(), subscription.getIdElement().toUnqualifiedVersionless().getValue()); - - operation.execute(); + deliverPayload(msg, subscription, payloadType, client); } - /** - * Subclasses may override - */ - protected ResourceDeliveryMessage massage(ResourceDeliveryMessage theMsg) { - return theMsg; - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestDstu2Test.java index f104fd06f85..0ebff63348e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestDstu2Test.java @@ -148,8 +148,8 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); Assert.assertNotNull(subscriptionTemp); @@ -163,8 +163,8 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { waitForQueueToDrain(); // Should see one subscription notification - waitForSize(3, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(3, ourUpdatedObservations); // Delet one subscription ourClient.delete().resourceById(new IdDt("Subscription/" + subscription2.getId())).execute(); @@ -173,8 +173,8 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); CodeableConceptDt codeableConcept = new CodeableConceptDt(); @@ -186,8 +186,8 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { // Should see no subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); @@ -200,8 +200,8 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(5, ourUpdatedObservations); Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); Assert.assertFalse(observation1.getId().isEmpty()); @@ -223,9 +223,8 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); Assert.assertNotNull(subscriptionTemp); @@ -237,8 +236,8 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { // Should see one subscription notification waitForQueueToDrain(); - waitForSize(3, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(3, ourUpdatedObservations); ourClient.delete().resourceById(new IdDt("Subscription/" + subscription2.getId())).execute(); @@ -246,8 +245,8 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); CodeableConceptDt codeableConcept = new CodeableConceptDt(); @@ -259,8 +258,8 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { // Should see no subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); @@ -273,8 +272,8 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(5, ourUpdatedObservations); Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); Assert.assertFalse(observation1.getId().isEmpty()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestDstu3Test.java index cb236d5cd63..3a7c0e95bfd 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestDstu3Test.java @@ -34,15 +34,15 @@ import static org.junit.Assert.fail; */ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RestHookTestDstu2Test.class); private static List ourCreatedObservations = Lists.newArrayList(); private static int ourListenerPort; private static RestfulServer ourListenerRestServer; private static Server ourListenerServer; private static String ourListenerServerBase; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RestHookTestDstu2Test.class); private static List ourUpdatedObservations = Lists.newArrayList(); - private List mySubscriptionIds = new ArrayList<>(); private static List ourContentTypes = new ArrayList<>(); + private List mySubscriptionIds = new ArrayList<>(); @After public void afterUnregisterRestHookListener() { @@ -74,23 +74,6 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { ourContentTypes.clear(); } - // TODO: Reenable this - @Test - @Ignore - public void testRestHookSubscriptionInvalidCriteria() throws Exception { - String payload = "application/xml"; - - String criteria1 = "Observation?codeeeee=SNOMED-CT"; - - try { - createSubscription(criteria1, payload, ourListenerServerBase); - fail(); - } catch (InvalidRequestException e) { - assertEquals("HTTP 400 Bad Request: Invalid criteria: Failed to parse match URL[Observation?codeeeee=SNOMED-CT] - Resource type Observation does not have a parameter with name: codeeeee", e.getMessage()); - } - } - - private Subscription createSubscription(String theCriteria, String thePayload, String theEndpoint) throws InterruptedException { Subscription subscription = new Subscription(); subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)"); @@ -129,7 +112,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { return observation; } - + @Test public void testRestHookSubscriptionApplicationFhirJson() throws Exception { String payload = "application/fhir+json"; @@ -145,15 +128,11 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0)); } - - private void waitForQueueToDrain() throws InterruptedException { - RestHookTestDstu2Test.waitForQueueToDrain(ourRestHookSubscriptionInterceptor); - } - + @Test public void testRestHookSubscriptionApplicationJson() throws Exception { String payload = "application/json"; @@ -169,8 +148,8 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0)); // Modify subscription 2 to also match @@ -185,8 +164,8 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { // Should see one subscription notification waitForQueueToDrain(); - waitForSize(3, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(3, ourUpdatedObservations); ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); waitForQueueToDrain(); @@ -195,8 +174,8 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); @@ -208,8 +187,8 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { // Should see no subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); @@ -222,8 +201,85 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(5, ourUpdatedObservations); + + Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); + Assert.assertFalse(observation1.getId().isEmpty()); + Assert.assertFalse(observation2.getId().isEmpty()); + } + + @Test + public void testRestHookSubscriptionApplicationXml() throws Exception { + String payload = "application/xml"; + + String code = "1000000050"; + String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml"; + String criteria2 = "Observation?code=SNOMED-CT|" + code + "111&_format=xml"; + + Subscription subscription1 = createSubscription(criteria1, payload, ourListenerServerBase); + Subscription subscription2 = createSubscription(criteria2, payload, ourListenerServerBase); + + Observation observation1 = sendObservation(code, "SNOMED-CT"); + + // Should see 1 subscription notification + waitForQueueToDrain(); + waitForSize(0, ourCreatedObservations); waitForSize(1, ourUpdatedObservations); + assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); + + // Modify subscription 2 to also match + Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); + Assert.assertNotNull(subscriptionTemp); + subscriptionTemp.setCriteria(criteria1); + ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); + waitForQueueToDrain(); + + // Send another observation + Observation observation2 = sendObservation(code, "SNOMED-CT"); + + // Should see two subscription notifications + waitForQueueToDrain(); + waitForSize(0, ourCreatedObservations); + waitForSize(3, ourUpdatedObservations); + + ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); + waitForQueueToDrain(); + + // Send another + Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); + + // Should see only one subscription notification + waitForQueueToDrain(); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); + + Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); + CodeableConcept codeableConcept = new CodeableConcept(); + observation3.setCode(codeableConcept); + Coding coding = codeableConcept.addCoding(); + coding.setCode(code + "111"); + coding.setSystem("SNOMED-CT"); + ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); + + // Should see no subscription notification + waitForQueueToDrain(); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); + + Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); + + CodeableConcept codeableConcept1 = new CodeableConcept(); + observation3a.setCode(codeableConcept1); + Coding coding1 = codeableConcept1.addCoding(); + coding1.setCode(code); + coding1.setSystem("SNOMED-CT"); + ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); + + // Should see only one subscription notification + waitForQueueToDrain(); + waitForSize(0, ourCreatedObservations); + waitForSize(5, ourUpdatedObservations); Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); Assert.assertFalse(observation1.getId().isEmpty()); @@ -245,86 +301,29 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); } + // TODO: Reenable this @Test - public void testRestHookSubscriptionApplicationXml() throws Exception { + @Ignore + public void testRestHookSubscriptionInvalidCriteria() throws Exception { String payload = "application/xml"; - String code = "1000000050"; - String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml"; - String criteria2 = "Observation?code=SNOMED-CT|" + code + "111&_format=xml"; + String criteria1 = "Observation?codeeeee=SNOMED-CT"; - Subscription subscription1 = createSubscription(criteria1, payload, ourListenerServerBase); - Subscription subscription2 = createSubscription(criteria2, payload, ourListenerServerBase); + try { + createSubscription(criteria1, payload, ourListenerServerBase); + fail(); + } catch (InvalidRequestException e) { + assertEquals("HTTP 400 Bad Request: Invalid criteria: Failed to parse match URL[Observation?codeeeee=SNOMED-CT] - Resource type Observation does not have a parameter with name: codeeeee", e.getMessage()); + } + } - Observation observation1 = sendObservation(code, "SNOMED-CT"); - - // Should see 1 subscription notification - waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); - assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); - - // Modify subscription 2 to also match - Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); - subscriptionTemp.setCriteria(criteria1); - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); - waitForQueueToDrain(); - - // Send another observation - Observation observation2 = sendObservation(code, "SNOMED-CT"); - - // Should see two subscription notifications - waitForQueueToDrain(); - waitForSize(3, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); - - ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); - waitForQueueToDrain(); - - // Send another - Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); - - // Should see only one subscription notification - waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); - - Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); - CodeableConcept codeableConcept = new CodeableConcept(); - observation3.setCode(codeableConcept); - Coding coding = codeableConcept.addCoding(); - coding.setCode(code + "111"); - coding.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); - - // Should see no subscription notification - waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); - - Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); - - CodeableConcept codeableConcept1 = new CodeableConcept(); - observation3a.setCode(codeableConcept1); - Coding coding1 = codeableConcept1.addCoding(); - coding1.setCode(code); - coding1.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); - - // Should see only one subscription notification - waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); - - Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); - Assert.assertFalse(observation1.getId().isEmpty()); - Assert.assertFalse(observation2.getId().isEmpty()); + private void waitForQueueToDrain() throws InterruptedException { + RestHookTestDstu2Test.waitForQueueToDrain(ourRestHookSubscriptionInterceptor); } @BeforeClass diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test.java index 080b0acb9bf..aa079ac0871 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test.java @@ -132,8 +132,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); Assert.assertNotNull(subscriptionTemp); @@ -146,8 +146,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B // Should see two subscription notifications waitForQueueToDrain(); - waitForSize(3, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(3, ourUpdatedObservations); ourClient.delete().resourceById(new IdDt("Subscription/"+ subscription2.getId())).execute(); @@ -155,8 +155,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); CodeableConceptDt codeableConcept = new CodeableConceptDt(); @@ -168,8 +168,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B // Should see no subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); @@ -182,8 +182,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(5, ourUpdatedObservations); Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); Assert.assertFalse(observation1.getId().isEmpty()); @@ -205,8 +205,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); Assert.assertNotNull(subscriptionTemp); @@ -219,8 +219,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B // Should see two subscription notifications waitForQueueToDrain(); - waitForSize(3, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(3, ourUpdatedObservations); ourClient.delete().resourceById(new IdDt("Subscription/"+ subscription2.getId())).execute(); @@ -228,8 +228,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); CodeableConceptDt codeableConcept = new CodeableConceptDt(); @@ -241,8 +241,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B // Should see no subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); @@ -255,8 +255,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(5, ourUpdatedObservations); Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); Assert.assertFalse(observation1.getId().isEmpty()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test.java index 08155fa6a2e..9311664f53c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test.java @@ -121,8 +121,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B // Should see 1 subscription notification Thread.sleep(500); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); Assert.assertNotNull(subscriptionTemp); @@ -135,8 +135,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B // Should see two subscription notifications Thread.sleep(500); - waitForSize(3, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(3, ourUpdatedObservations); ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute(); @@ -144,8 +144,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B // Should see only one subscription notification Thread.sleep(500); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); @@ -157,8 +157,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B // Should see no subscription notification Thread.sleep(500); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); @@ -171,8 +171,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B // Should see only one subscription notification Thread.sleep(500); - waitForSize(4, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(5, ourUpdatedObservations); Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); Assert.assertFalse(observation1.getId().isEmpty()); @@ -194,8 +194,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); Assert.assertNotNull(subscriptionTemp); @@ -208,8 +208,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B // Should see two subscription notifications waitForQueueToDrain(); - waitForSize(3, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(3, ourUpdatedObservations); ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute(); @@ -217,8 +217,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); @@ -230,8 +230,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B // Should see no subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); @@ -244,8 +244,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(5, ourUpdatedObservations); Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); Assert.assertFalse(observation1.getId().isEmpty()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/r4/RestHookTestR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/r4/RestHookTestR4Test.java index add67cf8057..3f05c58164a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/r4/RestHookTestR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/r4/RestHookTestR4Test.java @@ -130,8 +130,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0)); } @@ -150,8 +150,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0)); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); @@ -165,8 +165,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { waitForQueueToDrain(); // Should see two subscription notifications - waitForSize(3, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(3, ourUpdatedObservations); ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); waitForQueueToDrain(); @@ -175,8 +175,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { waitForQueueToDrain(); // Should see only one subscription notification - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); @@ -188,8 +188,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { // Should see no subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); @@ -202,8 +202,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(5, ourUpdatedObservations); Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); Assert.assertFalse(observation1.getId().isEmpty()); @@ -225,8 +225,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); @@ -239,8 +239,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { waitForQueueToDrain(); // Should see two subscription notifications - waitForSize(3, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(3, ourUpdatedObservations); ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); @@ -248,8 +248,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); @@ -261,8 +261,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { // Should see no subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); @@ -275,8 +275,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(5, ourUpdatedObservations); Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); Assert.assertFalse(observation1.getId().isEmpty()); @@ -298,8 +298,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); } @@ -338,8 +338,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0)); assertThat(ourHeaders, hasItem("X-Foo: FOO")); assertThat(ourHeaders, hasItem("X-Bar: BAR")); @@ -357,8 +357,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); // Disable subscription.setStatus(Subscription.SubscriptionStatus.OFF); @@ -370,8 +370,8 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/r4/RestHookTestWithInterceptorRegisteredToDaoConfigR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/r4/RestHookTestWithInterceptorRegisteredToDaoConfigR4Test.java index 6f834191403..7d70a3fb644 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/r4/RestHookTestWithInterceptorRegisteredToDaoConfigR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/r4/RestHookTestWithInterceptorRegisteredToDaoConfigR4Test.java @@ -126,8 +126,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base // Should see 1 subscription notification Thread.sleep(500); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); Assert.assertNotNull(subscriptionTemp); @@ -140,8 +140,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base // Should see two subscription notifications Thread.sleep(500); - waitForSize(3, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(3, ourUpdatedObservations); ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute(); @@ -149,8 +149,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base // Should see only one subscription notification Thread.sleep(500); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); @@ -162,8 +162,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base // Should see no subscription notification Thread.sleep(500); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); @@ -176,8 +176,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base // Should see only one subscription notification Thread.sleep(500); - waitForSize(4, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(5, ourUpdatedObservations); Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); Assert.assertFalse(observation1.getId().isEmpty()); @@ -199,8 +199,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base // Should see 1 subscription notification waitForQueueToDrain(); - waitForSize(1, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); Assert.assertNotNull(subscriptionTemp); @@ -213,8 +213,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base // Should see two subscription notifications waitForQueueToDrain(); - waitForSize(3, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(3, ourUpdatedObservations); ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute(); @@ -222,8 +222,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); @@ -235,8 +235,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base // Should see no subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(0, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(4, ourUpdatedObservations); Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); @@ -249,8 +249,8 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base // Should see only one subscription notification waitForQueueToDrain(); - waitForSize(4, ourCreatedObservations); - waitForSize(1, ourUpdatedObservations); + waitForSize(0, ourCreatedObservations); + waitForSize(5, ourUpdatedObservations); Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); Assert.assertFalse(observation1.getId().isEmpty()); diff --git a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/home.html b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/home.html index b65ada29664..e5d24f376ff 100644 --- a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/home.html +++ b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/home.html @@ -34,11 +34,11 @@ - + Server HAPI Restful Server - + Software - diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 6d6c934054b..8c5f223bff2 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -323,6 +323,11 @@ DSTU2 validator has been enhanced to do a better job handling ValueSets with expansions pointing to other ValueSets + + REST HOOK subscriptions now use HTTP PUT if there is a payload type + specified, regardless of whether the source event was a create or an + update +