summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java18
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java102
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/ErrorCodeMapTest.java56
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java683
4 files changed, 787 insertions, 72 deletions
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java
index 4df86a4d..845c5caf 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java
@@ -28,9 +28,8 @@ import java.util.EnumMap;
*
*/
public class ErrorCodeMap {
-
- protected static final EnumMap<MessageCodes, ErrorCodeInfo> hm = new EnumMap<>(MessageCodes.class);
+ private static final EnumMap<MessageCodes, ErrorCodeInfo> hm = new EnumMap<>(MessageCodes.class);
private static final String ERROR_PERMISSIONS = "POLICY-100E";
private static final String ERROR_PERMISSIONS_DESCRIPTION = "This is a Permissions Error. Please check the error message for detail information";
@@ -79,7 +78,12 @@ public class ErrorCodeMap {
hm.put(MessageCodes.ERROR_UNKNOWN, new ErrorCodeInfo(ERROR_UNKNOWN, ERROR_UNKNOWN_DESCRIPTION));
hm.put(MessageCodes.ERROR_AUDIT, new ErrorCodeInfo(ERROR_AUDIT, ERROR_AUDIT_DESCRIPTION));
}
- private ErrorCodeMap() {};
+ private ErrorCodeMap() {}
+
+ public static ErrorCodeInfo getErrorCodeInfo(MessageCodes messageCode) {
+ return hm.get(messageCode);
+ }
+
static class ErrorCodeInfo {
private String errorCode;
@@ -94,17 +98,9 @@ public class ErrorCodeMap {
return errorCode;
}
- public void setErrorCode(String errorCode) {
- this.errorCode = errorCode;
- }
-
public String getErrorDesc() {
return errorDesc;
}
-
- public void setErrorDesc(String errorDesc) {
- this.errorDesc = errorDesc;
- }
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java
index 58db1da4..3d351722 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java
@@ -361,16 +361,6 @@ public class PolicyLogger {
/**
* Records the Info event with String [] arguments
* @param msg
- * @param arguments
- */
- public static void info(MessageCodes msg, String... arguments) {
- MDC.put(classNameProp, "");
- debugLogger.info(msg, arguments);
- }
-
- /**
- * Records the Info event with String [] arguments
- * @param msg
* @param className
* @param arguments
*/
@@ -453,16 +443,6 @@ public class PolicyLogger {
MDC.put(classNameProp, "");
debugLogger.warn(MessageCodes.GENERAL_WARNING, arg0);
}
-
- /**
- * Records a message with passed in message code and a list of string values
- * @param msg
- * @param arguments
- */
- public static void warn(MessageCodes msg, String... arguments) {
- MDC.put(classNameProp, "");
- debugLogger.warn(msg, arguments);
- }
/**
* Records a message with passed in message code, class name and a list of string values
@@ -509,9 +489,9 @@ public class PolicyLogger {
*/
public static void error( String className, String arg0) {
MDC.put(classNameProp, className);
- if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
- MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+ if(ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
}
errorLogger.error(MessageCodes.GENERAL_ERROR, arg0);
@@ -525,9 +505,9 @@ public class PolicyLogger {
MDC.put(classNameProp, "");
MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
- MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+ if(ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
}
errorLogger.error(MessageCodes.GENERAL_ERROR, arg0);
@@ -541,9 +521,9 @@ public class PolicyLogger {
MDC.put(classNameProp, "");
MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
- MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+ if(ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
}
errorLogger.error(MessageCodes.GENERAL_ERROR, "" + arg0);
@@ -560,9 +540,9 @@ public class PolicyLogger {
MDC.put(classNameProp, "");
MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if(ErrorCodeMap.hm.get(msg) != null){
- MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(msg).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(msg).getErrorDesc());
+ if(ErrorCodeMap.getErrorCodeInfo(msg) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(msg).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(msg).getErrorDesc());
}
String arguments2 = getNormalizedStackTrace(arg0, arguments);
@@ -581,9 +561,9 @@ public class PolicyLogger {
MDC.put(classNameProp, className);
MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if(ErrorCodeMap.hm.get(msg) != null){
- MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(msg).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(msg).getErrorDesc());
+ if(ErrorCodeMap.getErrorCodeInfo(msg) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(msg).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(msg).getErrorDesc());
}
String arguments2 = getNormalizedStackTrace(arg0, arguments);
@@ -599,9 +579,9 @@ public class PolicyLogger {
MDC.put(classNameProp, "");
MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if(ErrorCodeMap.hm.get(msg) != null){
- MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(msg).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(msg).getErrorDesc());
+ if(ErrorCodeMap.getErrorCodeInfo(msg) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(msg).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(msg).getErrorDesc());
}
errorLogger.error(msg, arguments);
@@ -677,7 +657,7 @@ public class PolicyLogger {
String... arguments) {
MDC.put(classNameProp, "");
String arguments2 = getNormalizedStackTrace(arg0, arguments);
- errorLogger.error(msg, arguments2);
+ debugLogger.debug(msg, arguments2);
}
/**
@@ -691,7 +671,7 @@ public class PolicyLogger {
String... arguments) {
MDC.put(classNameProp, className);
String arguments2 = getNormalizedStackTrace(arg0, arguments);
- errorLogger.error(msg, arguments2);
+ debugLogger.debug(msg, arguments2);
}
/**
* returns true for enabled, false for not enabled
@@ -748,7 +728,7 @@ public class PolicyLogger {
*/
public static void trace( String className, String arg0) {
MDC.put(classNameProp, className);
- errorLogger.info(MessageCodes.GENERAL_INFO, arg0);
+ debugLogger.trace(MessageCodes.GENERAL_INFO, arg0);
}
/**
@@ -1172,8 +1152,8 @@ public class PolicyLogger {
String debugLevelProp = loggerProperties.getProperty("debugLogger.level","INFO");
String metricsLevelProp = loggerProperties.getProperty("metricsLogger.level","ON");
- String auditLevelProp = loggerProperties.getProperty("error.level","ON");
- String errorLevelProp = loggerProperties.getProperty("audit.level","ON");
+ String auditLevelProp = loggerProperties.getProperty("audit.level","ON");
+ String errorLevelProp = loggerProperties.getProperty("error.level","ON");
component = loggerProperties.getProperty("policy.component","DROOLS");
String overrideLogbackLevel = loggerProperties.getProperty("override.logback.level.setup");
@@ -1240,9 +1220,9 @@ public class PolicyLogger {
}else {
MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
- MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+ if(ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
}
errorLogger.error("failed to get the timer.delay.time, so use its default value: " + timerDelayTime);
@@ -1254,9 +1234,9 @@ public class PolicyLogger {
}else {
MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
- MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+ if(ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
}
errorLogger.error("failed to get the check.interval, so use its default value: " + checkInterval);
@@ -1269,9 +1249,9 @@ public class PolicyLogger {
}else {
MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
- MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+ if(ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
}
errorLogger.error("failed to get the event.expired.time, so use its default value: " + expiredTime);
@@ -1283,9 +1263,9 @@ public class PolicyLogger {
}else {
MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
- MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+ if(ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
}
errorLogger.error("failed to get the concurrentHashMap.limit, so use its default value: " + concurrentHashMapLimit);
@@ -1297,9 +1277,9 @@ public class PolicyLogger {
}else {
MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
- MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+ if(ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
}
errorLogger.error("failed to get the stop.check.point, so use its default value: " + stopCheckPoint);
@@ -1350,9 +1330,9 @@ public class PolicyLogger {
}catch(Exception e){
MDC.put(ERROR_CATEGORY, ERROR_CATEGORY_VALUE);
- if(ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR) != null){
- MDC.put(ERROR_CODE, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorCode());
- MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.hm.get(MessageCodes.GENERAL_ERROR).getErrorDesc());
+ if(ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR) != null){
+ MDC.put(ERROR_CODE, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorCode());
+ MDC.put(ERROR_DESCRIPTION, ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc());
}
errorLogger.error("failed to get the policyLogger.properties, so use their default values",e);
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/ErrorCodeMapTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/ErrorCodeMapTest.java
new file mode 100644
index 00000000..ed4c879f
--- /dev/null
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/ErrorCodeMapTest.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-Logging
+ * ================================================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.common.logging.eelf;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.onap.policy.common.logging.eelf.ErrorCodeMap.ErrorCodeInfo;
+
+public class ErrorCodeMapTest {
+
+ @Test
+ public void testGetErrorCodeInfo() {
+ assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.EXCEPTION_ERROR));
+ assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR));
+ assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.MISS_PROPERTY_ERROR));
+ assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.UPDATE_ERROR));
+ assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.ERROR_SYSTEM_ERROR));
+ assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.ERROR_DATA_ISSUE));
+ assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.ERROR_PERMISSIONS));
+ assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.ERROR_DATA_ISSUE));
+ assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.ERROR_PROCESS_FLOW));
+ assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.ERROR_SCHEMA_INVALID));
+ assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.ERROR_UNKNOWN));
+ assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.ERROR_AUDIT));
+ }
+
+ @Test
+ public void testErrorCodeInfoGetErrorCode() {
+ ErrorCodeInfo errorCodeInfo = ErrorCodeMap.getErrorCodeInfo(MessageCodes.EXCEPTION_ERROR);
+ assertEquals("POLICY-503E", errorCodeInfo.getErrorCode());
+ }
+
+ @Test
+ public void testErrorCodeInfoGetErrorDesc() {
+ ErrorCodeInfo errorCodeInfo = ErrorCodeMap.getErrorCodeInfo(MessageCodes.EXCEPTION_ERROR);
+ assertEquals("This is an exception error message during the process. Please check the error message for detail information", errorCodeInfo.getErrorDesc());
+ }
+
+}
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
new file mode 100644
index 00000000..910e0ba2
--- /dev/null
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java
@@ -0,0 +1,683 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-Logging
+ * ================================================================================
+ * Copyright (C) 2018 Ericsson. 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.common.logging.eelf;
+
+import static com.att.eelf.configuration.Configuration.MDC_ALERT_SEVERITY;
+import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID;
+import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
+import static com.att.eelf.configuration.Configuration.MDC_REMOTE_HOST;
+import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
+import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
+import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
+import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
+import static org.junit.Assert.*;
+import static org.onap.policy.common.logging.eelf.Configuration.PARTNER_NAME;
+import static org.onap.policy.common.logging.eelf.Configuration.RESPONSE_CODE;
+import static org.onap.policy.common.logging.eelf.Configuration.RESPONSE_DESCRIPTION;
+import static org.onap.policy.common.logging.eelf.Configuration.SERVER_NAME;
+import static org.onap.policy.common.logging.eelf.Configuration.STATUS_CODE;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.time.Instant;
+import java.util.Properties;
+import java.util.UUID;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.slf4j.MDC;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFLogger.Level;
+
+public class PolicyLoggerTest {
+
+ @Before
+ public void setUp(){
+ Properties properties = new Properties();
+ properties.setProperty("policy.component", "XACML");
+ PolicyLogger.init(properties);
+ }
+
+ @Test
+ public void testSetAndGetDebugLevelLevel() {
+ PolicyLogger.setDebugLevel(Level.INFO);
+ assertEquals(Level.INFO, PolicyLogger.getDebugLevel());
+ PolicyLogger.setDebugLevel(Level.DEBUG);
+ assertEquals(Level.DEBUG, PolicyLogger.getDebugLevel());
+ }
+
+ @Test
+ public void testSetAndGetAuditLevelLevel() {
+ PolicyLogger.setAuditLevel(Level.INFO);
+ assertEquals(Level.INFO, PolicyLogger.getAuditLevel());
+ PolicyLogger.setAuditLevel(Level.DEBUG);
+ assertEquals(Level.DEBUG, PolicyLogger.getAuditLevel());
+ }
+
+ @Test
+ public void testSetAndGetMetricsLevelLevel() {
+ PolicyLogger.setMetricsLevel(Level.INFO);
+ assertEquals(Level.INFO, PolicyLogger.getMetricsLevel());
+ PolicyLogger.setMetricsLevel(Level.DEBUG);
+ assertEquals(Level.DEBUG, PolicyLogger.getMetricsLevel());
+ }
+
+ @Test
+ public void testSetAndGetErrorLevelLevel() {
+ PolicyLogger.setErrorLevel(Level.INFO);
+ assertEquals(Level.INFO, PolicyLogger.getErrorLevel());
+ PolicyLogger.setErrorLevel(Level.DEBUG);
+ assertEquals(Level.DEBUG, PolicyLogger.getErrorLevel());
+ }
+
+ @Test
+ public void testSetAndGetClassname() {
+ assertEquals("ClassName", PolicyLogger.getClassname());
+ PolicyLogger.setClassname("PolicyLoggerTest");
+ assertEquals("PolicyLoggerTest", PolicyLogger.getClassname());
+ }
+
+ @Test
+ public void testPostMDCInfoForEventString() {
+ PolicyLogger.postMDCInfoForEvent("transactionId");
+
+ assertEquals("", MDC.get(MDC_REMOTE_HOST));
+ assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
+ assertEquals("Policy.xacmlPdp", MDC.get(MDC_SERVICE_NAME));
+ assertEquals("Policy.xacmlPdp.event", MDC.get(MDC_SERVICE_INSTANCE_ID));
+ assertEquals("", MDC.get(MDC_INSTANCE_UUID));
+ assertEquals("", MDC.get(MDC_ALERT_SEVERITY));
+ assertEquals("N/A", MDC.get(PARTNER_NAME));
+ assertEquals("COMPLETE", MDC.get(STATUS_CODE));
+ assertEquals("N/A", MDC.get(RESPONSE_CODE));
+ assertEquals("N/A", MDC.get(RESPONSE_DESCRIPTION));
+ }
+
+ @Test
+ public void testPostMDCInfoForEventStringDrools() {
+ Properties properties = new Properties();
+ properties.setProperty("policy.component", "DROOLS");
+ PolicyLogger.init(properties);
+
+ PolicyLogger.postMDCInfoForEvent("transactionId");
+
+ assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
+ assertEquals("Policy.droolsPdp", MDC.get(MDC_SERVICE_NAME));
+ assertEquals("Policy.droolsPdp.event", MDC.get(MDC_SERVICE_INSTANCE_ID));
+ }
+
+ @Test
+ public void testSetAndGetTransId() {
+ PolicyLogger.setTransId("123456");
+ assertEquals("123456", PolicyLogger.getTransId());
+ }
+
+ @Test
+ public void testPostMDCInfoForEventObject() {
+ PolicyLogger.postMDCInfoForEvent(1);
+
+ assertEquals("", MDC.get(MDC_REMOTE_HOST));
+ assertEquals("1", MDC.get(MDC_KEY_REQUEST_ID));
+ assertEquals("Policy.xacmlPdp", MDC.get(MDC_SERVICE_NAME));
+ assertEquals("Policy.xacmlPdp.event", MDC.get(MDC_SERVICE_INSTANCE_ID));
+ assertEquals("", MDC.get(MDC_INSTANCE_UUID));
+ assertEquals("", MDC.get(MDC_ALERT_SEVERITY));
+ assertEquals("N/A", MDC.get(PARTNER_NAME));
+ assertEquals("COMPLETE", MDC.get(STATUS_CODE));
+ assertEquals("N/A", MDC.get(RESPONSE_CODE));
+ assertEquals("N/A", MDC.get(RESPONSE_DESCRIPTION));
+ }
+
+ @Test
+ public void testPostMDCInfoForTriggeredRule() {
+ PolicyLogger.postMDCInfoForTriggeredRule("transactionId");
+
+ assertEquals("", MDC.get(MDC_REMOTE_HOST));
+ assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
+ assertEquals("Policy.droolsPdp", MDC.get(MDC_SERVICE_NAME));
+ assertEquals("", MDC.get(MDC_SERVICE_INSTANCE_ID));
+ assertNotNull(MDC.get(MDC_SERVER_FQDN));
+ assertNotNull(MDC.get(MDC_SERVER_IP_ADDRESS));
+ assertEquals("", MDC.get(MDC_INSTANCE_UUID));
+ assertEquals("", MDC.get(MDC_ALERT_SEVERITY));
+ assertEquals("COMPLETE", MDC.get(STATUS_CODE));
+ }
+
+ @Test
+ public void testPostMDCUUIDForTriggeredRule() {
+ PolicyLogger.postMDCUUIDForTriggeredRule(1);
+
+ assertEquals("", MDC.get(MDC_REMOTE_HOST));
+ assertEquals("1", MDC.get(MDC_KEY_REQUEST_ID));
+ assertEquals("Policy.droolsPdp", MDC.get(MDC_SERVICE_NAME));
+ assertEquals("", MDC.get(MDC_SERVICE_INSTANCE_ID));
+ assertNotNull(MDC.get(MDC_SERVER_FQDN));
+ assertNotNull(MDC.get(MDC_SERVER_IP_ADDRESS));
+ assertEquals("", MDC.get(MDC_INSTANCE_UUID));
+ assertEquals("", MDC.get(MDC_ALERT_SEVERITY));
+ assertEquals("COMPLETE", MDC.get(STATUS_CODE));
+ }
+
+ @Test
+ public void testInfoMessageCodesStringStringArray() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
+ Mockito.verify(mockLogger).info(MessageCodes.ERROR_DATA_ISSUE, "str2");
+ }
+
+ @Test
+ public void testInfoStringString() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.info("str1", "str2");
+ Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "str2");
+ }
+
+ @Test
+ public void testInfoObject() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.info("str1");
+ Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "str1");
+ }
+
+ @Test
+ public void testInfoMessageCodesThrowableStringArray() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
+ Mockito.verify(mockLogger).info((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ }
+
+ @Test
+ public void testInfoMessageCodesStringThrowableStringArray() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1", "str2");
+ Mockito.verify(mockLogger).info((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ }
+
+ @Test
+ public void testWarnMessageCodesStringStringArray() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "str1");
+ Mockito.verify(mockLogger).warn(MessageCodes.ERROR_DATA_ISSUE);
+ }
+
+ @Test
+ public void testWarnStringString() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.warn("str1", "str2");
+ Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_INFO, "str2");
+ }
+
+ @Test
+ public void testWarnObject() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.warn(1);
+ Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_WARNING, "1");
+ }
+
+ @Test
+ public void testWarnMessageCodesThrowableStringArray() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
+ Mockito.verify(mockLogger).warn((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ }
+
+ @Test
+ public void testWarnMessageCodesStringThrowableStringArray() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1", "str2");
+ Mockito.verify(mockLogger).warn((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ }
+
+ @Test
+ public void testWarnString() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.warn("str1");
+ Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_WARNING, "str1");
+ }
+
+ @Test
+ public void testErrorStringString() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ PolicyLogger.error("str1", "str2");
+ Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str2");
+ assertEquals("POLICY-515E", MDC.get("ErrorCode"));
+ assertEquals("This is a general error message during the process. Please check the error message for detail information", MDC.get("ErrorDescription"));
+ }
+
+ @Test
+ public void testErrorString() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ PolicyLogger.error("str1");
+ Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str1");
+ assertEquals("ERROR", MDC.get("ErrorCategory"));
+ assertEquals("POLICY-515E", MDC.get("ErrorCode"));
+ assertEquals("This is a general error message during the process. Please check the error message for detail information", MDC.get("ErrorDescription"));
+ }
+
+ @Test
+ public void testErrorObject() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ PolicyLogger.error(1);
+ Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "1");
+ assertEquals("ERROR", MDC.get("ErrorCategory"));
+ assertEquals("POLICY-515E", MDC.get("ErrorCode"));
+ assertEquals("This is a general error message during the process. Please check the error message for detail information", MDC.get("ErrorDescription"));
+ }
+
+ @Test
+ public void testErrorMessageCodesThrowableStringArray() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
+ Mockito.verify(mockLogger).error((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ }
+
+ @Test
+ public void testErrorMessageCodesStringThrowableStringArray() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1", "str2");
+ Mockito.verify(mockLogger).error((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ }
+
+ @Test
+ public void testErrorMessageCodesStringArray() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
+ Mockito.verify(mockLogger).error(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
+ }
+
+ @Test
+ public void testDebugMessageCodesStringArray() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
+ Mockito.verify(mockLogger).debug(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
+ }
+
+ @Test
+ public void testDebugStringString() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.debug("str1", "str2");
+ Mockito.verify(mockLogger).debug(MessageCodes.GENERAL_INFO, "str2");
+ }
+
+ @Test
+ public void testDebugString() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.debug("str1");
+ Mockito.verify(mockLogger).debug("str1");
+ }
+
+ @Test
+ public void testDebugObject() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.debug(1);
+ Mockito.verify(mockLogger).debug("1");
+ }
+
+ @Test
+ public void testAuditStringObject() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "auditLogger", mockLogger);
+ PolicyLogger.audit("PolicyLoggerTest", 1);
+ assertEquals("PolicyLoggerTest", MDC.get("ClassName"));
+ assertEquals("COMPLETE", MDC.get("StatusCode"));
+ Mockito.verify(mockLogger).info("1");
+ }
+
+ @Test
+ public void testAuditObject() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "auditLogger", mockLogger);
+ PolicyLogger.audit(1);
+ assertEquals("", MDC.get("ClassName"));
+ assertEquals("COMPLETE", MDC.get("StatusCode"));
+ Mockito.verify(mockLogger).info("1");
+ }
+
+ @Test
+ public void testDebugMessageCodesThrowableStringArray() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
+ Mockito.verify(mockLogger).debug((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ }
+
+ @Test
+ public void testDebugMessageCodesStringThrowableStringArray() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1", "str2");
+ Mockito.verify(mockLogger).debug((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ }
+
+ @Test
+ public void testIsDebugEnabled() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
+ assertFalse(PolicyLogger.isDebugEnabled());
+ assertTrue(PolicyLogger.isDebugEnabled());
+ }
+
+ @Test
+ public void testIsErrorEnabled() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Mockito.when(mockLogger.isErrorEnabled()).thenReturn(false).thenReturn(true);
+ assertFalse(PolicyLogger.isErrorEnabled());
+ assertTrue(PolicyLogger.isErrorEnabled());
+ }
+
+ @Test
+ public void testIsWarnEnabled() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Mockito.when(mockLogger.isWarnEnabled()).thenReturn(false).thenReturn(true);
+ assertFalse(PolicyLogger.isWarnEnabled());
+ assertTrue(PolicyLogger.isWarnEnabled());
+ }
+
+ @Test
+ public void testIsInfoEnabled1() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
+ assertFalse(PolicyLogger.isInfoEnabled1());
+ assertTrue(PolicyLogger.isInfoEnabled1());
+ }
+
+ @Test
+ public void testIsAuditEnabled() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
+ assertFalse(PolicyLogger.isAuditEnabled());
+ assertTrue(PolicyLogger.isAuditEnabled());
+ }
+
+ @Test
+ public void testIsInfoEnabled() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
+ assertFalse(PolicyLogger.isInfoEnabled());
+ assertTrue(PolicyLogger.isInfoEnabled());
+ }
+
+ @Test
+ public void testTraceStringString() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.trace("str1", "str2");
+ Mockito.verify(mockLogger).trace(MessageCodes.GENERAL_INFO, "str2");
+ }
+
+ @Test
+ public void testTraceObject() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ PolicyLogger.trace(1);
+ Mockito.verify(mockLogger).trace("1");
+ }
+
+ @Test
+ public void testRecordAuditEventStartAndEnd() {
+ PolicyLogger.recordAuditEventStart("eventId");
+ assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
+
+ PolicyLogger.recordAuditEventEnd("eventId", "rule");
+ assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
+ }
+
+ @Test
+ public void testRecordAuditEventStartAndEndUUID() {
+ UUID uuid = UUID.randomUUID();
+ PolicyLogger.recordAuditEventStart(uuid);;
+ assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
+
+ PolicyLogger.recordAuditEventEnd(uuid, "rule");
+ assertNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
+ }
+
+
+ @Test
+ public void testRecordAuditEventEndStringStringString() {
+ PolicyLogger.recordAuditEventStart("eventId");
+ assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
+
+ PolicyLogger.recordAuditEventEnd("eventId", "rule", "policyVersion");
+ assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
+ }
+
+ @Test
+ public void testRecordAuditEventEndUUIDStringString() {
+ UUID uuid = UUID.randomUUID();
+ PolicyLogger.recordAuditEventStart(uuid);;
+ assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
+
+ PolicyLogger.recordAuditEventEnd(uuid, "rule", "policyVersion");
+ assertNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
+ }
+
+
+ @Test
+ public void testCreatAuditEventTrackingRecordStringStringString() {
+ PolicyLogger.recordAuditEventStart("eventId");
+ assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
+
+ PolicyLogger.creatAuditEventTrackingRecord("eventId", "rule", "policyVersion");
+ assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
+ }
+
+ @Test
+ public void testCreatAuditEventTrackingRecordUUIDString() {
+ UUID uuid = UUID.randomUUID();
+ PolicyLogger.recordAuditEventStart(uuid);;
+ assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
+
+ PolicyLogger.creatAuditEventTrackingRecord(uuid, "rule");
+ assertNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
+ }
+
+ @Test
+ public void testRecordAuditEventStartToEnd() {
+ PolicyLogger.recordAuditEventStartToEnd("eventId", "rule", Instant.now(), Instant.now(), "policyVersion");
+ assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID));
+ }
+
+ @Test
+ public void testRecordMetricEventStringString() {
+ PolicyLogger.recordMetricEvent("eventId", "str1");
+ assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID));
+ }
+
+ @Test
+ public void testRecordMetricEventStringStringString() {
+ PolicyLogger.recordMetricEvent("eventId", "PolicyLoggerTest", "str1");
+ assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID));
+ }
+
+ @Test
+ public void testRecordMetricEventUUIDString() {
+ UUID uuid = UUID.randomUUID();
+ PolicyLogger.recordMetricEvent(uuid, "str1");
+ assertEquals(uuid.toString(), MDC.get(MDC_KEY_REQUEST_ID));
+ }
+
+ @Test
+ public void testRecordMetricEventString() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
+ PolicyLogger.recordMetricEvent("eventId");
+ Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(), Mockito.eq("eventId"));
+ }
+
+ @Test
+ public void testMetricsString() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
+ PolicyLogger.metrics("str1");
+ Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(), Mockito.eq("str1"));
+ }
+
+ @Test
+ public void testMetricsStringObject() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
+ PolicyLogger.metrics("PolicyLoggerTest", 1);
+ Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(), Mockito.eq("1"));
+ }
+
+ @Test
+ public void testMetricsObject() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
+ PolicyLogger.metrics(1);
+ Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(), Mockito.eq("1"));
+ }
+
+ @Test
+ public void testMetricsPrintln() {
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
+ PolicyLogger.metricsPrintln("str1");
+ Mockito.verify(mockLogger).info("str1");
+ }
+
+ @Test
+ public void testInitNullProperties() {
+ PolicyLogger.init(null);
+ }
+
+ @Test
+ public void testInit() {
+ Properties properties = new Properties();
+ properties.setProperty("override.logback.level.setup", "true");
+ properties.setProperty("metricsLogger.level", "OFF");
+ properties.setProperty("error.level", "OFF");
+ properties.setProperty("audit.level", "OFF");
+ properties.setProperty("timer.delay.time", "0");
+ properties.setProperty("check.interval", "0");
+ properties.setProperty("event.expired.time", "0");
+ properties.setProperty("concurrentHashMap.limit", "0");
+ properties.setProperty("stop.check.point", "0");
+ properties.setProperty("logger.property", "LOG4J");
+
+ PolicyLogger.init(properties);
+ }
+
+ @Test
+ public void testSetDebugLevelString() {
+ PolicyLogger.setOverrideLogbackLevel(true);
+ PolicyLogger.setDebugLevel("TRACE");
+ assertEquals(Level.TRACE, PolicyLogger.getDebugLevel());
+ }
+
+ @Test
+ public void testSetErrorLevelStringOff() {
+ PolicyLogger.setOverrideLogbackLevel(true);
+ PolicyLogger.setErrorLevel("OFF");
+ assertEquals(Level.OFF, PolicyLogger.getErrorLevel());
+ }
+
+ @Test
+ public void testSetErrorLevelStringOther() {
+ PolicyLogger.setOverrideLogbackLevel(true);
+ PolicyLogger.setErrorLevel("INFO");
+ assertEquals(Level.ERROR, PolicyLogger.getErrorLevel());
+ }
+
+ @Test
+ public void testSetMetricsLevelStringOff() {
+ PolicyLogger.setOverrideLogbackLevel(true);
+ PolicyLogger.setMetricsLevel("OFF");
+ assertEquals(Level.OFF, PolicyLogger.getMetricsLevel());
+ }
+
+ @Test
+ public void testSetMetricsLevelStringOther() {
+ PolicyLogger.setOverrideLogbackLevel(true);
+ PolicyLogger.setMetricsLevel("ERROR");
+ assertEquals(Level.INFO, PolicyLogger.getMetricsLevel());
+ }
+
+ @Test
+ public void testSetAuditLevelStringOff() {
+ PolicyLogger.setOverrideLogbackLevel(true);
+ PolicyLogger.setAuditLevel("OFF");
+ assertEquals(Level.OFF, PolicyLogger.getAuditLevel());
+ }
+
+ @Test
+ public void testSetAuditLevelStringOther() {
+ PolicyLogger.setOverrideLogbackLevel(true);
+ PolicyLogger.setAuditLevel("ERROR");
+ assertEquals(Level.INFO, PolicyLogger.getAuditLevel());
+ }
+
+ @Test
+ public void testSetAndIsOverrideLogbackLevel() {
+ PolicyLogger.setOverrideLogbackLevel(false);
+ assertFalse(PolicyLogger.isOverrideLogbackLevel());
+ PolicyLogger.setOverrideLogbackLevel(true);
+ assertTrue(PolicyLogger.isOverrideLogbackLevel());
+ }
+
+ @Test
+ public void testSetServerInfo() {
+ PolicyLogger.setServerInfo("serverHost", "serverPort");
+ assertEquals("serverHost:serverPort", MDC.get(SERVER_NAME));
+ }
+
+ private static void overrideStaticField(@SuppressWarnings("rawtypes") final Class clazz, final String fieldName, final Object newValue) {
+ try {
+ final Field field = clazz.getDeclaredField(fieldName);
+ field.setAccessible(true);
+
+ final Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+
+ field.set(null, newValue);
+ } catch (final Exception e) {
+ fail(e.toString());
+ }
+ }
+
+}