Fix tests for #710
This commit is contained in:
parent
356d9acaf7
commit
1e158311d8
|
@ -84,7 +84,8 @@ public class RestHookSubscriptionDstu2Interceptor extends BaseRestHookSubscripti
|
||||||
*/
|
*/
|
||||||
private void checkSubscriptions(IIdType idType, String resourceType, RestOperationTypeEnum theOperation) {
|
private void checkSubscriptions(IIdType idType, String resourceType, RestOperationTypeEnum theOperation) {
|
||||||
//avoid a ConcurrentModificationException by copying to an array
|
//avoid a ConcurrentModificationException by copying to an array
|
||||||
for (Object object : myRestHookSubscriptions.toArray()) {
|
Object[] subscriptions = myRestHookSubscriptions.toArray();
|
||||||
|
for (Object object : subscriptions) {
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ public abstract class BaseResourceProviderDstu2Test extends BaseJpaDstu2Test {
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
ourClient = myFhirCtx.newRestfulGenericClient(ourServerBase);
|
ourClient = myFhirCtx.newRestfulGenericClient(ourServerBase);
|
||||||
ourClient.registerInterceptor(new LoggingInterceptor(true));
|
ourClient.registerInterceptor(new LoggingInterceptor());
|
||||||
|
|
||||||
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
||||||
HttpClientBuilder builder = HttpClientBuilder.create();
|
HttpClientBuilder builder = HttpClientBuilder.create();
|
||||||
|
|
|
@ -1,23 +1,6 @@
|
||||||
|
|
||||||
package ca.uhn.fhir.jpa.subscription;
|
package ca.uhn.fhir.jpa.subscription;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
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.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||||
import ca.uhn.fhir.jpa.provider.BaseResourceProviderDstu2Test;
|
import ca.uhn.fhir.jpa.provider.BaseResourceProviderDstu2Test;
|
||||||
|
@ -38,6 +21,19 @@ import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||||
import ca.uhn.fhir.util.PortUtil;
|
import ca.uhn.fhir.util.PortUtil;
|
||||||
|
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.instance.model.api.IIdType;
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the rest-hook subscriptions
|
* Test the rest-hook subscriptions
|
||||||
|
@ -51,12 +47,19 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
private static String ourListenerServerBase;
|
private static String ourListenerServerBase;
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RestHookTestDstu2Test.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RestHookTestDstu2Test.class);
|
||||||
private static List<Observation> ourUpdatedObservations = Lists.newArrayList();
|
private static List<Observation> ourUpdatedObservations = Lists.newArrayList();
|
||||||
|
private List<IIdType> mySubscriptionIds = new ArrayList<IIdType>();
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void afterUnregisterRestHookListener() {
|
public void afterUnregisterRestHookListener() {
|
||||||
|
for (IIdType next : mySubscriptionIds){
|
||||||
|
ourClient.delete().resourceById(next).execute();
|
||||||
|
}
|
||||||
|
mySubscriptionIds.clear();
|
||||||
|
|
||||||
myDaoConfig.setAllowMultipleDelete(true);
|
myDaoConfig.setAllowMultipleDelete(true);
|
||||||
ourLog.info("Deleting all subscriptions");
|
ourLog.info("Deleting all subscriptions");
|
||||||
ourClient.delete().resourceConditionalByUrl("Subscription?status=active").execute();
|
ourClient.delete().resourceConditionalByUrl("Subscription?status=active").execute();
|
||||||
|
ourClient.delete().resourceConditionalByUrl("Observation?code:missing=false").execute();
|
||||||
ourLog.info("Done deleting all subscriptions");
|
ourLog.info("Done deleting all subscriptions");
|
||||||
myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete());
|
myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete());
|
||||||
|
|
||||||
|
@ -77,7 +80,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
private Subscription createSubscription(String criteria, String payload, String endpoint) {
|
private Subscription createSubscription(String criteria, String payload, String endpoint) {
|
||||||
Subscription subscription = new Subscription();
|
Subscription subscription = new Subscription();
|
||||||
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
||||||
subscription.setStatus(SubscriptionStatusEnum.ACTIVE);
|
subscription.setStatus(SubscriptionStatusEnum.REQUESTED);
|
||||||
subscription.setCriteria(criteria);
|
subscription.setCriteria(criteria);
|
||||||
|
|
||||||
Channel channel = new Channel();
|
Channel channel = new Channel();
|
||||||
|
@ -88,6 +91,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
|
|
||||||
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
||||||
subscription.setId(methodOutcome.getId().getIdPart());
|
subscription.setId(methodOutcome.getId().getIdPart());
|
||||||
|
mySubscriptionIds.add(methodOutcome.getId());
|
||||||
|
|
||||||
return subscription;
|
return subscription;
|
||||||
}
|
}
|
||||||
|
@ -136,9 +140,9 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
|
|
||||||
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see two subscription notifications
|
// Should see one subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(3, ourCreatedObservations.size());
|
assertEquals(2, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
ourClient.delete().resourceById(new IdDt("Subscription/" + subscription2.getId())).execute();
|
ourClient.delete().resourceById(new IdDt("Subscription/" + subscription2.getId())).execute();
|
||||||
|
@ -147,7 +151,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId());
|
Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId());
|
||||||
|
@ -160,7 +164,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
|
|
||||||
// Should see no subscription notification
|
// Should see no subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId());
|
Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId());
|
||||||
|
@ -174,7 +178,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(1, ourUpdatedObservations.size());
|
assertEquals(1, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Assert.assertFalse(subscription1.getId().equals(subscription2.getId()));
|
Assert.assertFalse(subscription1.getId().equals(subscription2.getId()));
|
||||||
|
@ -222,9 +226,9 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
|
|
||||||
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see two subscription notifications
|
// Should see one subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(3, ourCreatedObservations.size());
|
assertEquals(ourCreatedObservations.toString(), 2, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
ourClient.delete().resourceById(new IdDt("Subscription/" + subscription2.getId())).execute();
|
ourClient.delete().resourceById(new IdDt("Subscription/" + subscription2.getId())).execute();
|
||||||
|
@ -233,7 +237,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId());
|
Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId());
|
||||||
|
@ -246,7 +250,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
|
|
||||||
// Should see no subscription notification
|
// Should see no subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId());
|
Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId());
|
||||||
|
@ -260,7 +264,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(1, ourUpdatedObservations.size());
|
assertEquals(1, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Assert.assertFalse(subscription1.getId().equals(subscription2.getId()));
|
Assert.assertFalse(subscription1.getId().equals(subscription2.getId()));
|
||||||
|
|
|
@ -8,11 +8,15 @@ import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.model.dstu2.valueset.SubscriptionChannelTypeEnum;
|
||||||
|
import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum;
|
||||||
|
import ca.uhn.fhir.util.PortUtil;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
import org.hl7.fhir.dstu3.model.*;
|
import org.hl7.fhir.dstu3.model.*;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
@ -34,21 +38,26 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||||
*/
|
*/
|
||||||
public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
|
|
||||||
private static List<String> ourContentTypes = new ArrayList<String>();
|
|
||||||
private static List<Observation> ourCreatedObservations = Lists.newArrayList();
|
private static List<Observation> ourCreatedObservations = Lists.newArrayList();
|
||||||
private static int ourListenerPort;
|
private static int ourListenerPort;
|
||||||
private static RestfulServer ourListenerRestServer;
|
private static RestfulServer ourListenerRestServer;
|
||||||
private static Server ourListenerServer;
|
private static Server ourListenerServer;
|
||||||
private static String ourListenerServerBase;
|
private static String ourListenerServerBase;
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RestHookTestDstu3Test.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RestHookTestDstu2Test.class);
|
||||||
|
|
||||||
private static List<Observation> ourUpdatedObservations = Lists.newArrayList();
|
private static List<Observation> ourUpdatedObservations = Lists.newArrayList();
|
||||||
|
private List<IIdType> mySubscriptionIds = new ArrayList<IIdType>();
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void afterUnregisterRestHookListener() {
|
public void afterUnregisterRestHookListener() {
|
||||||
|
for (IIdType next : mySubscriptionIds){
|
||||||
|
ourClient.delete().resourceById(next).execute();
|
||||||
|
}
|
||||||
|
mySubscriptionIds.clear();
|
||||||
|
|
||||||
myDaoConfig.setAllowMultipleDelete(true);
|
myDaoConfig.setAllowMultipleDelete(true);
|
||||||
ourLog.info("Deleting all subscriptions");
|
ourLog.info("Deleting all subscriptions");
|
||||||
ourClient.delete().resourceConditionalByUrl("Subscription?status=active").execute();
|
ourClient.delete().resourceConditionalByUrl("Subscription?status=active").execute();
|
||||||
|
ourClient.delete().resourceConditionalByUrl("Observation?code:missing=false").execute();
|
||||||
ourLog.info("Done deleting all subscriptions");
|
ourLog.info("Done deleting all subscriptions");
|
||||||
myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete());
|
myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete());
|
||||||
|
|
||||||
|
@ -64,38 +73,23 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
public void beforeReset() {
|
public void beforeReset() {
|
||||||
ourCreatedObservations.clear();
|
ourCreatedObservations.clear();
|
||||||
ourUpdatedObservations.clear();
|
ourUpdatedObservations.clear();
|
||||||
ourContentTypes.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private Subscription createSubscription(String criteria, String payload, String endpoint) {
|
||||||
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) {
|
|
||||||
Subscription subscription = new Subscription();
|
Subscription subscription = new Subscription();
|
||||||
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
|
||||||
subscription.setStatus(Subscription.SubscriptionStatus.ACTIVE);
|
subscription.setStatus(Subscription.SubscriptionStatus.REQUESTED);
|
||||||
subscription.setCriteria(theCriteria);
|
subscription.setCriteria(criteria);
|
||||||
|
|
||||||
Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent();
|
Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent();
|
||||||
channel.setType(Subscription.SubscriptionChannelType.RESTHOOK);
|
channel.setType(Subscription.SubscriptionChannelType.RESTHOOK);
|
||||||
channel.setPayload(thePayload);
|
channel.setPayload(payload);
|
||||||
channel.setEndpoint(theEndpoint);
|
channel.setEndpoint(endpoint);
|
||||||
subscription.setChannel(channel);
|
subscription.setChannel(channel);
|
||||||
|
|
||||||
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
|
||||||
subscription.setId(methodOutcome.getId().getIdPart());
|
subscription.setId(methodOutcome.getId().getIdPart());
|
||||||
|
mySubscriptionIds.add(methodOutcome.getId());
|
||||||
|
|
||||||
return subscription;
|
return subscription;
|
||||||
}
|
}
|
||||||
|
@ -119,27 +113,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestHookSubscriptionApplicationFhirJson() throws Exception {
|
public void testRestHookSubscriptionJson() throws Exception {
|
||||||
String payload = "application/fhir+json";
|
|
||||||
|
|
||||||
String code = "1000000050";
|
|
||||||
String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml";
|
|
||||||
String criteria2 = "Observation?code=SNOMED-CT|" + code + "111&_format=xml";
|
|
||||||
|
|
||||||
createSubscription(criteria1, payload, ourListenerServerBase);
|
|
||||||
createSubscription(criteria2, payload, ourListenerServerBase);
|
|
||||||
|
|
||||||
sendObservation(code, "SNOMED-CT");
|
|
||||||
|
|
||||||
// Should see 1 subscription notification
|
|
||||||
Thread.sleep(500);
|
|
||||||
assertEquals(1, ourCreatedObservations.size());
|
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
|
||||||
assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRestHookSubscriptionApplicationJson() throws Exception {
|
|
||||||
String payload = "application/json";
|
String payload = "application/json";
|
||||||
|
|
||||||
String code = "1000000050";
|
String code = "1000000050";
|
||||||
|
@ -155,7 +129,6 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(1, ourCreatedObservations.size());
|
assertEquals(1, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
assertEquals(Constants.CT_FHIR_JSON_NEW, ourContentTypes.get(0));
|
|
||||||
|
|
||||||
Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId());
|
Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId());
|
||||||
Assert.assertNotNull(subscriptionTemp);
|
Assert.assertNotNull(subscriptionTemp);
|
||||||
|
@ -163,21 +136,20 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
subscriptionTemp.setCriteria(criteria1);
|
subscriptionTemp.setCriteria(criteria1);
|
||||||
ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
|
ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
|
||||||
|
|
||||||
|
|
||||||
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see two subscription notifications
|
// Should see one subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(3, ourCreatedObservations.size());
|
assertEquals(2, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute();
|
ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute();
|
||||||
|
|
||||||
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId());
|
Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId());
|
||||||
|
@ -190,7 +162,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
|
|
||||||
// Should see no subscription notification
|
// Should see no subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId());
|
Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId());
|
||||||
|
@ -204,7 +176,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(1, ourUpdatedObservations.size());
|
assertEquals(1, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Assert.assertFalse(subscription1.getId().equals(subscription2.getId()));
|
Assert.assertFalse(subscription1.getId().equals(subscription2.getId()));
|
||||||
|
@ -213,28 +185,21 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestHookSubscriptionApplicationXmlJson() throws Exception {
|
public void testRestHookSubscriptionInvalidCriteria() throws Exception {
|
||||||
String payload = "application/fhir+xml";
|
String payload = "application/xml";
|
||||||
|
|
||||||
String code = "1000000050";
|
String criteria1 = "Observation?codeeeee=SNOMED-CT";
|
||||||
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);
|
try {
|
||||||
Subscription subscription2 = createSubscription(criteria2, payload, ourListenerServerBase);
|
createSubscription(criteria1, payload, ourListenerServerBase);
|
||||||
|
fail();
|
||||||
Observation observation1 = sendObservation(code, "SNOMED-CT");
|
} 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());
|
||||||
// Should see 1 subscription notification
|
}
|
||||||
Thread.sleep(500);
|
|
||||||
assertEquals(1, ourCreatedObservations.size());
|
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
|
||||||
assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestHookSubscriptionApplicationXml() throws Exception {
|
public void testRestHookSubscriptionXml() throws Exception {
|
||||||
String payload = "application/xml";
|
String payload = "application/xml";
|
||||||
|
|
||||||
String code = "1000000050";
|
String code = "1000000050";
|
||||||
|
@ -250,7 +215,6 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(1, ourCreatedObservations.size());
|
assertEquals(1, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0));
|
|
||||||
|
|
||||||
Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId());
|
Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId());
|
||||||
Assert.assertNotNull(subscriptionTemp);
|
Assert.assertNotNull(subscriptionTemp);
|
||||||
|
@ -258,21 +222,20 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
subscriptionTemp.setCriteria(criteria1);
|
subscriptionTemp.setCriteria(criteria1);
|
||||||
ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
|
ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
|
||||||
|
|
||||||
|
|
||||||
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
Observation observation2 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see two subscription notifications
|
// Should see one subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(3, ourCreatedObservations.size());
|
assertEquals(ourCreatedObservations.toString(), 2, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute();
|
ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute();
|
||||||
|
|
||||||
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
Observation observationTemp3 = sendObservation(code, "SNOMED-CT");
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId());
|
Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId());
|
||||||
|
@ -285,7 +248,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
|
|
||||||
// Should see no subscription notification
|
// Should see no subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(0, ourUpdatedObservations.size());
|
assertEquals(0, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId());
|
Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId());
|
||||||
|
@ -299,7 +262,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
|
|
||||||
// Should see only one subscription notification
|
// Should see only one subscription notification
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertEquals(4, ourCreatedObservations.size());
|
assertEquals(3, ourCreatedObservations.size());
|
||||||
assertEquals(1, ourUpdatedObservations.size());
|
assertEquals(1, ourUpdatedObservations.size());
|
||||||
|
|
||||||
Assert.assertFalse(subscription1.getId().equals(subscription2.getId()));
|
Assert.assertFalse(subscription1.getId().equals(subscription2.getId()));
|
||||||
|
@ -309,7 +272,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startListenerServer() throws Exception {
|
public static void startListenerServer() throws Exception {
|
||||||
ourListenerPort = RandomServerPortProvider.findFreePort();
|
ourListenerPort = PortUtil.findFreePort();
|
||||||
ourListenerRestServer = new RestfulServer(FhirContext.forDstu3());
|
ourListenerRestServer = new RestfulServer(FhirContext.forDstu3());
|
||||||
ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context";
|
ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context";
|
||||||
|
|
||||||
|
@ -337,9 +300,8 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
public static class ObservationListener implements IResourceProvider {
|
public static class ObservationListener implements IResourceProvider {
|
||||||
|
|
||||||
@Create
|
@Create
|
||||||
public MethodOutcome create(@ResourceParam Observation theObservation, HttpServletRequest theRequest) {
|
public MethodOutcome create(@ResourceParam Observation theObservation) {
|
||||||
ourLog.info("Received Listener Create");
|
ourLog.info("Received Listener Create");
|
||||||
ourContentTypes.add(theRequest.getHeader(Constants.HEADER_CONTENT_TYPE).replaceAll(";.*", ""));
|
|
||||||
ourCreatedObservations.add(theObservation);
|
ourCreatedObservations.add(theObservation);
|
||||||
return new MethodOutcome(new IdType("Observation/1"), true);
|
return new MethodOutcome(new IdType("Observation/1"), true);
|
||||||
}
|
}
|
||||||
|
@ -350,10 +312,9 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Update
|
@Update
|
||||||
public MethodOutcome update(@ResourceParam Observation theObservation, HttpServletRequest theRequest) {
|
public MethodOutcome update(@ResourceParam Observation theObservation) {
|
||||||
ourLog.info("Received Listener Update");
|
ourLog.info("Received Listener Update");
|
||||||
ourUpdatedObservations.add(theObservation);
|
ourUpdatedObservations.add(theObservation);
|
||||||
ourContentTypes.add(theRequest.getHeader(Constants.HEADER_CONTENT_TYPE).replaceAll(";.*", ""));
|
|
||||||
return new MethodOutcome(new IdType("Observation/1"), false);
|
return new MethodOutcome(new IdType("Observation/1"), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue