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));
}
if (format != null) {
configuredHeaders.add(new HTTPHeader("Accept", format));
configuredHeaders.add(new HTTPHeader("Content-Type", format + ";charset=" + DEFAULT_CHARSET));
}
Iterable<HTTPHeader> resourceFormatHeaders = getResourceFormatHeaders(format);
resourceFormatHeaders.forEach(configuredHeaders::add);
Iterable<HTTPHeader> authHeaders = getAuthHeaders();
authHeaders.forEach(configuredHeaders::add);
@ -328,6 +327,14 @@ public class ClientUtils {
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

View File

@ -62,11 +62,11 @@ public class ClientUtilsTest {
@Test
@DisplayName("Test resource format headers are added correctly.")
void addResourceFormatHeadersGET() {
/* FIXME restore this after refactor
String testFormat = "yaml";
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);
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.");
*/
}
@Test
@DisplayName("Test resource format headers are added correctly (POST).")
void addResourceFormatHeadersPOST() {
/*FIXME restore this after refactor
String testFormat = "yaml";
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);
Assertions.assertNotNull(headersMap.get("Accept"), "Accept header null.");
@ -93,10 +93,10 @@ public class ClientUtilsTest {
"Accept header not populated with expected value " + testFormat + ".");
Assertions.assertNotNull(headersMap.get("Content-Type"), "Content-Type header null.");
Assertions.assertEquals(testFormat + ";charset=" + FhirRequestBuilder.DEFAULT_CHARSET, headersMap.get("Content-Type").get(0),
"Content-Type header not populated with expected value \"" + testFormat + ";charset=" + FhirRequestBuilder.DEFAULT_CHARSET + "\".");
Assertions.assertEquals(testFormat + ";charset=" + ClientUtils.DEFAULT_CHARSET, headersMap.get("Content-Type").get(0),
"Content-Type header not populated with expected value \"" + testFormat + ";charset=" + ClientUtils.DEFAULT_CHARSET + "\".");
*/
}
@Test