aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-distribution-client/src/test/java/org/onap
diff options
context:
space:
mode:
authorMarek Szwałkiewicz <marek.szwalkiewicz@external.t-mobile.pl>2023-03-02 12:43:50 +0100
committerMarek Szwałkiewicz <marek.szwalkiewicz@external.t-mobile.pl>2023-03-03 12:42:35 +0100
commit508489a4ea7000b9e24cdb0ea48f5357010d783e (patch)
treed0ae300483b4fb943194ce8f0535a19eb9c1b8f5 /sdc-distribution-client/src/test/java/org/onap
parent928348966d924f7cf41077f98ab6665ea6aec512 (diff)
Enable case insensitive matching of http headers
This change creates simple case insensitive map implementation that is used in HttpSdcResponse class to store the response headers. Generally HTTP headers are supposed to be case insensitive and sometimes get transformed (in our case - by istio sidecar) to lower case. With this change lower case will still be matched and the original behaviour will not break. Issue-ID: SDC-4233 Signed-off-by: Marek Szwałkiewicz <marek.szwalkiewicz@external.t-mobile.pl> Change-Id: I1cb9d9e75ff656ccb12c690c553bccc672332a12
Diffstat (limited to 'sdc-distribution-client/src/test/java/org/onap')
-rw-r--r--sdc-distribution-client/src/test/java/org/onap/sdc/http/HttpAsdcClientTest.java3
-rw-r--r--sdc-distribution-client/src/test/java/org/onap/sdc/http/HttpRequestFactoryTest.java5
-rw-r--r--sdc-distribution-client/src/test/java/org/onap/sdc/http/SdcConnectorClientTest.java14
3 files changed, 15 insertions, 7 deletions
diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/http/HttpAsdcClientTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/http/HttpAsdcClientTest.java
index cbd12c3..6193e4c 100644
--- a/sdc-distribution-client/src/test/java/org/onap/sdc/http/HttpAsdcClientTest.java
+++ b/sdc-distribution-client/src/test/java/org/onap/sdc/http/HttpAsdcClientTest.java
@@ -41,6 +41,7 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.sdc.utils.Pair;
import org.onap.sdc.utils.TestConfiguration;
+import org.onap.sdc.utils.CaseInsensitiveMap;
@ExtendWith(MockitoExtension.class)
class HttpSdcClientTest {
@@ -51,7 +52,7 @@ class HttpSdcClientTest {
private static final String K_2 = "k2";
private static final String V_2 = "v2";
private static final Header[] HEADERS = new Header[]{new BasicHeader(K_1, V_1), new BasicHeader(K_2, V_2)};
- private static final HashMap<String, String> HEADERS_MAP = new HashMap<String, String>() {{
+ private static final CaseInsensitiveMap<String, String> HEADERS_MAP = new CaseInsensitiveMap<String, String>() {{
put("key1", "key2");
}};
diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/http/HttpRequestFactoryTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/http/HttpRequestFactoryTest.java
index c9eb4b3..a5404ae 100644
--- a/sdc-distribution-client/src/test/java/org/onap/sdc/http/HttpRequestFactoryTest.java
+++ b/sdc-distribution-client/src/test/java/org/onap/sdc/http/HttpRequestFactoryTest.java
@@ -25,12 +25,11 @@ import static org.mockito.Mockito.mock;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.junit.jupiter.api.Test;
+import org.onap.sdc.utils.CaseInsensitiveMap;
class HttpRequestFactoryTest {
@@ -40,7 +39,7 @@ class HttpRequestFactoryTest {
private static final String HEADER_KEY_2 = "key2";
private static final String HEADER_VALUE_1 = "value1";
private static final String HEADER_VALUE_2 = "value2";
- private static final Map<String, String> HEADERS = new HashMap<String, String>() {
+ private static final CaseInsensitiveMap<String, String> HEADERS = new CaseInsensitiveMap<String, String>() {
{
put(HEADER_KEY_1, HEADER_VALUE_1);
put(HEADER_KEY_2, HEADER_VALUE_2);
diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/http/SdcConnectorClientTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/http/SdcConnectorClientTest.java
index 61b8388..e449c4c 100644
--- a/sdc-distribution-client/src/test/java/org/onap/sdc/http/SdcConnectorClientTest.java
+++ b/sdc-distribution-client/src/test/java/org/onap/sdc/http/SdcConnectorClientTest.java
@@ -38,7 +38,6 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
@@ -54,6 +53,7 @@ import org.onap.sdc.api.results.IDistributionClientResult;
import org.onap.sdc.utils.DistributionActionResultEnum;
import org.onap.sdc.utils.Pair;
import org.onap.sdc.utils.kafka.KafkaDataResponse;
+import org.onap.sdc.utils.CaseInsensitiveMap;
public class SdcConnectorClientTest {
@@ -61,7 +61,7 @@ public class SdcConnectorClientTest {
private static final HttpSdcClient httpClient = mock(HttpSdcClient.class);
private static final IConfiguration configuration = mock(IConfiguration.class);
private static final HttpSdcResponse httpSdcResponse = mock(HttpSdcResponse.class);
- private static final Map<String, String> mockHeaders = new HashMap<>();
+ private static final Map<String, String> mockHeaders = new CaseInsensitiveMap<>();
private static SdcConnectorClient sdcClient;
private static final String ARTIFACT_URL = "http://127.0.0.1/artifact/url";
@@ -219,7 +219,7 @@ public class SdcConnectorClientTest {
@Test
public void downloadArtifactHappyScenarioTest() throws IOException {
- Map<String, String> headers = new HashMap<>();
+ CaseInsensitiveMap<String, String> headers = new CaseInsensitiveMap<>();
headers.put(SdcConnectorClient.CONTENT_DISPOSITION_HEADER, "SomeHeader");
IArtifactInfo artifactInfo = mock(IArtifactInfo.class);
@@ -242,6 +242,9 @@ public class SdcConnectorClientTest {
@Test
public void downloadArtifactDataIntegrityProblemTest() throws IOException {
+ CaseInsensitiveMap<String, String> headers = new CaseInsensitiveMap<>();
+ headers.put(SdcConnectorClient.CONTENT_DISPOSITION_HEADER, "SomeHeader");
+
IArtifactInfo artifactInfo = mock(IArtifactInfo.class);
when(artifactInfo.getArtifactURL()).thenReturn(ARTIFACT_URL);
@@ -251,6 +254,7 @@ public class SdcConnectorClientTest {
when(responseMock.getStatus()).thenReturn(HttpStatus.SC_OK);
when(responseMock.getMessage()).thenReturn(messageMock);
+ when(responseMock.getHeadersMap()).thenReturn(headers);
when(messageMock.getContent()).thenReturn(new ByteArrayInputStream(BYTES));
doReturn(responsePair).when(httpClient).getRequest(eq(ARTIFACT_URL), any(), eq(false));
@@ -260,6 +264,9 @@ public class SdcConnectorClientTest {
@Test
public void downloadArtifactExceptionDuringDownloadHandlingTest() throws IOException {
+ CaseInsensitiveMap<String, String> headers = new CaseInsensitiveMap<>();
+ headers.put(SdcConnectorClient.CONTENT_DISPOSITION_HEADER, "SomeHeader");
+
IArtifactInfo artifactInfo = mock(IArtifactInfo.class);
when(artifactInfo.getArtifactURL()).thenReturn(ARTIFACT_URL);
@@ -269,6 +276,7 @@ public class SdcConnectorClientTest {
when(responseMock.getStatus()).thenReturn(HttpStatus.SC_OK);
when(responseMock.getMessage()).thenReturn(messageMock);
+ when(responseMock.getHeadersMap()).thenReturn(headers);
when(messageMock.getContent()).thenReturn(new ThrowingInputStreamForTesting());
doReturn(responsePair).when(httpClient).getRequest(eq(ARTIFACT_URL), any(), eq(false));