From 9cf2b18d5d4a07f87438808213bbac5fb72910ed Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 17 Jun 2015 16:17:16 -0400 Subject: [PATCH] Fix broken unit test --- .../uhn/fhir/rest/server/RestfulServerUtils.java | 2 +- .../fhir/rest/server/RestfulServerUtilsTest.java | 12 ++++++++++++ .../uhn/fhir/rest/server/ServerFeaturesTest.java | 14 ++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java index 2eeaa007567..c8bb6e18c36 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java @@ -224,7 +224,7 @@ public class RestfulServerUtils { } } - if (q > bestQ) { + if (q > bestQ && encoding != null) { retVal = encoding; bestQ = q; } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java index ea449f6fa1b..c98994426a9 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java @@ -16,4 +16,16 @@ public class RestfulServerUtilsTest { assertEquals("application/json+fhir", m.group(1)); } + @Test + public void testAcceptPattern2() { + Matcher m = RestfulServerUtils.ACCEPT_HEADER_PATTERN.matcher("text/plain, " + Constants.CT_FHIR_JSON); + assertTrue(m.find()); + assertEquals("text/plain,", m.group(0)); + assertEquals("text/plain", m.group(1)); + + assertTrue(m.find()); + assertEquals(" application/json+fhir", m.group(0)); + assertEquals("application/json+fhir", m.group(1)); + } + } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java index 90754d15272..042b4e2f08c 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java @@ -2,6 +2,7 @@ package ca.uhn.fhir.rest.server; import static org.junit.Assert.*; +import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -10,6 +11,7 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; @@ -145,11 +147,15 @@ public class ServerFeaturesTest { IOUtils.closeQuietly(status.getEntity().getContent()); assertThat(responseContent, StringContains.containsString("