From 75d51a299e7d36cb988ef074fce00eb4b29a3394 Mon Sep 17 00:00:00 2001 From: RehanRaza Date: Mon, 13 May 2019 14:02:39 +0000 Subject: Bugfix: add MDC context to http redirect logs Change-Id: Icdf00480eed43536a8b4693cbb208560f0881c95 Issue-ID: DCAEGEN2-1462 Signed-off-by: RehanRaza --- .../service/producer/DmaapProducerHttpClientTest.java | 3 +-- .../datafile/web/PublishRedirectStrategyTest.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'datafile-app-server/src/test') 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 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); } } -- cgit 1.2.3-korg