Add test for #801

This commit is contained in:
James Agnew 2017-12-07 18:15:49 -06:00
parent e838b0e32d
commit 7ce70a792d
2 changed files with 218 additions and 84 deletions

View File

@ -587,90 +587,6 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
}
@Test
public void testTransactionWithIfMatch() {
Patient p = new Patient();
p.setId("P1");
p.setActive(true);
myPatientDao.update(p);
p.setActive(false);
Bundle b = new Bundle();
b.setType(BundleType.TRANSACTION);
b.addEntry()
.setFullUrl("Patient/P1")
.setResource(p)
.getRequest()
.setMethod(HTTPVerb.PUT)
.setUrl("Patient/P1")
.setIfMatch("2");
try {
mySystemDao.transaction(mySrd, b);
} catch (ResourceVersionConflictException e) {
assertEquals("Trying to update Patient/P1/_history/2 but this is not the current version", e.getMessage());
}
b = new Bundle();
b.setType(BundleType.TRANSACTION);
b.addEntry()
.setFullUrl("Patient/P1")
.setResource(p)
.getRequest()
.setMethod(HTTPVerb.PUT)
.setUrl("Patient/P1")
.setIfMatch("1");
Bundle resp = mySystemDao.transaction(mySrd, b);
assertEquals("Patient/P1/_history/2", new IdType(resp.getEntry().get(0).getResponse().getLocation()).toUnqualified().getValue());
}
@Test
public void testTransactionWithIfNoneExist() {
Patient p = new Patient();
p.setId("P1");
p.setActive(true);
myPatientDao.update(p);
p = new Patient();
p.setActive(true);
p.addName().setFamily("AAA");
Bundle b = new Bundle();
b.setType(BundleType.TRANSACTION);
b.addEntry()
.setFullUrl("Patient")
.setResource(p)
.getRequest()
.setMethod(HTTPVerb.POST)
.setUrl("Patient/P1")
.setIfNoneExist("Patient?active=true");
Bundle resp = mySystemDao.transaction(mySrd, b);
assertEquals("Patient/P1/_history/1", new IdType(resp.getEntry().get(0).getResponse().getLocation()).toUnqualified().getValue());
p = new Patient();
p.setActive(true);
p.addName().setFamily("AAA");
b = new Bundle();
b.setType(BundleType.TRANSACTION);
b.addEntry()
.setFullUrl("Patient")
.setResource(p)
.getRequest()
.setMethod(HTTPVerb.POST)
.setUrl("Patient/P1")
.setIfNoneExist("Patient?active=false");
resp = mySystemDao.transaction(mySrd, b);
assertThat( new IdType(resp.getEntry().get(0).getResponse().getLocation()).toUnqualified().getValue(), matchesPattern("Patient/[0-9]+/_history/1"));
}
@Test
public void testTransaction1() throws IOException {
String inputBundleString = loadClasspath("/david-bundle-error.json");
@ -2271,6 +2187,90 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
}
@Test
public void testTransactionWithIfMatch() {
Patient p = new Patient();
p.setId("P1");
p.setActive(true);
myPatientDao.update(p);
p.setActive(false);
Bundle b = new Bundle();
b.setType(BundleType.TRANSACTION);
b.addEntry()
.setFullUrl("Patient/P1")
.setResource(p)
.getRequest()
.setMethod(HTTPVerb.PUT)
.setUrl("Patient/P1")
.setIfMatch("2");
try {
mySystemDao.transaction(mySrd, b);
} catch (ResourceVersionConflictException e) {
assertEquals("Trying to update Patient/P1/_history/2 but this is not the current version", e.getMessage());
}
b = new Bundle();
b.setType(BundleType.TRANSACTION);
b.addEntry()
.setFullUrl("Patient/P1")
.setResource(p)
.getRequest()
.setMethod(HTTPVerb.PUT)
.setUrl("Patient/P1")
.setIfMatch("1");
Bundle resp = mySystemDao.transaction(mySrd, b);
assertEquals("Patient/P1/_history/2", new IdType(resp.getEntry().get(0).getResponse().getLocation()).toUnqualified().getValue());
}
@Test
public void testTransactionWithIfNoneExist() {
Patient p = new Patient();
p.setId("P1");
p.setActive(true);
myPatientDao.update(p);
p = new Patient();
p.setActive(true);
p.addName().setFamily("AAA");
Bundle b = new Bundle();
b.setType(BundleType.TRANSACTION);
b.addEntry()
.setFullUrl("Patient")
.setResource(p)
.getRequest()
.setMethod(HTTPVerb.POST)
.setUrl("Patient/P1")
.setIfNoneExist("Patient?active=true");
Bundle resp = mySystemDao.transaction(mySrd, b);
assertEquals("Patient/P1/_history/1", new IdType(resp.getEntry().get(0).getResponse().getLocation()).toUnqualified().getValue());
p = new Patient();
p.setActive(true);
p.addName().setFamily("AAA");
b = new Bundle();
b.setType(BundleType.TRANSACTION);
b.addEntry()
.setFullUrl("Patient")
.setResource(p)
.getRequest()
.setMethod(HTTPVerb.POST)
.setUrl("Patient/P1")
.setIfNoneExist("Patient?active=false");
resp = mySystemDao.transaction(mySrd, b);
assertThat(new IdType(resp.getEntry().get(0).getResponse().getLocation()).toUnqualified().getValue(), matchesPattern("Patient/[0-9]+/_history/1"));
}
@Test
public void testTransactionWithInlineMatchUrl() throws Exception {
myDaoConfig.setAllowInlineMatchUrlReferences(true);
@ -2343,6 +2343,22 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
}
/**
* See #801
*/
@Test
public void testTransactionWithMatchUrlToReferenceInSameBundle() throws IOException {
String input = IOUtils.toString(getClass().getResourceAsStream("/r4/bug801.json"), StandardCharsets.UTF_8);
Bundle bundle = myFhirCtx.newJsonParser().parseResource(Bundle.class, input);
try {
mySystemDao.transaction(mySrd, bundle);
fail();
} catch (ResourceNotFoundException e) {
// expected
}
}
@Test
public void testTransactionWithMultiBundle() throws IOException {
String inputBundleString = loadClasspath("/batch-error.xml");

View File

@ -0,0 +1,118 @@
{
"resourceType": "Bundle",
"type": "transaction",
"entry": [
{
"resource": {
"resourceType": "Observation",
"status": "final",
"category": [
{
"coding": [
{
"system": "http://hl7.org/fhir/observation-category",
"code": "vital-signs",
"display": "Vital Signs",
"userSelected": false
}
],
"text": "Vital Signs"
}
],
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "55284-4",
"display": "Blood pressure systolic and diastolic",
"userSelected": false
}
],
"text": "Blood pressure systolic and diastolic"
},
"subject": {
"reference": "Patient?identifier=http://ehr.example.com|Patient/A9"
},
"performer": [{
"reference": "Patient?identifier=http://ehr.example.com|Patient/A9"
}],
"effectiveDateTime": "2009-09-09T00:00:00",
"component": [
{
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "8480-6",
"display": "Systolic blood pressure",
"userSelected": false
}
],
"text": "Systolic blood pressure"
},
"valueQuantity": {
"value": 109,
"unit": "mmHg",
"system": "http://unitsofmeasure.org",
"code": "mm[Hg]"
}
},
{
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "8462-4",
"display": "Diastolic blood pressure",
"userSelected": false
}
],
"text": "Diastolic blood pressure"
},
"valueQuantity": {
"value": 66,
"unit": "mmHg",
"system": "http://unitsofmeasure.org",
"code": "mm[Hg]"
}
}
],
"comment": "BUNDLE testing."
},
"request": {
"method": "POST",
"url": "Observation"
}
},
{
"resource": {
"resourceType": "Patient",
"identifier": [
{
"use": "usual",
"system": "http://ehr.example.com",
"value": "Patient/A9"
}
],
"active": true,
"name": [
{
"use": "official",
"family": "Chalmers",
"given": [
"Peter",
"James"
]
}
],
"gender": "male",
"birthDate": "1974-12-25"
},
"request": {
"method": "POST",
"url": "Patient",
"ifNoneExist": "identifier=http://ehr.example.com|Patient/A9"
}
}
]
}