Add some tests

This commit is contained in:
James Agnew 2018-02-11 16:38:33 -05:00
parent 7046d2fe94
commit 388f51a823
4 changed files with 371 additions and 91 deletions

View File

@ -1801,91 +1801,6 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
assertNull(nextEntry.getResource());
}
@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 testTransactionSearchWithCount() {
String methodName = "testTransactionSearchWithCount";
@ -2198,6 +2113,162 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
}
@Test
public void testTransactionWithCircularReferences() {
Bundle request = new Bundle();
request.setType(BundleType.TRANSACTION);
Encounter enc = new Encounter();
enc.addIdentifier().setSystem("A").setValue("1");
enc.setId(IdType.newRandomUuid());
Condition cond = new Condition();
cond.addIdentifier().setSystem("A").setValue("2");
cond.setId(IdType.newRandomUuid());
enc.addDiagnosis().getCondition().setReference(cond.getId());
cond.getContext().setReference(enc.getId());
request
.addEntry()
.setFullUrl(enc.getId())
.setResource(enc)
.getRequest()
.setMethod(HTTPVerb.PUT)
.setUrl("Encounter?identifier=A|1");
request
.addEntry()
.setFullUrl(cond.getId())
.setResource(cond)
.getRequest()
.setMethod(HTTPVerb.PUT)
.setUrl("Condition?identifier=A|2");
Bundle resp = mySystemDao.transaction(mySrd, request);
assertEquals(2, resp.getEntry().size());
BundleEntryComponent respEntry = resp.getEntry().get(0);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
respEntry = resp.getEntry().get(1);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
}
@Test
public void testTransactionWithCircularReferences2() throws IOException {
Bundle request = loadResourceFromClasspath(Bundle.class, "/dstu3_transaction.xml");
Bundle resp = mySystemDao.transaction(mySrd, request);
assertEquals(3, resp.getEntry().size());
BundleEntryComponent respEntry = resp.getEntry().get(0);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
respEntry = resp.getEntry().get(1);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
}
@Test
public void testTransactionWithCircularReferences3() throws IOException {
Bundle request = loadResourceFromClasspath(Bundle.class, "/dstu3_transaction2.xml");
Bundle resp = mySystemDao.transaction(mySrd, request);
assertEquals(3, resp.getEntry().size());
BundleEntryComponent respEntry = resp.getEntry().get(0);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
respEntry = resp.getEntry().get(1);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
}
@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);
@ -2355,7 +2426,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
/*
* Make sure we are able to handle placeholder IDs in match URLs, e.g.
*
*
* "request": {
* "method": "PUT",
* "url": "Observation?subject=urn:uuid:8dba64a8-2aca-48fe-8b4e-8c7bf2ab695a&code=http%3A%2F%2Floinc.org|29463-7&date=2011-09-03T11:13:00-04:00"
@ -2385,7 +2456,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
/*
* Make sure we are able to handle placeholder IDs in match URLs, e.g.
*
*
* "request": {
* "method": "PUT",
* "url": "Observation?subject=urn:uuid:8dba64a8-2aca-48fe-8b4e-8c7bf2ab695a&code=http%3A%2F%2Floinc.org|29463-7&date=2011-09-03T11:13:00-04:00"
@ -2501,9 +2572,9 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
IdType medId1 = new IdType(outcome.getEntry().get(0).getResponse().getLocation());
IdType medOrderId1 = new IdType(outcome.getEntry().get(1).getResponse().getLocation());
/*
* Again!
*/
/*
* Again!
*/
bundle = new Bundle();
bundle.setType(BundleType.TRANSACTION);

View File

