aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-11-06 08:16:08 +0200
committerEylon Malin <eylon.malin@intl.att.com>2019-11-06 09:20:53 +0000
commit06e518055d9758ee3ecc2e40efe13c7a5d982a2a (patch)
tree6eda3ee37920da456a42643fc001a7d752ff6e69 /vid-app-common/src/test
parentb84d6332c492206cecf11d54a884c8a299ef1690 (diff)
print user-id in partner name record of audit log
Issue-ID: VID-253 Also add more verifications for audit log format Change-Id: I00976a63fd1a795a972c13ad975d6a71248e5c8b Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-app-common/src/test')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/logging/VidLoggingInterceptorTest.java61
1 files changed, 57 insertions, 4 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/logging/VidLoggingInterceptorTest.java b/vid-app-common/src/test/java/org/onap/vid/logging/VidLoggingInterceptorTest.java
index fc78ed714..c31d00df8 100644
--- a/vid-app-common/src/test/java/org/onap/vid/logging/VidLoggingInterceptorTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/logging/VidLoggingInterceptorTest.java
@@ -20,10 +20,22 @@
package org.onap.vid.logging;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import static org.onap.vid.logging.VidLoggingInterceptor.INBOUND_INVO_ID;
import static org.testng.Assert.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+import java.util.HashMap;
+import javax.servlet.http.HttpServletRequest;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.logging.filter.base.SimpleHashMap;
+import org.onap.logging.filter.base.SimpleMap;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs;
+import org.onap.vid.controller.ControllersUtils;
import org.slf4j.MDC;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -32,17 +44,58 @@ public class VidLoggingInterceptorTest {
private VidLoggingInterceptor interceptor;
+ @Mock
+ private ControllersUtils controllersUtils;
+
@BeforeMethod
public void setup() {
- interceptor = new VidLoggingInterceptor();
+ MockitoAnnotations.initMocks(this);
+ interceptor = new VidLoggingInterceptor(controllersUtils);
MDC.clear();
}
@Test
public void testAdditionalPreHandling() {
- MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, "987");
- interceptor.additionalPreHandling(null);
- assertEquals(MDC.get(INBOUND_INVO_ID), "987");
+
+ //given
+ final String invoID = "987";
+ MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invoID);
+ MDC.put(MDCs.PARTNER_NAME, "wrongPartnerName");
+ final String myUserId = "myUserId";
+ when(controllersUtils.extractUserId(any(HttpServletRequest.class)))
+ .thenReturn(myUserId);
+
+ //when
+ interceptor.additionalPreHandling(mock(HttpServletRequest.class));
+
+ //then
+ assertEquals(MDC.get(INBOUND_INVO_ID), invoID);
+ assertEquals(MDC.get(MDCs.PARTNER_NAME), myUserId);
+ }
+
+ @Test
+ public void whenNoUserId_previousPartnerNameIsPreserved() {
+ //given
+ final String prevPartnerName = "prevPartnerName";
+ MDC.put(MDCs.PARTNER_NAME, prevPartnerName);
+ final HttpServletRequest mockedRequest = mock(HttpServletRequest.class);
+ when(controllersUtils.extractUserId(any(HttpServletRequest.class)))
+ .thenReturn("");
+
+ //when
+ interceptor.additionalPreHandling(mockedRequest);
+
+ //then
+ assertEquals(MDC.get(MDCs.PARTNER_NAME), prevPartnerName);
+
+ }
+
+ @Test
+ public void givenNotValidAuthorizationHeader_whenGetBasicAuthUserName_noExceptionIsThrown() {
+ HashMap<String, String> hashMap = new HashMap<>();
+ hashMap.put("Authorization","abcdefghi");
+ SimpleMap headers = new SimpleHashMap(hashMap);
+ assertNull(interceptor.getBasicAuthUserName(headers));
}
}