Ad some tests for #837

This commit is contained in:
jamesagnew 2018-01-26 08:39:46 -05:00
parent 5750cfd03c
commit f7f69f6148
1 changed files with 25 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@ -272,8 +273,31 @@ public class ServerMimetypeR4Test {
assertEquals(Constants.CT_FHIR_XML_NEW, status.getFirstHeader("content-type").getValue().replaceAll(";.*", ""));
}
/**
* See #837
*/
@Test
public void testResponseContentTypes() throws IOException {
assertEquals("application/fhir+json", readAndReturnContentType("application/fhir+json"));
assertEquals("application/fhir+xml", readAndReturnContentType(null));
assertEquals("application/json+fhir", readAndReturnContentType("application/json+fhir"));
assertEquals("application/json+fhir", readAndReturnContentType("application/json"));
assertEquals("application/fhir+json", readAndReturnContentType("application/fhir+json,application/json;q=0.9"));
}
private String readAndReturnContentType(String theAccept) throws IOException {
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient");
if (theAccept != null) {
httpGet.addHeader(Constants.HEADER_ACCEPT, theAccept);
}
HttpResponse status = ourClient.execute(httpGet);
String contentType = status.getEntity().getContentType().getValue();
IOUtils.closeQuietly(status.getEntity().getContent());
contentType = contentType.replaceAll(";.*","");
return contentType;
}
@Test
public void testSearchWithFormatJsonSimple() throws Exception {