Test fixes

This commit is contained in:
jamesagnew 2021-10-11 21:31:42 -04:00
parent c73fd288f0
commit 8da38d1a9e
2 changed files with 35 additions and 34 deletions

View File

@ -89,8 +89,8 @@ public class BulkDataImportR4Test extends BaseJpaR4Test implements ITestDataBuil
public void testFlow_ErrorDuringWrite() { public void testFlow_ErrorDuringWrite() {
myInterceptorRegistry.registerInterceptor(new MyFailAfterThreeCreatesInterceptor()); myInterceptorRegistry.registerInterceptor(new MyFailAfterThreeCreatesInterceptor());
int transactionsPerFile = 10; int transactionsPerFile = 5;
int fileCount = 10; int fileCount = 5;
List<BulkImportJobFileJson> files = createInputFiles(transactionsPerFile, fileCount); List<BulkImportJobFileJson> files = createInputFiles(transactionsPerFile, fileCount);
BulkImportJobJson job = new BulkImportJobJson(); BulkImportJobJson job = new BulkImportJobJson();

View File

@ -28,6 +28,7 @@ import javax.mail.internet.MimeMessage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import static ca.uhn.fhir.jpa.subscription.resthook.RestHookTestDstu3Test.logAllInterceptors; import static ca.uhn.fhir.jpa.subscription.resthook.RestHookTestDstu3Test.logAllInterceptors;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -83,7 +84,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
myDaoConfig.setEmailFromAddress("123@hapifhir.io"); myDaoConfig.setEmailFromAddress("123@hapifhir.io");
} }
private Subscription createSubscription(String theCriteria, String thePayload) throws InterruptedException { private Subscription createSubscription(String theCriteria, String thePayload, Consumer<Subscription>... theModifiers) throws InterruptedException {
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.REQUESTED); subscription.setStatus(Subscription.SubscriptionStatus.REQUESTED);
@ -95,6 +96,12 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
channel.setEndpoint("mailto:foo@example.com"); channel.setEndpoint("mailto:foo@example.com");
subscription.setChannel(channel); subscription.setChannel(channel);
if (theModifiers != null) {
for (Consumer<Subscription> next : theModifiers) {
next.accept(subscription);
}
}
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()); mySubscriptionIds.add(methodOutcome.getId());
@ -157,17 +164,15 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
/** /**
* Tests an email subscription with payload set to JSON. The email sent must include content in the body of the email that is formatted as JSON. * Tests an email subscription with payload set to JSON. The email sent must include content in the body of the email that is formatted as JSON.
*/ */
@SuppressWarnings("unchecked")
@Test @Test
public void testEmailSubscriptionWithCustom() throws Exception { public void testEmailSubscriptionWithCustom() throws Exception {
String payload = "application/fhir+json"; String payload = "application/fhir+json";
String code = "1000000050"; String code = "1000000050";
String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml"; String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml";
Subscription sub1 = createSubscription(criteria1, payload);
Subscription subscriptionTemp = ourClient.read(Subscription.class, sub1.getId());
assertNotNull(subscriptionTemp);
Consumer<Subscription> modifier = subscriptionTemp->{
subscriptionTemp.getChannel().addExtension() subscriptionTemp.getChannel().addExtension()
.setUrl(HapiExtensions.EXT_SUBSCRIPTION_EMAIL_FROM) .setUrl(HapiExtensions.EXT_SUBSCRIPTION_EMAIL_FROM)
.setValue(new StringType("mailto:myfrom@from.com")); .setValue(new StringType("mailto:myfrom@from.com"));
@ -175,12 +180,12 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
.setUrl(HapiExtensions.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE) .setUrl(HapiExtensions.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE)
.setValue(new StringType("This is a subject")); .setValue(new StringType("This is a subject"));
subscriptionTemp.setIdElement(subscriptionTemp.getIdElement().toUnqualifiedVersionless()); subscriptionTemp.setIdElement(subscriptionTemp.getIdElement().toUnqualifiedVersionless());
};
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(subscriptionTemp)); Subscription sub1 = createSubscription(criteria1, payload, modifier);
ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
waitForQueueToDrain(); waitForQueueToDrain();
mySubscriptionTestUtil.setEmailSender(subscriptionTemp.getIdElement(), new EmailSenderImpl(withMailConfig())); mySubscriptionTestUtil.setEmailSender(sub1.getIdElement(), new EmailSenderImpl(withMailConfig()));
sendObservation(code, "SNOMED-CT"); sendObservation(code, "SNOMED-CT");
waitForQueueToDrain(); waitForQueueToDrain();
@ -213,10 +218,8 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
String code = "1000000050"; String code = "1000000050";
String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml"; String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml";
Subscription sub1 = createSubscription(criteria1, payload);
Subscription subscriptionTemp = ourClient.read(Subscription.class, sub1.getId()); Consumer<Subscription> modifier = subscriptionTemp ->{
assertNotNull(subscriptionTemp);
subscriptionTemp.getChannel().addExtension() subscriptionTemp.getChannel().addExtension()
.setUrl(HapiExtensions.EXT_SUBSCRIPTION_EMAIL_FROM) .setUrl(HapiExtensions.EXT_SUBSCRIPTION_EMAIL_FROM)
.setValue(new StringType("myfrom@from.com")); .setValue(new StringType("myfrom@from.com"));
@ -224,12 +227,12 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
.setUrl(HapiExtensions.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE) .setUrl(HapiExtensions.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE)
.setValue(new StringType("This is a subject")); .setValue(new StringType("This is a subject"));
subscriptionTemp.setIdElement(subscriptionTemp.getIdElement().toUnqualifiedVersionless()); subscriptionTemp.setIdElement(subscriptionTemp.getIdElement().toUnqualifiedVersionless());
};
IIdType id = ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute().getId(); Subscription sub1 = createSubscription(criteria1, payload, modifier);
ourLog.info("Subscription ID is: {}", id.getValue());
waitForQueueToDrain(); waitForQueueToDrain();
mySubscriptionTestUtil.setEmailSender(subscriptionTemp.getIdElement(), new EmailSenderImpl(withMailConfig())); mySubscriptionTestUtil.setEmailSender(sub1.getIdElement(), new EmailSenderImpl(withMailConfig()));
sendObservation(code, "SNOMED-CT"); sendObservation(code, "SNOMED-CT");
waitForQueueToDrain(); waitForQueueToDrain();
@ -248,11 +251,9 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
assertEquals("", received.get(0).getContent().toString().trim()); assertEquals("", received.get(0).getContent().toString().trim());
assertEquals(mySubscriptionIds.get(0).toUnqualifiedVersionless().getValue(), received.get(0).getHeader("X-FHIR-Subscription")[0]); assertEquals(mySubscriptionIds.get(0).toUnqualifiedVersionless().getValue(), received.get(0).getHeader("X-FHIR-Subscription")[0]);
ourLog.info("Subscription: {}", myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(ourClient.history().onInstance(id).andReturnBundle(Bundle.class).execute())); Subscription subscription = ourClient.read().resource(Subscription.class).withId(sub1.getIdElement().toUnqualifiedVersionless()).execute();
Subscription subscription = ourClient.read().resource(Subscription.class).withId(id.toUnqualifiedVersionless()).execute();
assertEquals(Subscription.SubscriptionStatus.ACTIVE, subscription.getStatus()); assertEquals(Subscription.SubscriptionStatus.ACTIVE, subscription.getStatus());
assertEquals("3", subscription.getIdElement().getVersionIdPart()); assertEquals("2", subscription.getIdElement().getVersionIdPart());
} }
private void waitForQueueToDrain() throws InterruptedException { private void waitForQueueToDrain() throws InterruptedException {