Add some tests
This commit is contained in:
parent
11584beb7d
commit
5310d684df
|
@ -601,6 +601,7 @@ public class JsonParserTest {
|
|||
public void testEncodeBundleCategory() {
|
||||
|
||||
Bundle b = new Bundle();
|
||||
|
||||
BundleEntry e = b.addEntry();
|
||||
e.setResource(new Patient());
|
||||
b.addCategory("scheme", "term", "label");
|
||||
|
@ -609,6 +610,7 @@ public class JsonParserTest {
|
|||
ourLog.info(val);
|
||||
|
||||
assertThat(val, StringContains.containsString("\"category\":[{\"term\":\"term\",\"label\":\"label\",\"scheme\":\"scheme\"}]"));
|
||||
assertThat(val, not(containsString("text")));
|
||||
|
||||
b = new FhirContext().newJsonParser().parseBundle(val);
|
||||
assertEquals(1, b.getEntries().size());
|
||||
|
@ -620,6 +622,7 @@ public class JsonParserTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBundleEntryCategory() {
|
||||
|
||||
|
|
|
@ -13,12 +13,14 @@ import net.sf.json.JsonConfig;
|
|||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.hamcrest.core.StringContains;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.BundleEntry;
|
||||
import ca.uhn.fhir.model.api.ExtensionDt;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
||||
|
@ -28,6 +30,7 @@ import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
|||
import ca.uhn.fhir.model.dstu2.composite.CodingDt;
|
||||
import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Binary;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry;
|
||||
import ca.uhn.fhir.model.dstu2.resource.DiagnosticReport;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Medication;
|
||||
import ca.uhn.fhir.model.dstu2.resource.MedicationPrescription;
|
||||
|
@ -80,6 +83,42 @@ public class JsonParserDstu2Test {
|
|||
ourLog.info(message);
|
||||
Assert.assertThat(message, containsString("contained"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBundleOldBundleNoText() {
|
||||
|
||||
Bundle b = new Bundle();
|
||||
|
||||
BundleEntry e = b.addEntry();
|
||||
e.setResource(new Patient());
|
||||
b.addCategory("scheme", "term", "label");
|
||||
|
||||
String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeBundleToString(b);
|
||||
ourLog.info(val);
|
||||
|
||||
assertThat(val, not(containsString("text")));
|
||||
|
||||
b = new FhirContext().newJsonParser().parseBundle(val);
|
||||
assertEquals(1, b.getEntries().size());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBundleNewBundleNoText() {
|
||||
|
||||
ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
||||
b.getText().getDiv();
|
||||
|
||||
Entry e = b.addEntry();
|
||||
e.setResource(new Patient());
|
||||
|
||||
String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeResourceToString(b);
|
||||
ourLog.info(val);
|
||||
|
||||
assertThat(val, not(containsString("text")));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* See #144 and #146
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package ca.uhn.fhir.rest.server;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -44,6 +46,8 @@ public class SearchDstu2Test {
|
|||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertThat(responseContent, not(containsString("text")));
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Patient patient = (Patient) ourCtx.newXmlParser().parseResource(Bundle.class, responseContent).getEntry().get(0).getResource();
|
||||
|
@ -52,6 +56,22 @@ public class SearchDstu2Test {
|
|||
assertNull(status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeConvertsReferencesToRelativeJson() throws Exception {
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithRef&_format=json");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertThat(responseContent, not(containsString("text")));
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Patient patient = (Patient) ourCtx.newJsonParser().parseResource(Bundle.class, responseContent).getEntry().get(0).getResource();
|
||||
String ref = patient.getManagingOrganization().getReference().getValue();
|
||||
assertEquals("Organization/555", ref);
|
||||
assertNull(status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
|
@ -67,7 +87,6 @@ public class SearchDstu2Test {
|
|||
|
||||
ServletHandler proxyHandler = new ServletHandler();
|
||||
RestfulServer servlet = new RestfulServer();
|
||||
servlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
|
||||
|
||||
servlet.setResourceProviders(patientProvider);
|
||||
ServletHolder servletHolder = new ServletHolder(servlet);
|
||||
|
|
Loading…
Reference in New Issue