diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java index 5cc196ed8ea..66a7ffb7591 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/imprt/svc/BulkDataImportR4Test.java @@ -89,8 +89,8 @@ public class BulkDataImportR4Test extends BaseJpaR4Test implements ITestDataBuil public void testFlow_ErrorDuringWrite() { myInterceptorRegistry.registerInterceptor(new MyFailAfterThreeCreatesInterceptor()); - int transactionsPerFile = 10; - int fileCount = 10; + int transactionsPerFile = 5; + int fileCount = 5; List files = createInputFiles(transactionsPerFile, fileCount); BulkImportJobJson job = new BulkImportJobJson(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu3Test.java index c258e362377..873ae422d7a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu3Test.java @@ -28,6 +28,7 @@ import javax.mail.internet.MimeMessage; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.function.Consumer; import static ca.uhn.fhir.jpa.subscription.resthook.RestHookTestDstu3Test.logAllInterceptors; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -83,7 +84,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { myDaoConfig.setEmailFromAddress("123@hapifhir.io"); } - private Subscription createSubscription(String theCriteria, String thePayload) throws InterruptedException { + private Subscription createSubscription(String theCriteria, String thePayload, Consumer... theModifiers) throws InterruptedException { Subscription subscription = new Subscription(); subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)"); subscription.setStatus(Subscription.SubscriptionStatus.REQUESTED); @@ -95,6 +96,12 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { channel.setEndpoint("mailto:foo@example.com"); subscription.setChannel(channel); + if (theModifiers != null) { + for (Consumer next : theModifiers) { + next.accept(subscription); + } + } + MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute(); subscription.setId(methodOutcome.getId().getIdPart()); mySubscriptionIds.add(methodOutcome.getId()); @@ -157,30 +164,28 @@ 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. */ + @SuppressWarnings("unchecked") @Test public void testEmailSubscriptionWithCustom() throws Exception { String payload = "application/fhir+json"; String code = "1000000050"; 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 modifier = subscriptionTemp->{ + subscriptionTemp.getChannel().addExtension() + .setUrl(HapiExtensions.EXT_SUBSCRIPTION_EMAIL_FROM) + .setValue(new StringType("mailto:myfrom@from.com")); + subscriptionTemp.getChannel().addExtension() + .setUrl(HapiExtensions.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE) + .setValue(new StringType("This is a subject")); + subscriptionTemp.setIdElement(subscriptionTemp.getIdElement().toUnqualifiedVersionless()); + }; - subscriptionTemp.getChannel().addExtension() - .setUrl(HapiExtensions.EXT_SUBSCRIPTION_EMAIL_FROM) - .setValue(new StringType("mailto:myfrom@from.com")); - subscriptionTemp.getChannel().addExtension() - .setUrl(HapiExtensions.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE) - .setValue(new StringType("This is a subject")); - subscriptionTemp.setIdElement(subscriptionTemp.getIdElement().toUnqualifiedVersionless()); + Subscription sub1 = createSubscription(criteria1, payload, modifier); - ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(subscriptionTemp)); - - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); waitForQueueToDrain(); - mySubscriptionTestUtil.setEmailSender(subscriptionTemp.getIdElement(), new EmailSenderImpl(withMailConfig())); + mySubscriptionTestUtil.setEmailSender(sub1.getIdElement(), new EmailSenderImpl(withMailConfig())); sendObservation(code, "SNOMED-CT"); waitForQueueToDrain(); @@ -213,23 +218,21 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { String code = "1000000050"; String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml"; - Subscription sub1 = createSubscription(criteria1, payload); - Subscription subscriptionTemp = ourClient.read(Subscription.class, sub1.getId()); - assertNotNull(subscriptionTemp); - subscriptionTemp.getChannel().addExtension() - .setUrl(HapiExtensions.EXT_SUBSCRIPTION_EMAIL_FROM) - .setValue(new StringType("myfrom@from.com")); - subscriptionTemp.getChannel().addExtension() - .setUrl(HapiExtensions.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE) - .setValue(new StringType("This is a subject")); - subscriptionTemp.setIdElement(subscriptionTemp.getIdElement().toUnqualifiedVersionless()); + Consumer modifier = subscriptionTemp ->{ + subscriptionTemp.getChannel().addExtension() + .setUrl(HapiExtensions.EXT_SUBSCRIPTION_EMAIL_FROM) + .setValue(new StringType("myfrom@from.com")); + subscriptionTemp.getChannel().addExtension() + .setUrl(HapiExtensions.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE) + .setValue(new StringType("This is a subject")); + subscriptionTemp.setIdElement(subscriptionTemp.getIdElement().toUnqualifiedVersionless()); + }; - IIdType id = ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute().getId(); - ourLog.info("Subscription ID is: {}", id.getValue()); + Subscription sub1 = createSubscription(criteria1, payload, modifier); waitForQueueToDrain(); - mySubscriptionTestUtil.setEmailSender(subscriptionTemp.getIdElement(), new EmailSenderImpl(withMailConfig())); + mySubscriptionTestUtil.setEmailSender(sub1.getIdElement(), new EmailSenderImpl(withMailConfig())); sendObservation(code, "SNOMED-CT"); waitForQueueToDrain(); @@ -248,11 +251,9 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { assertEquals("", received.get(0).getContent().toString().trim()); 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(id.toUnqualifiedVersionless()).execute(); + Subscription subscription = ourClient.read().resource(Subscription.class).withId(sub1.getIdElement().toUnqualifiedVersionless()).execute(); assertEquals(Subscription.SubscriptionStatus.ACTIVE, subscription.getStatus()); - assertEquals("3", subscription.getIdElement().getVersionIdPart()); + assertEquals("2", subscription.getIdElement().getVersionIdPart()); } private void waitForQueueToDrain() throws InterruptedException {