@ -11,7 +11,6 @@ import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.TokenOrListParam;
import ca.uhn.fhir.rest.server.exceptions.*;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails;
import ca.uhn.fhir.util.TestUtil;
@ -730,6 +729,78 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
}
@Test
public void testTransactionWithCircularReferences() {
Bundle request = new Bundle();
request.setType(BundleType.TRANSACTION);
Encounter enc = new Encounter();
enc.addIdentifier().setSystem("A").setValue("1");
enc.setId(IdType.newRandomUuid());
Condition cond = new Condition();
cond.addIdentifier().setSystem("A").setValue("2");
cond.setId(IdType.newRandomUuid());
enc.addDiagnosis().getCondition().setReference(cond.getId());
cond.getContext().setReference(enc.getId());
request
.addEntry()
.setFullUrl(enc.getId())
.setResource(enc)
.getRequest()
.setMethod(HTTPVerb.PUT)
.setUrl("Encounter?identifier=A|1");
request
.addEntry()
.setFullUrl(cond.getId())
.setResource(cond)
.getRequest()
.setMethod(HTTPVerb.PUT)
.setUrl("Condition?identifier=A|2");
Bundle resp = mySystemDao.transaction(mySrd, request);
assertEquals(2, resp.getEntry().size());
BundleEntryComponent respEntry = resp.getEntry().get(0);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
respEntry = resp.getEntry().get(1);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
}
@Test
public void testTransactionWithCircularReferences2() throws IOException {
Bundle request = loadResourceFromClasspath(Bundle.class, "/dstu3_transaction.xml");
Bundle resp = mySystemDao.transaction(mySrd, request);
assertEquals(3, resp.getEntry().size());
BundleEntryComponent respEntry = resp.getEntry().get(0);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
respEntry = resp.getEntry().get(1);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
}
@Test
public void testTransactionWithCircularReferences3() throws IOException {
Bundle request = loadResourceFromClasspath(Bundle.class, "/dstu3_transaction2.xml");
Bundle resp = mySystemDao.transaction(mySrd, request);
assertEquals(3, resp.getEntry().size());
BundleEntryComponent respEntry = resp.getEntry().get(0);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
respEntry = resp.getEntry().get(1);
assertEquals(Constants.STATUS_HTTP_201_CREATED + " Created", respEntry.getResponse().getStatus());
}
@Test
public void testTransactionCreateInlineMatchUrlWithOneMatchLastUpdated() {
Bundle request = new Bundle();

View File

@ -0,0 +1,65 @@
<Bundle xmlns="http://hl7.org/fhir">
<type value="transaction"/>
<entry>
<fullUrl value="urn:uuid:f307ffe9-359d-49fe-9ebc-b56d853b85c6"/>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<identifier>
<system value="urn:hssc:musc:patientid"/>
<value value="005674000"/>
</identifier>
</Patient>
</resource>
<request>
<method value="POST"/>
<url value="/Patient"/>
<ifNoneExist value="Patient?identifier=urn%3Ahssc%3Amusc%3Apatientid|005674000"/>
</request>
</entry>
<entry>
<fullUrl value="Encounter/ABC"/>
<resource>
<Encounter xmlns="http://hl7.org/fhir">
<id value="ABC"/>
<identifier>
<system value="urn:hssc:musc:encounterid"/>
<value value="1064100000"/>
</identifier>
<status value="in-progress"/>
<diagnosis>
<condition>
<reference value="urn:uuid:2c3d22b0-6c62-4f1a-b12a-a623546dd4d8"/>
</condition>
</diagnosis>
</Encounter>
</resource>
<request>
<method value="PUT"/>
<url value="Encounter/ABC"/>
</request>
</entry>
<entry>
<fullUrl value="urn:uuid:2c3d22b0-6c62-4f1a-b12a-a623546dd4d8"/>
<resource>
<Condition xmlns="http://hl7.org/fhir">
<identifier>
<system value="urn:hssc:musc:conditionid"/>
<value value="1064115000.1.5"/>
</identifier>
<code>
<coding>
<system value="http://www.icd10data.com/icd10pcs"/>
<code value="Z96.653"/>
<display value="Presence of artificial knee joint, bilateral"/>
</coding>
</code>
<onsetDateTime value="2016-05-23T17:56:33-04:00"/>
<abatementDateTime value="2017-05-23T17:56:33-04:00"/>
</Condition>
</resource>
<request>
<method value="PUT"/>
<url value="/Condition?identifier=urn%3Ahssc%3Amusc%3Aconditionid|1064115000.1.5"/>
</request>
</entry>
</Bundle>

View File

@ -0,0 +1,73 @@
<Bundle xmlns="http://hl7.org/fhir">
<type value="transaction"/>
<entry>
<fullUrl value="urn:uuid:65b011a6-3ae6-4798-a1f9-9e9de51b02fd"/>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<identifier>
<system value="urn:HSC:MSC:patientid"/>
<value value="005674363"/>
</identifier>
</Patient>
</resource>
<request>
<method value="POST"/>
<url value="/Patient"/>
<ifNoneExist value="Patient?identifier=urn%3AHSC%3AMSC%3Apatientid|005674363"/>
</request>
</entry>
<entry>
<fullUrl value="urn:uuid:7aae0024-9cff-441b-9a21-6826cadaf75c"/>
<resource>
<Encounter xmlns="http://hl7.org/fhir">
<identifier>
<system value="urn:HSC:MSC:encounterid"/>
<value value="1064115858"/>
</identifier>
<subject>
<reference value="urn:uuid:65b011a6-3ae6-4798-a1f9-9e9de51b02fd"/>
</subject>
<diagnosis>
<condition>
<reference value="urn:uuid:e2f72935-58a2-4a11-a600-0bcae7ea9fb5"/>
</condition>
</diagnosis>
</Encounter>
</resource>
<request>
<method value="POST"/>
<url value="/Encounter"/>
<ifNoneExist value="Encounter?identifier=urn%3AHSC%3AMSC%3Aencounterid|1064115858"/>
</request>
</entry>
<entry>
<fullUrl value="urn:uuid:e2f72935-58a2-4a11-a600-0bcae7ea9fb5"/>
<resource>
<Condition xmlns="http://hl7.org/fhir">
<identifier>
<system value="urn:HSC:MSC:conditionid"/>
<value value="1064115858.1.5"/>
</identifier>
<code>
<coding>
<system value="http://www.icd10data.com/icd10pcs"/>
<code value="Z96.653"/>
<display value="Presence of artificial knee joint, bilateral"/>
</coding>
</code>
<subject>
<reference value="urn:uuid:65b011a6-3ae6-4798-a1f9-9e9de51b02fd"/>
</subject>
<context>
<reference value="urn:uuid:7aae0024-9cff-441b-9a21-6826cadaf75c"/>
</context>
<onsetDateTime value="2016-05-23T17:56:33-04:00"/>
<abatementDateTime value="2016-05-23T17:56:33-04:00"/>
</Condition>
</resource>
<request>
<method value="PUT"/>
<url value="/Condition?identifier=urn%3AHSC%3AMSC%3Aconditionid|1064115858.1.5"/>
</request>
</entry>
</Bundle>