From bf6f763691b450783013ce0fc476ce4dea4782c3 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Fri, 20 May 2022 16:56:27 -0700 Subject: [PATCH] 20220520 mdm test failure (#3629) * wip fix test * move to override in test class * Test fixes * Add failsafe to other projects which have ITs * Fix test * Fix test to use transaction Co-authored-by: Ken Stevens --- hapi-fhir-jpaserver-mdm/pom.xml | 28 +++++++++++++++++++ .../ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java | 10 +++++++ .../fhir/jpa/mdm/interceptor/MdmEventIT.java | 1 - .../MdmSearchExpandingInterceptorIT.java | 28 ++++++++++--------- .../interceptor/MdmStorageInterceptorIT.java | 26 ++++++++++------- .../jpa/mdm/svc/MdmCandidateSearchSvcIT.java | 2 +- hapi-fhir-server/pom.xml | 28 +++++++++++++++++++ .../uhn/fhir/rest/server/mail/MailSvcIT.java | 2 ++ 8 files changed, 100 insertions(+), 25 deletions(-) diff --git a/hapi-fhir-jpaserver-mdm/pom.xml b/hapi-fhir-jpaserver-mdm/pom.xml index 83aa56bd462..bfea37f93c2 100644 --- a/hapi-fhir-jpaserver-mdm/pom.xml +++ b/hapi-fhir-jpaserver-mdm/pom.xml @@ -85,6 +85,34 @@ + + org.apache.maven.plugins + maven-failsafe-plugin + + 1 + false + alphabetical + + **/*IT.java + + false + + + + + integration-test + verify + + + + + + org.junit.jupiter + junit-jupiter-engine + ${junit_version} + + + org.jacoco jacoco-maven-plugin diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java index b66dd12c67a..c91e3f6f2ef 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/BaseMdmR4Test.java @@ -140,6 +140,11 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test { myRequestDetails = new ServletRequestDetails(myInterceptorBroadcaster); } + @Override + public void beforeUnregisterAllSubscriptions() { + //no-op + } + @AfterEach public void after() throws IOException { myMdmLinkDao.deleteAll(); @@ -198,6 +203,11 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test { return patient; } + @Override + public void afterResetInterceptors() { + //no-op + } + @Nonnull protected Patient createPatientOnPartition(Patient thePatient, boolean theMdmManaged, boolean isRedirect, RequestPartitionId theRequestPartitionId) { if (theMdmManaged) { diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmEventIT.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmEventIT.java index 995a8e1932e..7218fe8bb89 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmEventIT.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmEventIT.java @@ -43,7 +43,6 @@ import static org.slf4j.LoggerFactory.getLogger; @TestPropertySource(properties = { "mdm.prevent_multiple_eids=false" }) -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @ContextConfiguration(classes = {MdmHelperConfig.class}) public class MdmEventIT extends BaseMdmR4Test { diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmSearchExpandingInterceptorIT.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmSearchExpandingInterceptorIT.java index 8a87c2aa1e6..d90e04ca1cc 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmSearchExpandingInterceptorIT.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmSearchExpandingInterceptorIT.java @@ -41,7 +41,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.slf4j.LoggerFactory.getLogger; -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @ContextConfiguration(classes = {MdmHelperConfig.class}) public class MdmSearchExpandingInterceptorIT extends BaseMdmR4Test { @@ -177,18 +176,21 @@ public class MdmSearchExpandingInterceptorIT extends BaseMdmR4Test { // test myDaoConfig.setAllowMdmExpansion(true); IFhirResourceDaoPatient dao = (IFhirResourceDaoPatient) myPatientDao; - IBundleProvider outcome = dao.patientInstanceEverything( - req, - new IdDt(id), - null, - null, - null, - null, - null, - null, - null, - theDetails - ); + IBundleProvider outcome = runInTransaction(() -> { + IBundleProvider res = dao.patientInstanceEverything( + req, + new IdDt(id), + null, + null, + null, + null, + null, + null, + null, + theDetails + ); + return res; + }); // verify return results // we expect all the linked ids to be returned too diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java index 85aabecbc74..31c1dbb4acf 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmStorageInterceptorIT.java @@ -22,6 +22,7 @@ import org.hl7.fhir.r4.model.Medication; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.SearchParameter; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; @@ -50,7 +51,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.fail; import static org.slf4j.LoggerFactory.getLogger; -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @ContextConfiguration(classes = {MdmHelperConfig.class}) public class MdmStorageInterceptorIT extends BaseMdmR4Test { @@ -62,6 +62,12 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { @Autowired private IJpaIdHelperService myIdHelperService; + + @Override + public void beforeUnregisterAllSubscriptions() { + // noop + } + @Test public void testCreatePractitioner() throws InterruptedException { myMdmHelper.createWithLatch(buildPractitionerWithNameAndId("somename", "some_id")); @@ -98,7 +104,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { myMdmHelper.doCreateResource(patient, true); fail(); } catch (ForbiddenOperationException e) { - assertThat(e.getMessage(), startsWith("Cannot create or modify Resources that are managed by MDM.")); + assertThat(e.getMessage(), startsWith("HAPI-0765: Cannot create or modify Resources that are managed by MDM.")); } } @@ -110,7 +116,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { myMdmHelper.doCreateResource(patient, true); fail(); } catch (ForbiddenOperationException e) { - assertThat(e.getMessage(), startsWith("Cannot create or modify Resources that are managed by MDM.")); + assertThat(e.getMessage(), startsWith("HAPI-0765: Cannot create or modify Resources that are managed by MDM.")); } } @@ -122,7 +128,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { myMdmHelper.doCreateResource(medication, true); fail(); } catch (ForbiddenOperationException e) { - assertThat(e.getMessage(), startsWith("Cannot create or modify Resources that are managed by MDM.")); + assertThat(e.getMessage(), startsWith("HAPI-0765: Cannot create or modify Resources that are managed by MDM.")); } } @@ -150,7 +156,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { myMdmHelper.doCreateResource(organization, true); fail(); } catch (ForbiddenOperationException e) { - assertThat(e.getMessage(), startsWith("Cannot create or modify Resources that are managed by MDM.")); + assertThat(e.getMessage(), startsWith("HAPI-0765: Cannot create or modify Resources that are managed by MDM.")); } } @@ -164,7 +170,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { myMdmHelper.doUpdateResource(organization, true); fail(); } catch (ForbiddenOperationException e) { - assertEquals("The HAPI-MDM tag on a resource may not be changed once created.", e.getMessage()); + assertEquals("HAPI-0764: The HAPI-MDM tag on a resource may not be changed once created.", e.getMessage()); } } @@ -195,7 +201,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { myMdmHelper.doUpdateResource(patient, true); fail(); } catch (ForbiddenOperationException e) { - assertEquals("The HAPI-MDM tag on a resource may not be changed once created.", e.getMessage()); + assertEquals("HAPI-0764: The HAPI-MDM tag on a resource may not be changed once created.", e.getMessage()); } } @@ -216,7 +222,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { myMdmHelper.doUpdateResource(goldenResourcePatient, true); fail(); } catch (ForbiddenOperationException e) { - assertThat(e.getMessage(), startsWith("Cannot create or modify Resources that are managed by MDM.")); + assertThat(e.getMessage(), startsWith("HAPI-0765: Cannot create or modify Resources that are managed by MDM.")); } } @@ -264,7 +270,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { myMdmHelper.doUpdateResource(jane, true); fail(); } catch (ForbiddenOperationException e) { - assertThat(e.getMessage(), is(equalTo("While running with EID updates disabled, EIDs may not be updated on source resources"))); + assertThat(e.getMessage(), is(equalTo("HAPI-0763: While running with EID updates disabled, EIDs may not be updated on source resources"))); } setPreventEidUpdates(false); } @@ -279,7 +285,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test { myMdmHelper.doCreateResource(patient, true); fail(); } catch (ForbiddenOperationException e) { - assertThat(e.getMessage(), is(equalTo("While running with multiple EIDs disabled, source resources may have at most one EID."))); + assertThat(e.getMessage(), is(equalTo("HAPI-0766: While running with multiple EIDs disabled, source resources may have at most one EID."))); } setPreventMultipleEids(false); diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmCandidateSearchSvcIT.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmCandidateSearchSvcIT.java index f283683458e..eb6dcfd6847 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmCandidateSearchSvcIT.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmCandidateSearchSvcIT.java @@ -145,7 +145,7 @@ public class MdmCandidateSearchSvcIT extends BaseMdmR4Test { myMdmCandidateSearchSvc.findCandidates("Patient", newJane, RequestPartitionId.allPartitions()); fail(); } catch (TooManyCandidatesException e) { - assertEquals("More than 3 candidate matches found for Patient?identifier=http%3A%2F%2Fa.tv%2F%7CID.JANE.123&active=true. Aborting mdm matching.", e.getMessage()); + assertEquals("HAPI-0762: More than 3 candidate matches found for Patient?identifier=http%3A%2F%2Fa.tv%2F%7CID.JANE.123&active=true. Aborting mdm matching.", e.getMessage()); } } diff --git a/hapi-fhir-server/pom.xml b/hapi-fhir-server/pom.xml index 8e337c0ae4b..22b73c28e4b 100644 --- a/hapi-fhir-server/pom.xml +++ b/hapi-fhir-server/pom.xml @@ -136,6 +136,34 @@ @{argLine} ${surefire_jvm_args} + + org.apache.maven.plugins + maven-failsafe-plugin + + 1 + false + alphabetical + + **/*IT.java + + false + + + + + integration-test + verify + + + + + + org.junit.jupiter + junit-jupiter-engine + ${junit_version} + + + org.apache.felix maven-bundle-plugin diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/mail/MailSvcIT.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/mail/MailSvcIT.java index f1075ffb98a..206a623ff6f 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/mail/MailSvcIT.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/mail/MailSvcIT.java @@ -71,8 +71,10 @@ public class MailSvcIT { public void testSendMailWithInvalidToAddress() { // setup final Email email = withEmail("xyz"); + // execute fixture.sendMail(email); + // validate assertTrue(ourGreenMail.waitForIncomingEmail(1000, 0)); final MimeMessage[] receivedMessages = ourGreenMail.getReceivedMessages();