Add test for #438

This commit is contained in:
James Agnew 2016-10-21 11:40:50 -04:00
parent 173d40496d
commit 27208127e0
1 changed files with 82 additions and 66 deletions

View File

@ -100,14 +100,13 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
TestUtil.clearAllStaticFieldsForUnitTest();
}
@Override
public void before() throws Exception {
super.before();
myDaoConfig.setAllowMultipleDelete(true);
}
private void checkParamMissing(String paramName) throws IOException, ClientProtocolException {
HttpGet get = new HttpGet(ourServerBase + "/Observation?" + paramName + ":missing=false");
CloseableHttpResponse resp = ourHttpClient.execute(get);
@ -115,6 +114,25 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
assertEquals(200, resp.getStatusLine().getStatusCode());
}
/**
* See #438
*/
@Test
public void testCreateAndUpdateBinary() {
byte[] arr = { 23, 21, 74, 123, -44 };
Binary binary = new Binary();
binary.setContent(arr);
binary.setContentType("dansk");
binary.addUndeclaredExtension(true, "bobobo", new StringDt("hey there"));
IIdType resource = ourClient.create().resource(binary).execute().getId();
Binary fromDB = ourClient.read().resource(Binary.class).withId(resource.toVersionless()).execute();
fromDB.setContentType("test");
ourClient.update().resource(fromDB).execute();
}
/**
* See #441
*/
@ -123,7 +141,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
Medication medication = new Medication();
medication.getCode().addCoding().setSystem("SYSTEM").setCode("04823543");
IIdType medId = myMedicationDao.create(medication).getId().toUnqualifiedVersionless();
MedicationAdministration ma = new MedicationAdministration();
ma.setMedication(new ResourceReferenceDt(medId));
IIdType moId = myMedicationAdministrationDao.create(ma).getId().toUnqualifiedVersionless();
@ -140,8 +158,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
}
@Test
public void testEverythingInstanceWithContentFilter() {
Patient pt1 = new Patient();
@ -155,7 +171,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
Device dev1 = new Device();
dev1.setManufacturer("Some Manufacturer");
IIdType devId1 = myDeviceDao.create(dev1, mySrd).getId().toUnqualifiedVersionless();
Device dev2 = new Device();
dev2.setManufacturer("Some Manufacturer 2");
myDeviceDao.create(dev2, mySrd).getId().toUnqualifiedVersionless();
@ -179,12 +195,12 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
obs3.getCode().addCoding().setCode("CODE3");
obs3.setValue(new StringDt("obsvalue3"));
IIdType obsId3 = myObservationDao.create(obs3, mySrd).getId().toUnqualifiedVersionless();
List<IIdType> actual;
StringAndListParam param;
ourLog.info("Pt1:{} Pt2:{} Obs1:{} Obs2:{} Obs3:{}", new Object[] {ptId1.getIdPart(), ptId2.getIdPart(), obsId1.getIdPart(), obsId2.getIdPart(), obsId3.getIdPart()});
ourLog.info("Pt1:{} Pt2:{} Obs1:{} Obs2:{} Obs3:{}", new Object[] { ptId1.getIdPart(), ptId2.getIdPart(), obsId1.getIdPart(), obsId2.getIdPart(), obsId3.getIdPart() });
param = new StringAndListParam();
param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1")));
@ -196,13 +212,12 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
.withParameter(Parameters.class, Constants.PARAM_CONTENT, new StringDt("obsvalue1"))
.execute();
//@formatter:on
actual = toUnqualifiedVersionlessIds((ca.uhn.fhir.model.dstu2.resource.Bundle)response.getParameter().get(0).getResource());
actual = toUnqualifiedVersionlessIds((ca.uhn.fhir.model.dstu2.resource.Bundle) response.getParameter().get(0).getResource());
assertThat(actual, containsInAnyOrder(ptId1, obsId1, devId1));
}
@Test
public void testBundleCreate() throws Exception {
IGenericClient client = ourClient;
@ -231,7 +246,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
}
}
// private void delete(String theResourceType, String theParamName, String theParamValue) {
// Bundle resources;
// do {
@ -264,7 +278,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setCriteria("Observation?");
IIdType id = ourClient.create().resource(subs).execute().getId().toUnqualifiedVersionless();
//@formatter:off
ca.uhn.fhir.model.dstu2.resource.Bundle resp = ourClient
.search()
@ -439,10 +453,10 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
// .conditionalByUrl("Patient?identifier=http://general-hospital.co.uk/Identifiers|09832345234543876876")
// .execute().getId();
// //@formatter:on
assertEquals(id.getValue(), id2.getValue());
}
@Test
public void testCreateResourceConditional() throws IOException {
String methodName = "testCreateResourceConditional";
@ -512,7 +526,8 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
ourLog.info(responseString);
assertEquals(400, response.getStatusLine().getStatusCode());
OperationOutcome oo = myFhirCtx.newXmlParser().parseResource(OperationOutcome.class, responseString);
assertEquals("Can not create resource with ID \"2\", ID must not be supplied on a create (POST) operation (use an HTTP PUT / update operation if you wish to supply an ID)", oo.getIssue().get(0).getDiagnostics());
assertEquals("Can not create resource with ID \"2\", ID must not be supplied on a create (POST) operation (use an HTTP PUT / update operation if you wish to supply an ID)",
oo.getIssue().get(0).getDiagnostics());
} finally {
response.getEntity().getContent().close();
response.close();
@ -572,12 +587,12 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
String methodName = "testDeleteConditionalMultiple";
myDaoConfig.setAllowMultipleDelete(false);
Patient p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("FAM1");
IIdType id1 = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless();
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("FAM2");
@ -593,15 +608,16 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
//@formatter:on
fail();
} catch (PreconditionFailedException e) {
assertEquals("HTTP 412 Precondition Failed: Failed to DELETE resource with match URL \"Patient?identifier=testDeleteConditionalMultiple\" because this search matched 2 resources", e.getMessage());
assertEquals("HTTP 412 Precondition Failed: Failed to DELETE resource with match URL \"Patient?identifier=testDeleteConditionalMultiple\" because this search matched 2 resources",
e.getMessage());
}
// Not deleted yet..
ourClient.read().resource("Patient").withId(id1).execute();
ourClient.read().resource("Patient").withId(id2).execute();
myDaoConfig.setAllowMultipleDelete(true);
//@formatter:off
ourClient
.delete()
@ -677,7 +693,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
}
}
/**
* Based on email from Rene Spronk
*/
@ -833,7 +849,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
IIdType devId = ourClient.create().resource(dev).execute().getId().toUnqualifiedVersionless();
Location locParent = new Location();
locParent.setName(methodName+"Parent");
locParent.setName(methodName + "Parent");
IIdType locPId = ourClient.create().resource(locParent).execute().getId().toUnqualifiedVersionless();
Location locChild = new Location();
@ -845,7 +861,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
encU.getPatient().setReference(patientId);
encU.addLocation().getLocation().setReference(locCId);
IIdType encUId = ourClient.create().resource(encU).execute().getId().toUnqualifiedVersionless();
Encounter enc = new Encounter();
enc.getPatient().setReference(patientId);
enc.addLocation().getLocation().setReference(locCId);
@ -858,7 +874,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
IIdType obsId = ourClient.create().resource(obs).execute().getId().toUnqualifiedVersionless();
ourLog.info("IDs: EncU:" + encUId.getIdPart() + " Enc:" + encId.getIdPart() + " " + patientId.toUnqualifiedVersionless());
Parameters output = ourClient.operation().onInstance(encId).named("everything").withNoParameters(Parameters.class).execute();
ca.uhn.fhir.model.dstu2.resource.Bundle b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource();
List<IIdType> ids = toUnqualifiedVersionlessIds(b);
@ -897,7 +913,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
IIdType devId = ourClient.create().resource(dev).execute().getId().toUnqualifiedVersionless();
Location locParent = new Location();
locParent.setName(methodName+"Parent");
locParent.setName(methodName + "Parent");
IIdType locPId = ourClient.create().resource(locParent).execute().getId().toUnqualifiedVersionless();
Location locChild = new Location();
@ -908,7 +924,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
Encounter encU = new Encounter();
encU.addIdentifier().setValue(methodName);
IIdType encUId = ourClient.create().resource(encU).execute().getId().toUnqualifiedVersionless();
Encounter enc = new Encounter();
enc.getPatient().setReference(patientId);
enc.addLocation().getLocation().setReference(locCId);
@ -986,18 +1002,18 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
assertThat(ids.size(), greaterThan(10));
}
}
/**
* Test for #226
*/
@Test
public void testEverythingPatientIncludesBackReferences() throws Exception {
String methodName = "testEverythingIncludesBackReferences";
Medication med = new Medication();
med.getCode().setText(methodName);
IIdType medId = myMedicationDao.create(med, mySrd).getId().toUnqualifiedVersionless();
Patient pat = new Patient();
pat.addAddress().addLine(methodName);
IIdType patId = myPatientDao.create(pat, mySrd).getId().toUnqualifiedVersionless();
@ -1006,7 +1022,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
mo.getPatient().setReference(patId);
mo.setMedication(new ResourceReferenceDt(medId));
IIdType moId = myMedicationOrderDao.create(mo, mySrd).getId().toUnqualifiedVersionless();
Parameters output = ourClient.operation().onInstance(patId).named("everything").withNoParameters(Parameters.class).execute();
ca.uhn.fhir.model.dstu2.resource.Bundle b = (ca.uhn.fhir.model.dstu2.resource.Bundle) output.getParameterFirstRep().getResource();
List<IIdType> ids = toUnqualifiedVersionlessIds(b);
@ -1049,8 +1065,6 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
}
@Test
public void testEverythingPatientOperation() throws Exception {
String methodName = "testEverythingOperation";
@ -1095,27 +1109,27 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
ourLog.info(ids.toString());
}
@Test
public void testEverythingPatientType() throws Exception {
String methodName = "testEverythingPatientType";
Organization o1 = new Organization();
o1.setName(methodName+"1");
o1.setName(methodName + "1");
IIdType o1Id = ourClient.create().resource(o1).execute().getId().toUnqualifiedVersionless();
Organization o2 = new Organization();
o2.setName(methodName+"2");
o2.setName(methodName + "2");
IIdType o2Id = ourClient.create().resource(o2).execute().getId().toUnqualifiedVersionless();
Patient p1 = new Patient();
p1.addName().addFamily(methodName+"1");
p1.addName().addFamily(methodName + "1");
p1.getManagingOrganization().setReference(o1Id);
IIdType p1Id = ourClient.create().resource(p1).execute().getId().toUnqualifiedVersionless();
Patient p2 = new Patient();
p2.addName().addFamily(methodName+"2");
p2.addName().addFamily(methodName + "2");
p2.getManagingOrganization().setReference(o2Id);
IIdType p2Id = ourClient.create().resource(p2).execute().getId().toUnqualifiedVersionless();
Condition c1 = new Condition();
c1.getPatient().setReference(p1Id);
IIdType c1Id = ourClient.create().resource(c1).execute().getId().toUnqualifiedVersionless();
@ -1124,7 +1138,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
IIdType c2Id = ourClient.create().resource(c2).execute().getId().toUnqualifiedVersionless();
Condition c3 = new Condition();
c3.addIdentifier().setValue(methodName+"3");
c3.addIdentifier().setValue(methodName + "3");
IIdType c3Id = ourClient.create().resource(c3).execute().getId().toUnqualifiedVersionless();
Parameters output = ourClient.operation().onType(Patient.class).named("everything").withNoParameters(Parameters.class).execute();
@ -1143,18 +1157,18 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
Organization org = new Organization();
org.setName(methodName);
IIdType oId = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless();
long time1 = System.currentTimeMillis();
Thread.sleep(10);
Patient p = new Patient();
p.addName().addFamily(methodName);
p.getManagingOrganization().setReference(oId);
IIdType pId = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless();
long time2 = System.currentTimeMillis();
Thread.sleep(10);
Condition c = new Condition();
c.getCode().setText(methodName);
c.getPatient().setReference(pId);
@ -1162,8 +1176,8 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
Thread.sleep(10);
long time3 = System.currentTimeMillis();
// %3E=> %3C=<
// %3E=> %3C=<
HttpGet get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_lastUpdated=%3E" + new InstantDt(new Date(time1)).getValueAsString());
CloseableHttpResponse response = ourHttpClient.execute(get);
@ -1179,7 +1193,8 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
response.close();
}
get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_lastUpdated=%3E" + new InstantDt(new Date(time2)).getValueAsString() + "&_lastUpdated=%3C" + new InstantDt(new Date(time3)).getValueAsString());
get = new HttpGet(ourServerBase + "/Patient/" + pId.getIdPart() + "/$everything?_lastUpdated=%3E" + new InstantDt(new Date(time2)).getValueAsString() + "&_lastUpdated=%3C"
+ new InstantDt(new Date(time3)).getValueAsString());
response = ourHttpClient.execute(get);
try {
assertEquals(200, response.getStatusLine().getStatusCode());
@ -1220,7 +1235,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
} finally {
response.close();
}
}
@Test
@ -1255,7 +1270,8 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
patient.setId(id);
ourClient.update().resource(patient).execute();
ca.uhn.fhir.model.dstu2.resource.Bundle history = ourClient.history().onInstance(id).andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class).prettyPrint().summaryMode(SummaryEnum.DATA).execute();
ca.uhn.fhir.model.dstu2.resource.Bundle history = ourClient.history().onInstance(id).andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class).prettyPrint().summaryMode(SummaryEnum.DATA)
.execute();
assertEquals(3, history.getEntry().size());
assertEquals(id.withVersion("3"), history.getEntry().get(0).getResource().getId());
assertEquals(1, ((Patient) history.getEntry().get(0).getResource()).getName().size());
@ -1502,7 +1518,8 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
p1.addIdentifier().setValue("testSearchByIdentifierWithoutSystem01");
IdDt p1Id = (IdDt) ourClient.create().resource(p1).execute().getId();
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode(null, "testSearchByIdentifierWithoutSystem01")).encodedJson().prettyPrint().execute();
Bundle actual = ourClient.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode(null, "testSearchByIdentifierWithoutSystem01")).encodedJson().prettyPrint()
.execute();
assertEquals(1, actual.size());
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
@ -1540,7 +1557,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
Organization o1 = new Organization();
o1.setName("testSearchByResourceChainName01");
IdDt o1id = (IdDt) ourClient.create().resource(o1).execute().getId().toUnqualifiedVersionless();
IdDt o1id = (IdDt) ourClient.create().resource(o1).execute().getId().toUnqualifiedVersionless();
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue("testSearchByResourceChain01");
@ -1567,28 +1584,28 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
assertEquals(p1Id.getIdPart(), actual.getEntries().get(0).getResource().getId().getIdPart());
}
@Test
public void testSearchByReferenceIds() {
Organization o1 = new Organization();
o1.setName("testSearchByResourceChainName01");
IdDt o1id = (IdDt) ourClient.create().resource(o1).execute().getId().toUnqualifiedVersionless();
IdDt o1id = (IdDt) ourClient.create().resource(o1).execute().getId().toUnqualifiedVersionless();
Organization o2 = new Organization();
o2.setName("testSearchByResourceChainName02");
IdDt o2id = (IdDt) ourClient.create().resource(o2).execute().getId().toUnqualifiedVersionless();
Patient p1 = new Patient();
p1.addIdentifier().setSystem("urn:system").setValue("testSearchByReferenceIds01");
p1.addName().addFamily("testSearchByReferenceIdsFamily01").addGiven("testSearchByReferenceIdsGiven01");
p1.setManagingOrganization(new ResourceReferenceDt(o1id.toUnqualifiedVersionless()));
IdDt p1Id = (IdDt) ourClient.create().resource(p1).execute().getId();
Patient p2 = new Patient();
p2.addIdentifier().setSystem("urn:system").setValue("testSearchByReferenceIds02");
p2.addName().addFamily("testSearchByReferenceIdsFamily02").addGiven("testSearchByReferenceIdsGiven02");
p2.setManagingOrganization(new ResourceReferenceDt(o2id.toUnqualifiedVersionless()));
IdDt p2Id = (IdDt) ourClient.create().resource(p2).execute().getId();
//@formatter:off
Bundle actual = ourClient.search()
.forResource(Patient.class)
@ -1640,7 +1657,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
patient.addName().addFamily(methodName).addGiven("John");
id2 = (IdDt) ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless();
}
ourLog.info("Before: {}", beforeAny.getValue());
{
//@formatter:off
@ -1664,7 +1681,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
List<IdDt> patients = toIdListUnqualifiedVersionless(found);
assertThat(patients, hasItems(id1a, id1b, id2));
}
{
//@formatter:off
Bundle found = ourClient.search()
@ -1719,7 +1736,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
@Test
public void testSearchReturnsSearchDate() throws Exception {
ourLog.info("Starting testSearchReturnsSearchDate");
Date before = new Date();
Thread.sleep(100);
@ -2422,5 +2439,4 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test {
}
}