From 93da042d19138c328006f04b8534338ef6f05b1f Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Thu, 25 Jun 2020 11:14:42 -0400 Subject: [PATCH] fix empi tests so they work with Spring Batch (all but one test fixed) --- .../ca/uhn/fhir/jpa/dao/EmpiLinkDaoSvc.java | 1 + .../ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java | 21 ++++++++++++++++++- .../jpa/empi/interceptor/EmpiExpungeTest.java | 2 +- .../jpa/empi/provider/BaseLinkR4Test.java | 2 +- .../provider/EmpiProviderQueryLinkR4Test.java | 2 +- .../fhir/jpa/empi/svc/EmpiLinkSvcTest.java | 2 +- .../jpa/empi/svc/EmpiPersonMergerSvcTest.java | 4 ++-- 7 files changed, 27 insertions(+), 7 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/EmpiLinkDaoSvc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/EmpiLinkDaoSvc.java index 8cf57e23bf3..cd64a83c289 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/EmpiLinkDaoSvc.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/EmpiLinkDaoSvc.java @@ -52,6 +52,7 @@ public class EmpiLinkDaoSvc { @Autowired private IdHelperService myIdHelperService; + @Transactional public EmpiLink createOrUpdateLinkEntity(IBaseResource thePerson, IBaseResource theTarget, EmpiMatchResultEnum theMatchResult, EmpiLinkSourceEnum theLinkSource, @Nullable EmpiTransactionContext theEmpiTransactionContext) { Long personPid = myIdHelperService.getPidOrNull(thePerson); Long resourcePid = myIdHelperService.getPidOrNull(theTarget); diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java index 6b0fa70e17b..54cf3786b38 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java @@ -48,8 +48,11 @@ import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.support.TransactionTemplate; import javax.annotation.Nonnull; +import javax.annotation.PostConstruct; import java.util.Collections; import java.util.Date; import java.util.List; @@ -99,16 +102,32 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test { EmpiSearchParameterLoader myEmpiSearchParameterLoader; @Autowired SearchParamRegistryImpl mySearchParamRegistry; + @Autowired + private PlatformTransactionManager myPlatformTransactionManager; + + private TransactionTemplate myTxTemplate; + + @PostConstruct + public void initTxTemplate() { + myTxTemplate = new TransactionTemplate(myPlatformTransactionManager); + } protected ServletRequestDetails myRequestDetails = new ServletRequestDetails(null); @Override @After public void after() { - myEmpiLinkDao.deleteAll(); + // TODO KHS Why does adding Spring Batch now require us to wrap this in a transaction? + myTxTemplate.executeWithoutResult(t -> myEmpiLinkDao.deleteAll()); + assertEquals(0, myEmpiLinkDao.count()); super.after(); } + // TODO KHS Why does adding Spring Batch now require us to wrap this in a transaction? + protected void saveLink(EmpiLink theNoMatchLink) { + myTxTemplate.executeWithoutResult(t -> myEmpiLinkDaoSvc.save(theNoMatchLink)); + } + @Nonnull protected Person createUnmanagedPerson() { return createPerson(new Person(), false); diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiExpungeTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiExpungeTest.java index 051db629424..4f12fdb295e 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiExpungeTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiExpungeTest.java @@ -50,7 +50,7 @@ public class EmpiExpungeTest extends BaseEmpiR4Test { empiLink.setMatchResult(EmpiMatchResultEnum.MATCH); empiLink.setPersonPid(myPersonEntity.getId()); empiLink.setTargetPid(myTargetEntity.getId()); - myEmpiLinkDaoSvc.save(empiLink); + saveLink(empiLink); } @Test diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseLinkR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseLinkR4Test.java index 6687d91d7c0..38a610678f7 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseLinkR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseLinkR4Test.java @@ -41,7 +41,7 @@ public abstract class BaseLinkR4Test extends BaseProviderR4Test { myLink = getOnlyPatientLink(); // Tests require our initial link to be a POSSIBLE_MATCH myLink.setMatchResult(EmpiMatchResultEnum.POSSIBLE_MATCH); - myEmpiLinkDao.save(myLink); + saveLink(myLink); assertEquals(EmpiLinkSourceEnum.AUTO, myLink.getLinkSource()); } diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderQueryLinkR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderQueryLinkR4Test.java index a9b9356c23b..ba86ca7f11c 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderQueryLinkR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderQueryLinkR4Test.java @@ -47,7 +47,7 @@ public class EmpiProviderQueryLinkR4Test extends BaseLinkR4Test { myPerson2Id = new StringType(person2.getIdElement().toVersionless().getValue()); Long person2Pid = myIdHelperService.getPidOrNull(person2); EmpiLink possibleDuplicateEmpiLink = new EmpiLink().setPersonPid(person1Pid).setTargetPid(person2Pid).setMatchResult(EmpiMatchResultEnum.POSSIBLE_DUPLICATE).setLinkSource(EmpiLinkSourceEnum.AUTO); - myEmpiLinkDaoSvc.save(possibleDuplicateEmpiLink); + saveLink(possibleDuplicateEmpiLink); } @Test diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcTest.java index ea95311fac1..a9047326dd5 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcTest.java @@ -116,7 +116,7 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test { .setTargetPid(theTargetPid) .setLinkSource(EmpiLinkSourceEnum.MANUAL) .setMatchResult(EmpiMatchResultEnum.NO_MATCH); - myEmpiLinkDaoSvc.save(noMatchLink); + saveLink(noMatchLink); } @Test diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonMergerSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonMergerSvcTest.java index 7294794b71c..f9f15933fe1 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonMergerSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonMergerSvcTest.java @@ -164,7 +164,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test { EmpiLink fromLink = createEmpiLink(myFromPerson, myTargetPatient1); fromLink.setLinkSource(EmpiLinkSourceEnum.MANUAL); fromLink.setMatchResult(EmpiMatchResultEnum.MATCH); - myEmpiLinkDaoSvc.save(fromLink); + saveLink(fromLink); createEmpiLink(myToPerson, myTargetPatient1); @@ -214,7 +214,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test { EmpiLink toLink = createEmpiLink(myToPerson, myTargetPatient1); toLink.setLinkSource(EmpiLinkSourceEnum.MANUAL); toLink.setMatchResult(EmpiMatchResultEnum.MATCH); - myEmpiLinkDaoSvc.save(toLink); + saveLink(toLink); try { mergePersons();