fix empi tests so they work with Spring Batch

(all but one test fixed)
This commit is contained in:
Ken Stevens 2020-06-25 11:14:42 -04:00
parent e51c5b5263
commit 93da042d19
7 changed files with 27 additions and 7 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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());
}

View File

@ -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

View File

@ -116,7 +116,7 @@ public class EmpiLinkSvcTest extends BaseEmpiR4Test {
.setTargetPid(theTargetPid)
.setLinkSource(EmpiLinkSourceEnum.MANUAL)
.setMatchResult(EmpiMatchResultEnum.NO_MATCH);
myEmpiLinkDaoSvc.save(noMatchLink);
saveLink(noMatchLink);
}
@Test

View File

@ -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();