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);
resourceId = entity.getIdDt();
} else {
return create(theResource);
return create(theResource, null, thePerformIndexing);
}
} else {
resourceId = theResource.getId();

View File

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

View File

@ -517,12 +517,12 @@ public class FhirSystemDaoDstu2Test {
p = new Patient();
p.addIdentifier().setSystem("urn:system").setValue(methodName);
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);
Observation o = new 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);
Bundle resp = ourSystemDao.transaction(request);

View File

@ -302,7 +302,7 @@ public class ResourceProviderDstu2Test {
byte[] buf = new byte[10000];
int count;
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")));
}
String resp = b.toString();

View File

@ -1,5 +1,7 @@
package ca.uhn.fhir.jpa.provider;
import static org.junit.Assert.*;
import java.io.InputStream;
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.Patient;
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.server.RestfulServer;
@ -48,6 +52,34 @@ public class SystemProviderTest {
String bundle = IOUtils.toString(bundleRes);
String response = ourClient.transaction().withBundle(bundle).prettyPrint().execute();
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

View File

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