Fix unit tests

This commit is contained in:
James Agnew 2015-05-07 11:22:05 -04:00
parent 5a7eb6f25e
commit 9d744f2a44
6 changed files with 43 additions and 11 deletions

View File

@ -2006,7 +2006,7 @@ public abstract class BaseFhirResourceDao<T extends IResource> extends BaseFhirD
entity = myEntityManager.find(ResourceTable.class, pid); entity = myEntityManager.find(ResourceTable.class, pid);
resourceId = entity.getIdDt(); resourceId = entity.getIdDt();
} else { } else {
return create(theResource); return create(theResource, null, thePerformIndexing);
} }
} else { } else {
resourceId = theResource.getId(); resourceId = theResource.getId();

View File

@ -200,9 +200,9 @@ public class FhirSystemDaoDstu2 extends BaseFhirSystemDao<Bundle> {
String url = extractTransactionUrlOrThrowException(nextEntry, verb); String url = extractTransactionUrlOrThrowException(nextEntry, verb);
UrlParts parts = parseUrl(verb.getCode(), url); UrlParts parts = parseUrl(verb.getCode(), url);
if (res.getId().hasIdPart() && isBlank(parts.getResourceId())) { // if (res.getId().hasIdPart() && isBlank(parts.getResourceId())) {
parts.setResourceId(res.getId().getIdPart()); // parts.setResourceId(res.getId().getIdPart());
} // }
if (isNotBlank(parts.getResourceId())) { if (isNotBlank(parts.getResourceId())) {
res.setId(new IdDt(parts.getResourceType(), parts.getResourceId())); res.setId(new IdDt(parts.getResourceType(), parts.getResourceId()));
outcome = resourceDao.update(res, null, false); outcome = resourceDao.update(res, null, false);

View File

@ -517,12 +517,12 @@ public class FhirSystemDaoDstu2Test {
p = new Patient(); p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addIdentifier().setSystem("urn:system").setValue(methodName);
p.addName().addFamily("Hello"); p.addName().addFamily("Hello");
p.setId("urn:"+methodName); p.setId(methodName);
request.addEntry().setResource(p).getTransaction().setMethod(HTTPVerbEnum.PUT).setUrl("Patient?identifier=urn%3Asystem%7C" + methodName); request.addEntry().setResource(p).getTransaction().setMethod(HTTPVerbEnum.PUT).setUrl("Patient?identifier=urn%3Asystem%7C" + methodName);
Observation o = new Observation(); Observation o = new Observation();
o.getCode().setText("Some Observation"); o.getCode().setText("Some Observation");
o.getSubject().setReference("Patient/urn:"+methodName); o.getSubject().setReference("Patient/"+methodName);
request.addEntry().setResource(o).getTransaction().setMethod(HTTPVerbEnum.POST); request.addEntry().setResource(o).getTransaction().setMethod(HTTPVerbEnum.POST);
Bundle resp = ourSystemDao.transaction(request); Bundle resp = ourSystemDao.transaction(request);

View File

@ -302,7 +302,7 @@ public class ResourceProviderDstu2Test {
byte[] buf = new byte[10000]; byte[] buf = new byte[10000];
int count; int count;
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
while ((count = inputStream.read(buf)) > 0) { while ((count = inputStream.read(buf)) != -1) {
b.append(new String(buf, 0, count, Charset.forName("UTF-8"))); b.append(new String(buf, 0, count, Charset.forName("UTF-8")));
} }
String resp = b.toString(); String resp = b.toString();

View File

@ -1,5 +1,7 @@
package ca.uhn.fhir.jpa.provider; package ca.uhn.fhir.jpa.provider;
import static org.junit.Assert.*;
import java.io.InputStream; import java.io.InputStream;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -21,6 +23,8 @@ import ca.uhn.fhir.model.dstu.resource.Observation;
import ca.uhn.fhir.model.dstu.resource.Organization; import ca.uhn.fhir.model.dstu.resource.Organization;
import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu.resource.Questionnaire; import ca.uhn.fhir.model.dstu.resource.Questionnaire;
import ca.uhn.fhir.model.dstu2.resource.Bundle;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.client.IGenericClient;
import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.RestfulServer;
@ -48,6 +52,34 @@ public class SystemProviderTest {
String bundle = IOUtils.toString(bundleRes); String bundle = IOUtils.toString(bundleRes);
String response = ourClient.transaction().withBundle(bundle).prettyPrint().execute(); String response = ourClient.transaction().withBundle(bundle).prettyPrint().execute();
ourLog.info(response); ourLog.info(response);
Bundle resp = ourCtx.newXmlParser().parseResource(Bundle.class, response);
IdDt id1_1 = new IdDt(resp.getEntry().get(1).getTransactionResponse().getLocation());
assertEquals("Provenance", id1_1.getResourceType());
IdDt id1_2 = new IdDt(resp.getEntry().get(2).getTransactionResponse().getLocation());
IdDt id1_3 = new IdDt(resp.getEntry().get(3).getTransactionResponse().getLocation());
IdDt id1_4 = new IdDt(resp.getEntry().get(4).getTransactionResponse().getLocation());
/*
* Same bundle!
*/
bundleRes = SystemProviderTest.class.getResourceAsStream("/transaction_link_patient_eve_temp.xml");
bundle = IOUtils.toString(bundleRes);
response = ourClient.transaction().withBundle(bundle).prettyPrint().execute();
ourLog.info(response);
resp = ourCtx.newXmlParser().parseResource(Bundle.class, response);
IdDt id2_1 = new IdDt(resp.getEntry().get(1).getTransactionResponse().getLocation());
IdDt id2_2 = new IdDt(resp.getEntry().get(2).getTransactionResponse().getLocation());
IdDt id2_3 = new IdDt(resp.getEntry().get(3).getTransactionResponse().getLocation());
IdDt id2_4 = new IdDt(resp.getEntry().get(4).getTransactionResponse().getLocation());
assertNotEquals(id1_1.toVersionless(), id2_1.toVersionless());
assertEquals("Provenance", id2_1.getResourceType());
assertEquals(id1_2.toVersionless(), id2_2.toVersionless());
assertEquals(id1_3.toVersionless(), id2_3.toVersionless());
assertEquals(id1_4.toVersionless(), id2_4.toVersionless());
} }
@AfterClass @AfterClass

View File

@ -11,7 +11,7 @@
</text> </text>
<target> <target>
<!-- unversioned, part of a transaction --> <!-- unversioned, part of a transaction -->
<reference value="Patient/b555-44-4444"/> <reference value="Patient/555-44-4444"/>
</target> </target>
<recorded value="2015-05-07T13:06:03+01:00"/> <recorded value="2015-05-07T13:06:03+01:00"/>
<reason> <reason>
@ -27,7 +27,7 @@
<code value="patient"/> <code value="patient"/>
</type> </type>
<referenceReference> <referenceReference>
<reference value="Patient/b555-44-4444"/> <reference value="Patient/555-44-4444"/>
<display value="Patient Everywoman"/> <display value="Patient Everywoman"/>
</referenceReference> </referenceReference>
<display value="Eve Everywoman"/> <display value="Eve Everywoman"/>
@ -41,7 +41,7 @@
<entry> <entry>
<resource> <resource>
<Patient> <Patient>
<id value="b555-44-4444"/> <id value="555-44-4444"/>
<extension url="http://ihe.net/ITI-78/Profile/pdqm#mothersMaidenName"> <extension url="http://ihe.net/ITI-78/Profile/pdqm#mothersMaidenName">
<valueHumanName> <valueHumanName>
<family value="Jones"/> <family value="Jones"/>
@ -123,7 +123,7 @@
</managingOrganization> </managingOrganization>
<link> <link>
<other> <other>
<reference value="Patient/b555-44-4444"/> <reference value="Patient/555-44-4444"/>
</other> </other>
<type value="replace"/> <type value="replace"/>
</link> </link>