WIP restore format header tests - turns out they break

This commit is contained in:
dotasek 2024-11-05 09:08:40 -05:00
parent ac7c7332d3
commit f1d5f714d3
2 changed files with 19 additions and 12 deletions

View File

@ -315,10 +315,9 @@ public class ClientUtils {
configuredHeaders.add(new HTTPHeader("Content-Language", acceptLanguage)); configuredHeaders.add(new HTTPHeader("Content-Language", acceptLanguage));
} }
if (format != null) { Iterable<HTTPHeader> resourceFormatHeaders = getResourceFormatHeaders(format);
configuredHeaders.add(new HTTPHeader("Accept", format)); resourceFormatHeaders.forEach(configuredHeaders::add);
configuredHeaders.add(new HTTPHeader("Content-Type", format + ";charset=" + DEFAULT_CHARSET));
}
Iterable<HTTPHeader> authHeaders = getAuthHeaders(); Iterable<HTTPHeader> authHeaders = getAuthHeaders();
authHeaders.forEach(configuredHeaders::add); authHeaders.forEach(configuredHeaders::add);
@ -328,6 +327,14 @@ public class ClientUtils {
return configuredHeaders; return configuredHeaders;
} }
//FIXME this shouldn't set Content-Type header for GET requests
protected static List<HTTPHeader> getResourceFormatHeaders(String format) {
return Arrays.asList(
new HTTPHeader("Accept", format),
new HTTPHeader("Content-Type", format + ";charset=" + DEFAULT_CHARSET)
);
}
/** /**
* *
* @param request The request to be sent * @param request The request to be sent

View File

@ -62,11 +62,11 @@ public class ClientUtilsTest {
@Test @Test
@DisplayName("Test resource format headers are added correctly.") @DisplayName("Test resource format headers are added correctly.")
void addResourceFormatHeadersGET() { void addResourceFormatHeadersGET() {
/* FIXME restore this after refactor
String testFormat = "yaml"; String testFormat = "yaml";
HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.GET); HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.GET);
Iterable<HTTPHeader> headers = FhirRequestBuilder.getResourceFormatHeaders(request, testFormat); Iterable<HTTPHeader> headers = ClientUtils.getResourceFormatHeaders(testFormat);
Map<String, List<String>> headersMap = HTTPHeaderUtil.getMultimap(headers); Map<String, List<String>> headersMap = HTTPHeaderUtil.getMultimap(headers);
Assertions.assertNotNull(headersMap.get("Accept"), "Accept header null."); Assertions.assertNotNull(headersMap.get("Accept"), "Accept header null.");
@ -75,17 +75,17 @@ public class ClientUtilsTest {
Assertions.assertNull(headersMap.get("Content-Type"), "Content-Type header null."); Assertions.assertNull(headersMap.get("Content-Type"), "Content-Type header null.");
*/
} }
@Test @Test
@DisplayName("Test resource format headers are added correctly (POST).") @DisplayName("Test resource format headers are added correctly (POST).")
void addResourceFormatHeadersPOST() { void addResourceFormatHeadersPOST() {
/*FIXME restore this after refactor
String testFormat = "yaml"; String testFormat = "yaml";
HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.POST); HTTPRequest request = new HTTPRequest().withUrl("http://www.google.com").withMethod(HTTPRequest.HttpMethod.POST);
Iterable<HTTPHeader> headers = FhirRequestBuilder.getResourceFormatHeaders(request, testFormat); Iterable<HTTPHeader> headers = ClientUtils.getResourceFormatHeaders(testFormat);
Map<String, List<String>> headersMap = HTTPHeaderUtil.getMultimap(headers); Map<String, List<String>> headersMap = HTTPHeaderUtil.getMultimap(headers);
Assertions.assertNotNull(headersMap.get("Accept"), "Accept header null."); Assertions.assertNotNull(headersMap.get("Accept"), "Accept header null.");
@ -93,10 +93,10 @@ public class ClientUtilsTest {
"Accept header not populated with expected value " + testFormat + "."); "Accept header not populated with expected value " + testFormat + ".");
Assertions.assertNotNull(headersMap.get("Content-Type"), "Content-Type header null."); Assertions.assertNotNull(headersMap.get("Content-Type"), "Content-Type header null.");
Assertions.assertEquals(testFormat + ";charset=" + FhirRequestBuilder.DEFAULT_CHARSET, headersMap.get("Content-Type").get(0), Assertions.assertEquals(testFormat + ";charset=" + ClientUtils.DEFAULT_CHARSET, headersMap.get("Content-Type").get(0),
"Content-Type header not populated with expected value \"" + testFormat + ";charset=" + FhirRequestBuilder.DEFAULT_CHARSET + "\"."); "Content-Type header not populated with expected value \"" + testFormat + ";charset=" + ClientUtils.DEFAULT_CHARSET + "\".");
*/
} }
@Test @Test