summaryrefslogtreecommitdiffstats
path: root/common-logging/src/test/java/org
diff options
context:
space:
mode:
authorJoseph Chou <jc2555@att.com>2020-04-22 14:06:23 -0400
committerJoseph Chou <jc2555@att.com>2020-04-28 10:07:15 -0400
commit7968b32c3f18cf8e98d87229f100c622323cd78e (patch)
tree02fc7886f49adf12be047eb5bb5a15ab77c64b12 /common-logging/src/test/java/org
parent2cf13e0dcad627b8ba0b6b320c958b9026d1a975 (diff)
Logging enhancement work
Update log tool to provide placeholder feature Change-Id: I3f2b10d009a1d51f30a6080c07459eb0ac07189f Issue-ID: POLICY-2478 Signed-off-by: Joseph Chou <jc2555@att.com>
Diffstat (limited to 'common-logging/src/test/java/org')
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java20
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java20
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java10
3 files changed, 44 insertions, 6 deletions
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java
index b318c18d..adb7d366 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java
@@ -36,6 +36,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
import static org.onap.policy.common.logging.eelf.OnapConfigProperties.PARTNER_NAME;
import static org.onap.policy.common.logging.eelf.OnapConfigProperties.RESPONSE_CODE;
import static org.onap.policy.common.logging.eelf.OnapConfigProperties.RESPONSE_DESCRIPTION;
@@ -200,6 +202,9 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info("str1", "str2");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
+ PolicyLogger.info("str1", "str2");
Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "str2");
}
@@ -243,6 +248,9 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn("str1", "str2");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isWarnEnabled()).thenReturn(true);
+ PolicyLogger.warn("str1", "str2");
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_INFO, "str2");
}
@@ -286,6 +294,9 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error("str1", "str2");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isErrorEnabled()).thenReturn(true);
+ PolicyLogger.error("str1", "str2");
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str2");
assertEquals("500", MDC.get("ErrorCode"));
assertEquals("This is a general error message during the process. Please check the error message for detail "
@@ -356,6 +367,9 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug("str1", "str2");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isDebugEnabled()).thenReturn(true);
+ PolicyLogger.debug("str1", "str2");
Mockito.verify(mockLogger).debug(MessageCodes.GENERAL_INFO, "str2");
}
@@ -380,6 +394,9 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "auditLogger", mockLogger);
PolicyLogger.audit("PolicyLoggerTest", 1);
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
+ PolicyLogger.audit("PolicyLoggerTest", 1);
assertEquals("PolicyLoggerTest", MDC.get("ClassName"));
assertEquals("COMPLETE", MDC.get("StatusCode"));
Mockito.verify(mockLogger).info("1");
@@ -591,6 +608,9 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics("PolicyLoggerTest", 1);
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
+ PolicyLogger.metrics("PolicyLoggerTest", 1);
Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
Mockito.eq("1"));
}
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java
index d3c09ee6..1245e164 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java
@@ -3,7 +3,7 @@
* ONAP-Logging
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.never;
import com.att.eelf.configuration.EELFLogger;
import java.util.UUID;
@@ -93,6 +94,9 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.debug("message");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isDebugEnabled()).thenReturn(true);
+ eelfLogger.debug("message");
Mockito.verify(mockLogger).debug(MessageCodes.GENERAL_INFO, "message");
}
@@ -101,6 +105,9 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error("message");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isErrorEnabled()).thenReturn(true);
+ eelfLogger.error("message");
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "message");
}
@@ -109,6 +116,9 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.info("message");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
+ eelfLogger.info("message");
Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "message");
}
@@ -117,6 +127,9 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn("message");
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isWarnEnabled()).thenReturn(true);
+ eelfLogger.warn("message");
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_INFO, "message");
}
@@ -219,6 +232,8 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.info("message", new NullPointerException());
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
Mockito.verify(mockLogger).info((MessageCodes) Mockito.any(),
Mockito.startsWith("message:java.lang.NullPointerException"));
}
@@ -317,6 +332,9 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
eelfLogger.metrics(1);
+ Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
+ eelfLogger.metrics(1);
Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
Mockito.eq("1"));
}
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java
index ca73d1cb..cde423f5 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java
@@ -427,7 +427,7 @@ public class SystemOutLoggerTest {
try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
- systemOutLogger.debug(1, new NullPointerException());
+ systemOutLogger.debug("1", new NullPointerException());
assertTrue(baos.toString(),
baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
@@ -444,7 +444,7 @@ public class SystemOutLoggerTest {
try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
- systemOutLogger.error(1, new NullPointerException());
+ systemOutLogger.error("1", new NullPointerException());
assertTrue(baos.toString(),
baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
@@ -461,7 +461,7 @@ public class SystemOutLoggerTest {
try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
- systemOutLogger.info(1, new NullPointerException());
+ systemOutLogger.info("1", new NullPointerException());
assertTrue(baos.toString(),
baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
@@ -478,7 +478,7 @@ public class SystemOutLoggerTest {
try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
- systemOutLogger.warn(1, new NullPointerException());
+ systemOutLogger.warn("1", new NullPointerException());
assertTrue(baos.toString(),
baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
@@ -512,7 +512,7 @@ public class SystemOutLoggerTest {
try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
- systemOutLogger.audit(1, new NullPointerException());
+ systemOutLogger.audit("1", new NullPointerException());
assertTrue(baos.toString(),
baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {