summaryrefslogtreecommitdiffstats
path: root/datafile-app-server/src/test
diff options
context:
space:
mode:
authorRehanRaza <muhammad.rehan.raza@est.tech>2019-05-13 14:02:39 +0000
committerRehanRaza <muhammad.rehan.raza@est.tech>2019-05-13 14:02:39 +0000
commit75d51a299e7d36cb988ef074fce00eb4b29a3394 (patch)
treece2c20f9d24c30822473098556991dec39f58490 /datafile-app-server/src/test
parent0e7fe2901b830841efb9d575c14c6c7ada7c7e0f (diff)
Bugfix: add MDC context to http redirect logs
Change-Id: Icdf00480eed43536a8b4693cbb208560f0881c95 Issue-ID: DCAEGEN2-1462 Signed-off-by: RehanRaza <muhammad.rehan.raza@est.tech>
Diffstat (limited to 'datafile-app-server/src/test')
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java3
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java15
2 files changed, 14 insertions, 4 deletions
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java
index add47b0a..e21bbd7b 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
@@ -110,7 +109,7 @@ class DmaapProducerHttpClientTest {
verify(clientBuilderMock).setSslContext(any(SSLContext.class));
verify(clientBuilderMock).setSslHostnameVerifier(any(NoopHostnameVerifier.class));
- verify(clientBuilderMock).setRedirectStrategy(PublishRedirectStrategy.INSTANCE);
+ verify(clientBuilderMock).setRedirectStrategy(any(PublishRedirectStrategy.class));
verify(clientBuilderMock).setDefaultRequestConfig(any());
verify(clientBuilderMock).build();
verifyNoMoreInteractions(clientBuilderMock);
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java
index 298656a8..df13f2db 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java
@@ -19,7 +19,8 @@ package org.onap.dcaegen2.collectors.datafile.web;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-
+import java.util.HashMap;
+import java.util.Map;
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
@@ -32,16 +33,23 @@ import org.apache.http.protocol.HttpContext;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables;
+import org.slf4j.MDC;
class PublishRedirectStrategyTest {
private static final String URI = "sftp://localhost:80/";
+ private static final String SAMPLE_REQUEST_ID = "A20000626.2315+0200-2330+0200_PNF0-0-1MB.tar.gz";
+ private static final String ANOTHER_REQUEST_ID = "something_else";
private static PublishRedirectStrategy publishRedirectStrategy;
@BeforeAll
static void setUp() {
- publishRedirectStrategy = new PublishRedirectStrategy();
+ MDC.put(MdcVariables.REQUEST_ID, ANOTHER_REQUEST_ID);
+ Map<String, String> contextMap = new HashMap<>();
+ contextMap.put(MdcVariables.REQUEST_ID, SAMPLE_REQUEST_ID);
+ publishRedirectStrategy = new PublishRedirectStrategy(contextMap);
}
@Test
@@ -70,5 +78,8 @@ class PublishRedirectStrategyTest {
HttpUriRequest actualRedirect = publishRedirectStrategy.getRedirect(requestMock, responseMock, contextMock);
assertEquals(URI, actualRedirect.getURI().toString());
+
+ String actualRequestId = MDC.get(MdcVariables.REQUEST_ID);
+ assertEquals(SAMPLE_REQUEST_ID, actualRequestId);
}
}