Skip to content

Commit

Permalink
Fix jdk8 issues
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <petern@amazon.com>
  • Loading branch information
peternied committed Nov 21, 2023
1 parent 7408813 commit 97aacef
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

package org.opensearch.security.filter;

import java.util.List;
import java.util.Map;

import org.apache.http.HttpHeaders;
Expand All @@ -23,6 +22,9 @@
import org.opensearch.rest.RestResponse;
import org.opensearch.rest.RestStatus;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

Expand All @@ -46,7 +48,7 @@ public void testSecurityResponseHasSingleContentType() {
public void testSecurityResponseMultipleContentTypesUsesPassed() {
final SecurityResponse response = new SecurityResponse(HttpStatus.SC_OK, null, "foo bar", XContentType.JSON.mediaType());
response.addHeader(HttpHeaders.CONTENT_TYPE, BytesRestResponse.TEXT_CONTENT_TYPE);
assertThat(response.getHeaders().get("Content-Type"), equalTo(List.of(BytesRestResponse.TEXT_CONTENT_TYPE)));
assertThat(response.getHeaders().get("Content-Type"), equalTo(ImmutableList.of(BytesRestResponse.TEXT_CONTENT_TYPE)));
final RestResponse restResponse = response.asRestResponse();
assertThat(restResponse.contentType(), equalTo(XContentType.JSON.mediaType()));
assertThat(restResponse.status(), equalTo(RestStatus.OK));
Expand Down Expand Up @@ -82,9 +84,9 @@ public void testSecurityResponseSetHeaderContentTypeDoesNothing() {
public void testSecurityResponseAddMultipleContentTypeHeaders() {
final SecurityResponse response = new SecurityResponse(HttpStatus.SC_OK, null, "foo bar", XContentType.JSON.mediaType());
response.addHeader(HttpHeaders.CONTENT_TYPE, BytesRestResponse.TEXT_CONTENT_TYPE);
assertThat(response.getHeaders().get("Content-Type"), equalTo(List.of(BytesRestResponse.TEXT_CONTENT_TYPE)));
assertThat(response.getHeaders().get("Content-Type"), equalTo(ImmutableList.of(BytesRestResponse.TEXT_CONTENT_TYPE)));
response.addHeader(HttpHeaders.CONTENT_TYPE, "newContentType");
assertThat(response.getHeaders().get("Content-Type"), equalTo(List.of(BytesRestResponse.TEXT_CONTENT_TYPE, "newContentType")));
assertThat(response.getHeaders().get("Content-Type"), equalTo(ImmutableList.of(BytesRestResponse.TEXT_CONTENT_TYPE, "newContentType")));
final RestResponse restResponse = response.asRestResponse();
assertThat(restResponse.status(), equalTo(RestStatus.OK));
}
Expand All @@ -105,8 +107,8 @@ public void testSecurityResponseFakeContentTypeArgumentPasses() {
*/
@Test
public void testSecurityResponseContentTypeInConstructorHeader() {
final SecurityResponse response = new SecurityResponse(HttpStatus.SC_OK, Map.of("Content-Type", "testType"), "foo bar");
assertThat(response.getHeaders().get("Content-Type"), equalTo(List.of("testType")));
final SecurityResponse response = new SecurityResponse(HttpStatus.SC_OK, ImmutableMap.of("Content-Type", "testType"), "foo bar");
assertThat(response.getHeaders().get("Content-Type"), equalTo(ImmutableList.of("testType")));
final RestResponse restResponse = response.asRestResponse();
assertThat(restResponse.contentType(), equalTo(BytesRestResponse.TEXT_CONTENT_TYPE));
assertThat(restResponse.status(), equalTo(RestStatus.OK));
Expand All @@ -119,11 +121,11 @@ public void testSecurityResponseContentTypeInConstructorHeader() {
public void testSecurityResponseContentTypeInConstructorHeaderConflicts() {
final SecurityResponse response = new SecurityResponse(
HttpStatus.SC_OK,
Map.of("Content-Type", "testType"),
ImmutableMap.of("Content-Type", "testType"),
"foo bar",
XContentType.JSON.mediaType()
);
assertThat(response.getHeaders().get("Content-Type"), equalTo(List.of("testType")));
assertThat(response.getHeaders().get("Content-Type"), equalTo(ImmutableList.of("testType")));
final RestResponse restResponse = response.asRestResponse();
assertThat(restResponse.contentType(), equalTo(XContentType.JSON.mediaType()));
assertThat(restResponse.status(), equalTo(RestStatus.OK));
Expand Down

0 comments on commit 97aacef

Please sign in to comment.