Connection handling cleanup for new tests

This commit is contained in:
James Agnew 2017-08-02 10:42:04 -04:00
parent 0e2cecfbd0
commit a4cbda357e
2 changed files with 76 additions and 65 deletions

View File

@ -60,7 +60,7 @@ public class FhirResourceDaoSearchParameterR4 extends FhirResourceDaoR4<SearchPa
ourLog.info("Marking all resources of type {} for reindexing due to updated search parameter with path: {}", expression); ourLog.info("Marking all resources of type {} for reindexing due to updated search parameter with path: {}", expression);
TransactionTemplate txTemplate = new TransactionTemplate(myPlatformTransactionManager); TransactionTemplate txTemplate = new TransactionTemplate(myPlatformTransactionManager);
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
int updatedCount = txTemplate.execute(new TransactionCallback<Integer>() { int updatedCount = txTemplate.execute(new TransactionCallback<Integer>() {
@Override @Override
public Integer doInTransaction(TransactionStatus theStatus) { public Integer doInTransaction(TransactionStatus theStatus) {

View File

@ -10,6 +10,8 @@ import org.hl7.fhir.r4.model.Appointment.AppointmentStatus;
import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender; import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.*; import org.junit.*;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.*;
import ca.uhn.fhir.jpa.dao.SearchParameterMap; import ca.uhn.fhir.jpa.dao.SearchParameterMap;
import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.Include;
@ -207,26 +209,26 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
Patient patient = new Patient(); Patient patient = new Patient();
patient.addName().setFamily("P2"); patient.addName().setFamily("P2");
Extension extParent = patient Extension extParent = patient
.addExtension() .addExtension()
.setUrl("http://acme.org/foo"); .setUrl("http://acme.org/foo");
extParent extParent
.addExtension() .addExtension()
.setUrl("http://acme.org/bar") .setUrl("http://acme.org/bar")
.setValue(new Coding().setSystem("foo").setCode("bar")); .setValue(new Coding().setSystem("foo").setCode("bar"));
IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add("foobar", new TokenParam("foo", "bar")); map.add("foobar", new TokenParam("foo", "bar"));
results = myPatientDao.search(map); results = myPatientDao.search(map);
foundResources = toUnqualifiedVersionlessIdValues(results); foundResources = toUnqualifiedVersionlessIdValues(results);
assertThat(foundResources, contains(p2id.getValue())); assertThat(foundResources, contains(p2id.getValue()));
} }
@Test @Test
public void testSearchForExtensionTwoDeepCodeableConcept() { public void testSearchForExtensionTwoDeepCodeableConcept() {
SearchParameter siblingSp = new SearchParameter(); SearchParameter siblingSp = new SearchParameter();
@ -245,19 +247,19 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
Patient patient = new Patient(); Patient patient = new Patient();
patient.addName().setFamily("P2"); patient.addName().setFamily("P2");
Extension extParent = patient Extension extParent = patient
.addExtension() .addExtension()
.setUrl("http://acme.org/foo"); .setUrl("http://acme.org/foo");
extParent extParent
.addExtension() .addExtension()
.setUrl("http://acme.org/bar") .setUrl("http://acme.org/bar")
.setValue(new CodeableConcept().addCoding(new Coding().setSystem("foo").setCode("bar"))); .setValue(new CodeableConcept().addCoding(new Coding().setSystem("foo").setCode("bar")));
IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add("foobar", new TokenParam("foo", "bar")); map.add("foobar", new TokenParam("foo", "bar"));
results = myPatientDao.search(map); results = myPatientDao.search(map);
@ -283,24 +285,24 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
Appointment apt = new Appointment(); Appointment apt = new Appointment();
apt.setStatus(AppointmentStatus.ARRIVED); apt.setStatus(AppointmentStatus.ARRIVED);
IIdType aptId = myAppointmentDao.create(apt).getId().toUnqualifiedVersionless(); IIdType aptId = myAppointmentDao.create(apt).getId().toUnqualifiedVersionless();
Patient patient = new Patient(); Patient patient = new Patient();
patient.addName().setFamily("P2"); patient.addName().setFamily("P2");
Extension extParent = patient Extension extParent = patient
.addExtension() .addExtension()
.setUrl("http://acme.org/foo"); .setUrl("http://acme.org/foo");
extParent extParent
.addExtension() .addExtension()
.setUrl("http://acme.org/bar") .setUrl("http://acme.org/bar")
.setValue(new Reference(aptId.getValue())); .setValue(new Reference(aptId.getValue()));
IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add("foobar", new ReferenceParam(aptId.getValue())); map.add("foobar", new ReferenceParam(aptId.getValue()));
results = myPatientDao.search(map); results = myPatientDao.search(map);
@ -325,31 +327,31 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
Appointment apt = new Appointment(); Appointment apt = new Appointment();
apt.setStatus(AppointmentStatus.ARRIVED); apt.setStatus(AppointmentStatus.ARRIVED);
IIdType aptId = myAppointmentDao.create(apt).getId().toUnqualifiedVersionless(); IIdType aptId = myAppointmentDao.create(apt).getId().toUnqualifiedVersionless();
Patient patient = new Patient(); Patient patient = new Patient();
patient.addName().setFamily("P2"); patient.addName().setFamily("P2");
Extension extParent = patient Extension extParent = patient
.addExtension() .addExtension()
.setUrl("http://acme.org/foo"); .setUrl("http://acme.org/foo");
extParent extParent
.addExtension() .addExtension()
.setUrl("http://acme.org/bar") .setUrl("http://acme.org/bar")
.setValue(new Reference(aptId.getValue())); .setValue(new Reference(aptId.getValue()));
IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add("foobar", new ReferenceParam(aptId.getValue())); map.add("foobar", new ReferenceParam(aptId.getValue()));
results = myPatientDao.search(map); results = myPatientDao.search(map);
foundResources = toUnqualifiedVersionlessIdValues(results); foundResources = toUnqualifiedVersionlessIdValues(results);
assertThat(foundResources, contains(p2id.getValue())); assertThat(foundResources, contains(p2id.getValue()));
} }
@Test @Test
public void testSearchForExtensionTwoDeepReference() { public void testSearchForExtensionTwoDeepReference() {
SearchParameter siblingSp = new SearchParameter(); SearchParameter siblingSp = new SearchParameter();
@ -368,24 +370,24 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
Appointment apt = new Appointment(); Appointment apt = new Appointment();
apt.setStatus(AppointmentStatus.ARRIVED); apt.setStatus(AppointmentStatus.ARRIVED);
IIdType aptId = myAppointmentDao.create(apt).getId().toUnqualifiedVersionless(); IIdType aptId = myAppointmentDao.create(apt).getId().toUnqualifiedVersionless();
Patient patient = new Patient(); Patient patient = new Patient();
patient.addName().setFamily("P2"); patient.addName().setFamily("P2");
Extension extParent = patient Extension extParent = patient
.addExtension() .addExtension()
.setUrl("http://acme.org/foo"); .setUrl("http://acme.org/foo");
extParent extParent
.addExtension() .addExtension()
.setUrl("http://acme.org/bar") .setUrl("http://acme.org/bar")
.setValue(new Reference(aptId.getValue())); .setValue(new Reference(aptId.getValue()));
IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add("foobar", new ReferenceParam(aptId.getValue())); map.add("foobar", new ReferenceParam(aptId.getValue()));
results = myPatientDao.search(map); results = myPatientDao.search(map);
@ -410,24 +412,24 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
Appointment apt = new Appointment(); Appointment apt = new Appointment();
apt.setStatus(AppointmentStatus.ARRIVED); apt.setStatus(AppointmentStatus.ARRIVED);
IIdType aptId = myAppointmentDao.create(apt).getId().toUnqualifiedVersionless(); IIdType aptId = myAppointmentDao.create(apt).getId().toUnqualifiedVersionless();
Patient patient = new Patient(); Patient patient = new Patient();
patient.addName().setFamily("P2"); patient.addName().setFamily("P2");
Extension extParent = patient Extension extParent = patient
.addExtension() .addExtension()
.setUrl("http://acme.org/foo"); .setUrl("http://acme.org/foo");
extParent extParent
.addExtension() .addExtension()
.setUrl("http://acme.org/bar") .setUrl("http://acme.org/bar")
.setValue(new DateType("2012-01-02")); .setValue(new DateType("2012-01-02"));
IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add("foobar", new DateParam("2012-01-02")); map.add("foobar", new DateParam("2012-01-02"));
results = myPatientDao.search(map); results = myPatientDao.search(map);
@ -452,19 +454,19 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
Patient patient = new Patient(); Patient patient = new Patient();
patient.addName().setFamily("P2"); patient.addName().setFamily("P2");
Extension extParent = patient Extension extParent = patient
.addExtension() .addExtension()
.setUrl("http://acme.org/foo"); .setUrl("http://acme.org/foo");
extParent extParent
.addExtension() .addExtension()
.setUrl("http://acme.org/bar") .setUrl("http://acme.org/bar")
.setValue(new IntegerType(5)); .setValue(new IntegerType(5));
IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add("foobar", new NumberParam("5")); map.add("foobar", new NumberParam("5"));
results = myPatientDao.search(map); results = myPatientDao.search(map);
@ -474,7 +476,7 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
@Test @Test
public void testSearchForExtensionTwoDeepDecimal() { public void testSearchForExtensionTwoDeepDecimal() {
SearchParameter siblingSp = new SearchParameter(); final SearchParameter siblingSp = new SearchParameter();
siblingSp.addBase("Patient"); siblingSp.addBase("Patient");
siblingSp.setCode("foobar"); siblingSp.setCode("foobar");
siblingSp.setType(org.hl7.fhir.r4.model.Enumerations.SearchParamType.NUMBER); siblingSp.setType(org.hl7.fhir.r4.model.Enumerations.SearchParamType.NUMBER);
@ -482,26 +484,38 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
siblingSp.setExpression("Patient.extension('http://acme.org/foo').extension('http://acme.org/bar')"); siblingSp.setExpression("Patient.extension('http://acme.org/foo').extension('http://acme.org/bar')");
siblingSp.setXpathUsage(org.hl7.fhir.r4.model.SearchParameter.XPathUsageType.NORMAL); siblingSp.setXpathUsage(org.hl7.fhir.r4.model.SearchParameter.XPathUsageType.NORMAL);
siblingSp.setStatus(org.hl7.fhir.r4.model.Enumerations.PublicationStatus.ACTIVE); siblingSp.setStatus(org.hl7.fhir.r4.model.Enumerations.PublicationStatus.ACTIVE);
mySearchParameterDao.create(siblingSp, mySrd);
mySearchParamRegsitry.forceRefresh(); TransactionTemplate txTemplate = new TransactionTemplate(myTxManager);
txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW);
txTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus theArg0) {
mySearchParameterDao.create(siblingSp, mySrd);
mySearchParamRegsitry.forceRefresh();
}
});
Patient patient = new Patient(); final Patient patient = new Patient();
patient.addName().setFamily("P2"); patient.addName().setFamily("P2");
Extension extParent = patient Extension extParent = patient
.addExtension() .addExtension()
.setUrl("http://acme.org/foo"); .setUrl("http://acme.org/foo");
extParent extParent
.addExtension() .addExtension()
.setUrl("http://acme.org/bar") .setUrl("http://acme.org/bar")
.setValue(new DecimalType("2.1")); .setValue(new DecimalType("2.1"));
IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); IIdType p2id = txTemplate.execute(new TransactionCallback<IIdType>() {
@Override
public IIdType doInTransaction(TransactionStatus theArg0) {
return myPatientDao.create(patient).getId().toUnqualifiedVersionless();
}
});
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add("foobar", new NumberParam("2.1")); map.add("foobar", new NumberParam("2.1"));
results = myPatientDao.search(map); results = myPatientDao.search(map);
@ -526,19 +540,19 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
Patient patient = new Patient(); Patient patient = new Patient();
patient.addName().setFamily("P2"); patient.addName().setFamily("P2");
Extension extParent = patient Extension extParent = patient
.addExtension() .addExtension()
.setUrl("http://acme.org/foo"); .setUrl("http://acme.org/foo");
extParent extParent
.addExtension() .addExtension()
.setUrl("http://acme.org/bar") .setUrl("http://acme.org/bar")
.setValue(new StringType("HELLOHELLO")); .setValue(new StringType("HELLOHELLO"));
IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless();
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add("foobar", new StringParam("hello")); map.add("foobar", new StringParam("hello"));
results = myPatientDao.search(map); results = myPatientDao.search(map);
@ -573,7 +587,7 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
// Search by ref // Search by ref
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add("sibling", new ReferenceParam(p1id.getValue())); map.add("sibling", new ReferenceParam(p1id.getValue()));
@ -590,8 +604,6 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
} }
@Test @Test
public void testSearchForExtensionReferenceWithoutTarget() { public void testSearchForExtensionReferenceWithoutTarget() {
SearchParameter siblingSp = new SearchParameter(); SearchParameter siblingSp = new SearchParameter();
@ -622,7 +634,7 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
// Search by ref // Search by ref
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add("sibling", new ReferenceParam(p1id.getValue())); map.add("sibling", new ReferenceParam(p1id.getValue()));
@ -644,7 +656,6 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
foundResources = toUnqualifiedVersionlessIdValues(results); foundResources = toUnqualifiedVersionlessIdValues(results);
assertThat(foundResources, containsInAnyOrder(appid.getValue())); assertThat(foundResources, containsInAnyOrder(appid.getValue()));
} }
@Test @Test
@ -674,11 +685,11 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
Appointment app = new Appointment(); Appointment app = new Appointment();
app.addParticipant().getActor().setReference(p2id.getValue()); app.addParticipant().getActor().setReference(p2id.getValue());
IIdType appid = myAppointmentDao.create(app).getId().toUnqualifiedVersionless(); IIdType appid = myAppointmentDao.create(app).getId().toUnqualifiedVersionless();
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
// Search by ref // Search by ref
map = new SearchParameterMap(); map = new SearchParameterMap();
map.add("sibling", new ReferenceParam(p1id.getValue())); map.add("sibling", new ReferenceParam(p1id.getValue()));
@ -729,11 +740,11 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
Appointment app = new Appointment(); Appointment app = new Appointment();
app.addParticipant().getActor().setReference(p2id.getValue()); app.addParticipant().getActor().setReference(p2id.getValue());
IIdType appId = myAppointmentDao.create(app).getId().toUnqualifiedVersionless(); IIdType appId = myAppointmentDao.create(app).getId().toUnqualifiedVersionless();
SearchParameterMap map; SearchParameterMap map;
IBundleProvider results; IBundleProvider results;
List<String> foundResources; List<String> foundResources;
map = new SearchParameterMap(); map = new SearchParameterMap();
map.addInclude(new Include("Appointment:patient", true)); map.addInclude(new Include("Appointment:patient", true));
map.addInclude(new Include("Patient:attending", true)); map.addInclude(new Include("Patient:attending", true));
@ -846,7 +857,7 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
assertThat(foundResources, contains(patId.getValue())); assertThat(foundResources, contains(patId.getValue()));
} }
@Test @Test
public void testCustomReferenceParameter() throws Exception { public void testCustomReferenceParameter() throws Exception {
SearchParameter sp = new SearchParameter(); SearchParameter sp = new SearchParameter();
@ -858,15 +869,15 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test
sp.setXpathUsage(org.hl7.fhir.r4.model.SearchParameter.XPathUsageType.NORMAL); sp.setXpathUsage(org.hl7.fhir.r4.model.SearchParameter.XPathUsageType.NORMAL);
sp.setStatus(org.hl7.fhir.r4.model.Enumerations.PublicationStatus.ACTIVE); sp.setStatus(org.hl7.fhir.r4.model.Enumerations.PublicationStatus.ACTIVE);
mySearchParameterDao.create(sp); mySearchParameterDao.create(sp);
org.hl7.fhir.r4.model.Practitioner pract = new org.hl7.fhir.r4.model.Practitioner(); org.hl7.fhir.r4.model.Practitioner pract = new org.hl7.fhir.r4.model.Practitioner();
pract.setId("A"); pract.setId("A");
pract.addName().setFamily("PRACT"); pract.addName().setFamily("PRACT");
myPractitionerDao.update(pract); myPractitionerDao.update(pract);
Patient pat = myFhirCtx.newJsonParser().parseResource(Patient.class, loadClasspath("/r4/custom_resource_patient.json")); Patient pat = myFhirCtx.newJsonParser().parseResource(Patient.class, loadClasspath("/r4/custom_resource_patient.json"));
IIdType pid = myPatientDao.create(pat, mySrd).getId().toUnqualifiedVersionless(); IIdType pid = myPatientDao.create(pat, mySrd).getId().toUnqualifiedVersionless();
SearchParameterMap params = new SearchParameterMap(); SearchParameterMap params = new SearchParameterMap();
params.add("myDoctor", new ReferenceParam("A")); params.add("myDoctor", new ReferenceParam("A"));
IBundleProvider outcome = myPatientDao.search(params); IBundleProvider outcome = myPatientDao.search(params);