aboutsummaryrefslogtreecommitdiffstats
path: root/common-logging/src/test/java/org/onap
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-07-05 13:03:06 -0400
committerJim Hahn <jrh3@att.com>2019-07-05 17:36:12 -0400
commit02ba37e23bebc5fc8831feaa4ce073295c3c93d8 (patch)
tree4b4b99ec0d2d429fe2d857e3992d5e893615f6b1 /common-logging/src/test/java/org/onap
parent53f9550501ca1854318c1f552b0aba2e255b6748 (diff)
Fix sonar issues in policy ONAP logging
Sonar fixes, other than code coverage. These changes are disruptive and will likely cause breakage in a number of policy repos. Renamed constants. Moved constants/factories from interfaces to classes. Also fixed remaining checkstyle issues, which was equally disruptive, as it required renaming of methods and classes. Split out Onap config properties from EELF config properties, in case changes are made in the future such that Onap properties can no longer subclass from EELF properties (e.g., if EELF properties are converted from a interface to a utility class with a private constructor). Attempted to eliminate some duplicate blocks of code by refactoring out common methods. Change-Id: Ie038d2d4ed553037a9af3f0ddf31baf2b3628fa3 Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'common-logging/src/test/java/org/onap')
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPdpMdcInfoTest.java (renamed from common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfoTest.java)19
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java22
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java28
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java121
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java71
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java32
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java96
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java25
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/util/TestUtils.java77
9 files changed, 208 insertions, 283 deletions
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfoTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPdpMdcInfoTest.java
index 3dd62e69..96030962 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfoTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPdpMdcInfoTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
* 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.
@@ -23,19 +23,20 @@ package org.onap.policy.common.logging.eelf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import com.att.eelf.configuration.Configuration;
import org.junit.Test;
-public class DroolsPDPMDCInfoTest {
+public class DroolsPdpMdcInfoTest {
/**
- * Test method for {@link org.onap.policy.common.logging.eelf.DroolsPDPMDCInfo#getMDCInfo()}.
+ * Test method for {@link org.onap.policy.common.logging.eelf.DroolsPdpMdcInfo#getMdcInfo()}.
*/
@Test
- public void testGetMDCInfo() {
- DroolsPDPMDCInfo di = new DroolsPDPMDCInfo();
+ public void testGetMdcInfo() {
+ DroolsPdpMdcInfo di = new DroolsPdpMdcInfo();
- assertNotNull(di.getMDCInfo());
- assertEquals("Policy.droolsPdp", di.getMDCInfo().get(Configuration.MDC_SERVICE_NAME));
+ assertNotNull(di.getMdcInfo());
+ assertEquals("Policy.droolsPdp", di.getMdcInfo().get(Configuration.MDC_SERVICE_NAME));
}
}
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java
index f7aa733a..6fe81d27 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
* 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.
@@ -42,7 +42,7 @@ public class EventDataTest {
EventData eventData = new EventData();
assertNull(eventData.getEndTime());
- assertNull(eventData.getRequestID());
+ assertNull(eventData.getRequestId());
assertNull(eventData.getStartTime());
}
@@ -53,24 +53,24 @@ public class EventDataTest {
public void testEventDataStringInstantInstant() {
EventData eventData = new EventData("myreq", istart, iend);
- assertEquals("myreq", eventData.getRequestID());
+ assertEquals("myreq", eventData.getRequestId());
assertEquals(istart, eventData.getStartTime());
assertEquals(iend, eventData.getEndTime());
}
/**
- * Test method for {@link EventData#getRequestID()} and {@link EventData#setRequestID(String)}.
+ * Test method for {@link EventData#getRequestId()} and {@link EventData#setRequestId(String)}.
*/
@Test
public void testGetSetRequestId() {
EventData eventData = new EventData();
- assertNull(eventData.getRequestID());
+ assertNull(eventData.getRequestId());
- eventData.setRequestID("abc");
- assertEquals("abc", eventData.getRequestID());
+ eventData.setRequestId("abc");
+ assertEquals("abc", eventData.getRequestId());
- eventData.setRequestID("def");
- assertEquals("def", eventData.getRequestID());
+ eventData.setRequestId("def");
+ assertEquals("def", eventData.getRequestId());
}
/**
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java
index 7dc8fddc..e6024682 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
* 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.
@@ -55,16 +55,16 @@ public class EventTrackInfoTest {
}
/**
- * Test method for {@link EventTrackInfo#getEventDataByRequestID(String)}.
+ * Test method for {@link EventTrackInfo#getEventDataByRequestId(String)}.
*/
@Test
- public void testGetEventDataByRequestID() {
+ public void testGetEventDataByRequestId() {
info.storeEventData(data1);
info.storeEventData(data2);
- assertTrue(data1 == info.getEventDataByRequestID("abc"));
- assertTrue(data2 == info.getEventDataByRequestID("def"));
- assertNull(info.getEventDataByRequestID("hello"));
+ assertTrue(data1 == info.getEventDataByRequestId("abc"));
+ assertTrue(data2 == info.getEventDataByRequestId("def"));
+ assertNull(info.getEventDataByRequestId("hello"));
}
/**
@@ -86,14 +86,14 @@ public class EventTrackInfoTest {
assertEquals(2, info.getEventInfo().size());
// look-up by request id
- assertTrue(data1 == info.getEventDataByRequestID("abc"));
- assertTrue(data2 == info.getEventDataByRequestID("def"));
+ assertTrue(data1 == info.getEventDataByRequestId("abc"));
+ assertTrue(data2 == info.getEventDataByRequestId("def"));
// doesn't replace existing value
info.storeEventData(new EventData("abc", iend, istart));
assertEquals(2, info.getEventInfo().size());
- assertTrue(data1 == info.getEventDataByRequestID("abc"));
- assertTrue(data2 == info.getEventDataByRequestID("def"));
+ assertTrue(data1 == info.getEventDataByRequestId("abc"));
+ assertTrue(data2 == info.getEventDataByRequestId("def"));
}
/**
@@ -110,8 +110,8 @@ public class EventTrackInfoTest {
assertEquals(1, info.getEventInfo().size());
// look-up by request id
- assertNull(info.getEventDataByRequestID("abc"));
- assertTrue(data2 == info.getEventDataByRequestID("def"));
+ assertNull(info.getEventDataByRequestId("abc"));
+ assertTrue(data2 == info.getEventDataByRequestId("def"));
}
/**
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 8d6b6d68..6af3632a 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
@@ -3,13 +3,14 @@
* ONAP-Logging
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* 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.
@@ -34,12 +35,11 @@ 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.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 static org.onap.policy.common.logging.util.TestUtils.overrideStaticField;
+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;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.SERVER_NAME;
+import static org.onap.policy.common.logging.eelf.OnapConfigProperties.STATUS_CODE;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFLogger.Level;
@@ -51,6 +51,7 @@ import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
+import org.powermock.reflect.Whitebox;
import org.slf4j.MDC;
public class PolicyLoggerTest {
@@ -105,8 +106,8 @@ public class PolicyLoggerTest {
}
@Test
- public void testPostMDCInfoForEventString() {
- PolicyLogger.postMDCInfoForEvent("transactionId");
+ public void testPostMdcInfoForEventString() {
+ PolicyLogger.postMdcInfoForEvent("transactionId");
assertEquals("", MDC.get(MDC_REMOTE_HOST));
assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
@@ -121,12 +122,12 @@ public class PolicyLoggerTest {
}
@Test
- public void testPostMDCInfoForEventStringDrools() {
+ public void testPostMdcInfoForEventStringDrools() {
Properties properties = new Properties();
properties.setProperty("policy.component", "DROOLS");
PolicyLogger.init(properties);
- PolicyLogger.postMDCInfoForEvent("transactionId");
+ PolicyLogger.postMdcInfoForEvent("transactionId");
assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
assertEquals("Policy.droolsPdp", MDC.get(MDC_SERVICE_NAME));
@@ -140,8 +141,8 @@ public class PolicyLoggerTest {
}
@Test
- public void testPostMDCInfoForEventObject() {
- PolicyLogger.postMDCInfoForEvent(1);
+ public void testPostMdcInfoForEventObject() {
+ PolicyLogger.postMdcInfoForEvent(1);
assertEquals("", MDC.get(MDC_REMOTE_HOST));
assertEquals("1", MDC.get(MDC_KEY_REQUEST_ID));
@@ -156,8 +157,8 @@ public class PolicyLoggerTest {
}
@Test
- public void testPostMDCInfoForTriggeredRule() {
- PolicyLogger.postMDCInfoForTriggeredRule("transactionId");
+ public void testPostMdcInfoForTriggeredRule() {
+ PolicyLogger.postMdcInfoForTriggeredRule("transactionId");
assertEquals("", MDC.get(MDC_REMOTE_HOST));
assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
@@ -171,8 +172,8 @@ public class PolicyLoggerTest {
}
@Test
- public void testPostMDCUUIDForTriggeredRule() {
- PolicyLogger.postMDCUUIDForTriggeredRule(1);
+ public void testPostMdcUuidForTriggeredRule() {
+ PolicyLogger.postMdcUuidForTriggeredRule(1);
assertEquals("", MDC.get(MDC_REMOTE_HOST));
assertEquals("1", MDC.get(MDC_KEY_REQUEST_ID));
@@ -188,7 +189,7 @@ public class PolicyLoggerTest {
@Test
public void testInfoMessageCodesStringStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
Mockito.verify(mockLogger).info(MessageCodes.ERROR_DATA_ISSUE, "str2");
}
@@ -196,7 +197,7 @@ public class PolicyLoggerTest {
@Test
public void testInfoStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info("str1", "str2");
Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "str2");
}
@@ -204,7 +205,7 @@ public class PolicyLoggerTest {
@Test
public void testInfoObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info("str1");
Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "str1");
}
@@ -212,7 +213,7 @@ public class PolicyLoggerTest {
@Test
public void testInfoMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(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"));
@@ -221,7 +222,7 @@ public class PolicyLoggerTest {
@Test
public void testInfoMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
"str2");
Mockito.verify(mockLogger).info((MessageCodes) Mockito.any(),
@@ -231,7 +232,7 @@ public class PolicyLoggerTest {
@Test
public void testWarnMessageCodesStringStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "str1");
Mockito.verify(mockLogger).warn(MessageCodes.ERROR_DATA_ISSUE);
}
@@ -239,7 +240,7 @@ public class PolicyLoggerTest {
@Test
public void testWarnStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn("str1", "str2");
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_INFO, "str2");
}
@@ -247,7 +248,7 @@ public class PolicyLoggerTest {
@Test
public void testWarnObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn(1);
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_WARNING, "1");
}
@@ -255,7 +256,7 @@ public class PolicyLoggerTest {
@Test
public void testWarnMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(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"));
@@ -264,7 +265,7 @@ public class PolicyLoggerTest {
@Test
public void testWarnMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
"str2");
Mockito.verify(mockLogger).warn((MessageCodes) Mockito.any(),
@@ -274,7 +275,7 @@ public class PolicyLoggerTest {
@Test
public void testWarnString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn("str1");
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_WARNING, "str1");
}
@@ -282,7 +283,7 @@ public class PolicyLoggerTest {
@Test
public void testErrorStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error("str1", "str2");
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str2");
assertEquals("POLICY-515E", MDC.get("ErrorCode"));
@@ -293,7 +294,7 @@ public class PolicyLoggerTest {
@Test
public void testErrorString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error("str1");
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str1");
assertEquals("ERROR", MDC.get("ErrorCategory"));
@@ -305,7 +306,7 @@ public class PolicyLoggerTest {
@Test
public void testErrorObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error(1);
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "1");
assertEquals("ERROR", MDC.get("ErrorCategory"));
@@ -317,7 +318,7 @@ public class PolicyLoggerTest {
@Test
public void testErrorMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Whitebox.setInternalState(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"));
@@ -326,7 +327,7 @@ public class PolicyLoggerTest {
@Test
public void testErrorMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
"str2");
Mockito.verify(mockLogger).error((MessageCodes) Mockito.any(),
@@ -336,7 +337,7 @@ public class PolicyLoggerTest {
@Test
public void testErrorMessageCodesStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
Mockito.verify(mockLogger).error(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
}
@@ -344,7 +345,7 @@ public class PolicyLoggerTest {
@Test
public void testDebugMessageCodesStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
Mockito.verify(mockLogger).debug(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
}
@@ -352,7 +353,7 @@ public class PolicyLoggerTest {
@Test
public void testDebugStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug("str1", "str2");
Mockito.verify(mockLogger).debug(MessageCodes.GENERAL_INFO, "str2");
}
@@ -360,7 +361,7 @@ public class PolicyLoggerTest {
@Test
public void testDebugString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug("str1");
Mockito.verify(mockLogger).debug("str1");
}
@@ -368,7 +369,7 @@ public class PolicyLoggerTest {
@Test
public void testDebugObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug(1);
Mockito.verify(mockLogger).debug("1");
}
@@ -376,7 +377,7 @@ public class PolicyLoggerTest {
@Test
public void testAuditStringObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "auditLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "auditLogger", mockLogger);
PolicyLogger.audit("PolicyLoggerTest", 1);
assertEquals("PolicyLoggerTest", MDC.get("ClassName"));
assertEquals("COMPLETE", MDC.get("StatusCode"));
@@ -386,7 +387,7 @@ public class PolicyLoggerTest {
@Test
public void testAuditObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "auditLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "auditLogger", mockLogger);
PolicyLogger.audit(1);
assertEquals("", MDC.get("ClassName"));
assertEquals("COMPLETE", MDC.get("StatusCode"));
@@ -396,7 +397,7 @@ public class PolicyLoggerTest {
@Test
public void testDebugMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(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"));
@@ -405,7 +406,7 @@ public class PolicyLoggerTest {
@Test
public void testDebugMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
"str2");
Mockito.verify(mockLogger).debug((MessageCodes) Mockito.any(),
@@ -415,7 +416,7 @@ public class PolicyLoggerTest {
@Test
public void testIsDebugEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
assertFalse(PolicyLogger.isDebugEnabled());
assertTrue(PolicyLogger.isDebugEnabled());
@@ -424,7 +425,7 @@ public class PolicyLoggerTest {
@Test
public void testIsErrorEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
Mockito.when(mockLogger.isErrorEnabled()).thenReturn(false).thenReturn(true);
assertFalse(PolicyLogger.isErrorEnabled());
assertTrue(PolicyLogger.isErrorEnabled());
@@ -433,7 +434,7 @@ public class PolicyLoggerTest {
@Test
public void testIsWarnEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isWarnEnabled()).thenReturn(false).thenReturn(true);
assertFalse(PolicyLogger.isWarnEnabled());
assertTrue(PolicyLogger.isWarnEnabled());
@@ -442,7 +443,7 @@ public class PolicyLoggerTest {
@Test
public void testIsInfoEnabled1() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
assertFalse(PolicyLogger.isInfoEnabled1());
assertTrue(PolicyLogger.isInfoEnabled1());
@@ -451,7 +452,7 @@ public class PolicyLoggerTest {
@Test
public void testIsAuditEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
assertFalse(PolicyLogger.isAuditEnabled());
assertTrue(PolicyLogger.isAuditEnabled());
@@ -460,7 +461,7 @@ public class PolicyLoggerTest {
@Test
public void testIsInfoEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
assertFalse(PolicyLogger.isInfoEnabled());
assertTrue(PolicyLogger.isInfoEnabled());
@@ -469,7 +470,7 @@ public class PolicyLoggerTest {
@Test
public void testTraceStringString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.trace("str1", "str2");
Mockito.verify(mockLogger).trace(MessageCodes.GENERAL_INFO, "str2");
}
@@ -477,7 +478,7 @@ public class PolicyLoggerTest {
@Test
public void testTraceObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.trace(1);
Mockito.verify(mockLogger).trace("1");
}
@@ -492,7 +493,7 @@ public class PolicyLoggerTest {
}
@Test
- public void testRecordAuditEventStartAndEndUUID() {
+ public void testRecordAuditEventStartAndEndUuid() {
UUID uuid = UUID.randomUUID();
PolicyLogger.recordAuditEventStart(uuid);;
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
@@ -512,7 +513,7 @@ public class PolicyLoggerTest {
}
@Test
- public void testRecordAuditEventEndUUIDStringString() {
+ public void testRecordAuditEventEndUuidStringString() {
UUID uuid = UUID.randomUUID();
PolicyLogger.recordAuditEventStart(uuid);;
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
@@ -532,7 +533,7 @@ public class PolicyLoggerTest {
}
@Test
- public void testCreatAuditEventTrackingRecordUUIDString() {
+ public void testCreatAuditEventTrackingRecordUuidString() {
UUID uuid = UUID.randomUUID();
PolicyLogger.recordAuditEventStart(uuid);;
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
@@ -560,7 +561,7 @@ public class PolicyLoggerTest {
}
@Test
- public void testRecordMetricEventUUIDString() {
+ public void testRecordMetricEventUuidString() {
UUID uuid = UUID.randomUUID();
PolicyLogger.recordMetricEvent(uuid, "str1");
assertEquals(uuid.toString(), MDC.get(MDC_KEY_REQUEST_ID));
@@ -569,7 +570,7 @@ public class PolicyLoggerTest {
@Test
public void testRecordMetricEventString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.recordMetricEvent("eventId");
Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
Mockito.eq("eventId"));
@@ -578,7 +579,7 @@ public class PolicyLoggerTest {
@Test
public void testMetricsString() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics("str1");
Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
Mockito.eq("str1"));
@@ -587,7 +588,7 @@ public class PolicyLoggerTest {
@Test
public void testMetricsStringObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics("PolicyLoggerTest", 1);
Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
Mockito.eq("1"));
@@ -596,7 +597,7 @@ public class PolicyLoggerTest {
@Test
public void testMetricsObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics(1);
Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
Mockito.eq("1"));
@@ -605,7 +606,7 @@ public class PolicyLoggerTest {
@Test
public void testMetricsPrintln() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metricsPrintln("str1");
Mockito.verify(mockLogger).info("str1");
}
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 a7e835ce..d3c09ee6 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,13 +3,14 @@
* ONAP-Logging
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* 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.
@@ -26,16 +27,14 @@ 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.onap.policy.common.logging.util.TestUtils.overrideStaticField;
import com.att.eelf.configuration.EELFLogger;
-
import java.util.UUID;
-
import org.junit.Test;
import org.mockito.Mockito;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
+import org.powermock.reflect.Whitebox;
import org.slf4j.MDC;
public class EelfLoggerTest {
@@ -92,7 +91,7 @@ public class EelfLoggerTest {
@Test
public void testDebugObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.debug("message");
Mockito.verify(mockLogger).debug(MessageCodes.GENERAL_INFO, "message");
}
@@ -100,7 +99,7 @@ public class EelfLoggerTest {
@Test
public void testErrorObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error("message");
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "message");
}
@@ -108,7 +107,7 @@ public class EelfLoggerTest {
@Test
public void testInfoObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.info("message");
Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "message");
}
@@ -116,7 +115,7 @@ public class EelfLoggerTest {
@Test
public void testWarnObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn("message");
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_INFO, "message");
}
@@ -124,7 +123,7 @@ public class EelfLoggerTest {
@Test
public void testTraceObject() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.trace("message");
Mockito.verify(mockLogger).trace(MessageCodes.GENERAL_INFO, "message");
}
@@ -132,7 +131,7 @@ public class EelfLoggerTest {
@Test
public void testIsDebugEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
assertFalse(eelfLogger.isDebugEnabled());
assertTrue(eelfLogger.isDebugEnabled());
@@ -142,7 +141,7 @@ public class EelfLoggerTest {
@Test
public void testIsInfoEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
assertFalse(eelfLogger.isInfoEnabled());
assertTrue(eelfLogger.isInfoEnabled());
@@ -151,7 +150,7 @@ public class EelfLoggerTest {
@Test
public void testIsWarnEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isWarnEnabled()).thenReturn(false).thenReturn(true);
assertFalse(eelfLogger.isWarnEnabled());
assertTrue(eelfLogger.isWarnEnabled());
@@ -160,7 +159,7 @@ public class EelfLoggerTest {
@Test
public void testIsErrorEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
Mockito.when(mockLogger.isErrorEnabled()).thenReturn(false).thenReturn(true);
assertFalse(eelfLogger.isErrorEnabled());
assertTrue(eelfLogger.isErrorEnabled());
@@ -183,7 +182,7 @@ public class EelfLoggerTest {
@Test
public void testIsTraceEnabled() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
assertFalse(eelfLogger.isTraceEnabled());
assertTrue(eelfLogger.isTraceEnabled());
@@ -199,7 +198,7 @@ public class EelfLoggerTest {
@Test
public void testDebugObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.debug("message", new NullPointerException());
Mockito.verify(mockLogger).debug((MessageCodes) Mockito.any(),
Mockito.startsWith("message:java.lang.NullPointerException"));
@@ -208,7 +207,7 @@ public class EelfLoggerTest {
@Test
public void testErrorObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error("message", new NullPointerException());
Mockito.verify(mockLogger).error((MessageCodes) Mockito.any(),
Mockito.startsWith("message:java.lang.NullPointerException"));
@@ -218,7 +217,7 @@ public class EelfLoggerTest {
@Test
public void testInfoObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.info("message", new NullPointerException());
Mockito.verify(mockLogger).info((MessageCodes) Mockito.any(),
Mockito.startsWith("message:java.lang.NullPointerException"));
@@ -227,7 +226,7 @@ public class EelfLoggerTest {
@Test
public void testWarnObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn("message", new NullPointerException());
Mockito.verify(mockLogger).warn((MessageCodes) Mockito.any(),
Mockito.startsWith("message:java.lang.NullPointerException"));
@@ -236,7 +235,7 @@ public class EelfLoggerTest {
@Test
public void testTraceObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.trace("message", new NullPointerException());
Mockito.verify(mockLogger).trace("message");
}
@@ -244,7 +243,7 @@ public class EelfLoggerTest {
@Test
public void testAuditObjectThrowable() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "auditLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "auditLogger", mockLogger);
eelfLogger.audit("message", new NullPointerException());
Mockito.verify(mockLogger).info("message");
}
@@ -256,7 +255,7 @@ public class EelfLoggerTest {
}
@Test
- public void testRecordAuditEventStartUUID() {
+ public void testRecordAuditEventStartUuid() {
UUID uuid = UUID.randomUUID();
eelfLogger.recordAuditEventStart(uuid);
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
@@ -272,7 +271,7 @@ public class EelfLoggerTest {
}
@Test
- public void testRecordAuditEventEndUUIDStringString() {
+ public void testRecordAuditEventEndUuidStringString() {
UUID uuid = UUID.randomUUID();
eelfLogger.recordAuditEventStart(uuid);;
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
@@ -291,7 +290,7 @@ public class EelfLoggerTest {
}
@Test
- public void testRecordAuditEventEndUUIDString() {
+ public void testRecordAuditEventEndUuidString() {
UUID uuid = UUID.randomUUID();
eelfLogger.recordAuditEventStart(uuid);;
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
@@ -307,7 +306,7 @@ public class EelfLoggerTest {
}
@Test
- public void testRecordMetricEventUUIDString() {
+ public void testRecordMetricEventUuidString() {
UUID uuid = UUID.randomUUID();
eelfLogger.recordMetricEvent(uuid, "str2");
assertEquals(uuid.toString(), MDC.get(MDC_KEY_REQUEST_ID));
@@ -316,7 +315,7 @@ public class EelfLoggerTest {
@Test
public void testMetrics() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "metricsLogger", mockLogger);
eelfLogger.metrics(1);
Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
Mockito.eq("1"));
@@ -325,7 +324,7 @@ public class EelfLoggerTest {
@Test
public void testErrorMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error(MessageCodes.GENERAL_ERROR, new NullPointerException(), "str1", "str2");
Mockito.verify(mockLogger).error((MessageCodes) Mockito.any(),
Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
@@ -334,22 +333,22 @@ public class EelfLoggerTest {
@Test
public void testErrorMessageCodesStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error(MessageCodes.GENERAL_ERROR, "str1", "str2");
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str1", "str2");
}
@Test
- public void testPostMDCInfoForEventString() {
- eelfLogger.postMDCInfoForEvent("transactionId");
+ public void testPostMdcInfoForEventString() {
+ eelfLogger.postMdcInfoForEvent("transactionId");
assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
}
@Test
public void testWarnMessageCodesStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn(MessageCodes.GENERAL_ERROR, "str1", "str2");
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_ERROR, "str1", "str2");
}
@@ -357,7 +356,7 @@ public class EelfLoggerTest {
@Test
public void testWarnMessageCodesThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
+ Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn(MessageCodes.GENERAL_ERROR, new NullPointerException(), "str1", "str2");
Mockito.verify(mockLogger).warn((MessageCodes) Mockito.any(),
Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
@@ -365,14 +364,14 @@ public class EelfLoggerTest {
}
@Test
- public void testPostMDCInfoForTriggeredRule() {
- eelfLogger.postMDCInfoForTriggeredRule("transactionId");
+ public void testPostMdcInfoForTriggeredRule() {
+ eelfLogger.postMdcInfoForTriggeredRule("transactionId");
assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
}
@Test
- public void testPostMDCInfoForEventObject() {
- eelfLogger.postMDCInfoForEvent(1);
+ public void testPostMDdcInfoForEventObject() {
+ eelfLogger.postMdcInfoForEvent(1);
assertEquals("1", MDC.get(MDC_KEY_REQUEST_ID));
}
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java
index 7d6088eb..a74dd94d 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java
@@ -3,13 +3,14 @@
* ONAP-Logging
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* 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.
@@ -22,20 +23,19 @@ package org.onap.policy.common.logging.flexlogger;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertSame;
-import static org.onap.policy.common.logging.util.TestUtils.overrideStaticField;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
-
import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger.PropertiesCallBack;
+import org.powermock.reflect.Whitebox;
public class FlexLoggerTest {
@Test
public void testGetLoggerClassOfQEelf() {
- overrideStaticField(FlexLogger.class, "loggerType", LoggerType.EELF);
+ Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger((Class<?>) null);
assertSame(logger, FlexLogger.getLogger((Class<?>) null));
assertNotEquals(logger, FlexLogger.getLogger(String.class));
@@ -43,77 +43,77 @@ public class FlexLoggerTest {
@Test
public void testGetLoggerClassOfQLog4j() {
- overrideStaticField(FlexLogger.class, "loggerType", LoggerType.LOG4J);
+ Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.LOG4J);
Logger logger = FlexLogger.getLogger(this.getClass());
assertSame(logger, FlexLogger.getLogger(this.getClass()));
}
@Test
public void testGetLoggerClassOfQSystemOut() {
- overrideStaticField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
+ Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger(this.getClass());
assertSame(logger, FlexLogger.getLogger(this.getClass()));
}
@Test
public void testGetLoggerStringEelf() {
- overrideStaticField(FlexLogger.class, "loggerType", LoggerType.EELF);
+ Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger("str1");
assertSame(logger, FlexLogger.getLogger("str1"));
}
@Test
public void testGetLoggerStringLog4j() {
- overrideStaticField(FlexLogger.class, "loggerType", LoggerType.LOG4J);
+ Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.LOG4J);
Logger logger = FlexLogger.getLogger("str1");
assertSame(logger, FlexLogger.getLogger("str1"));
}
@Test
public void testGetLoggerStringSystemOut() {
- overrideStaticField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
+ Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger("str1");
assertSame(logger, FlexLogger.getLogger("str1"));
}
@Test
public void testGetLoggerClassOfQBooleanEelf() {
- overrideStaticField(FlexLogger.class, "loggerType", LoggerType.EELF);
+ Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger(this.getClass(), true);
assertSame(logger, FlexLogger.getLogger(this.getClass(), true));
}
@Test
public void testGetLoggerClassOfQBooleanLog4j() {
- overrideStaticField(FlexLogger.class, "loggerType", LoggerType.LOG4J);
+ Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.LOG4J);
Logger logger = FlexLogger.getLogger(this.getClass(), true);
assertSame(logger, FlexLogger.getLogger(this.getClass(), true));
}
@Test
public void testGetLoggerClassOfQBooleanSystemOut() {
- overrideStaticField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
+ Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger(this.getClass(), true);
assertSame(logger, FlexLogger.getLogger(this.getClass(), true));
}
@Test
public void testGetLoggerStringBooleanEelf() {
- overrideStaticField(FlexLogger.class, "loggerType", LoggerType.EELF);
+ Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger("str1", true);
assertSame(logger, FlexLogger.getLogger("str1", true));
}
@Test
public void testGetLoggerStringBooleanLog4j() {
- overrideStaticField(FlexLogger.class, "loggerType", LoggerType.LOG4J);
+ Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.LOG4J);
Logger logger = FlexLogger.getLogger("str1", true);
assertSame(logger, FlexLogger.getLogger("str1", true));
}
@Test
public void testGetLoggerStringBooleanSystemOut() {
- overrideStaticField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
+ Whitebox.setInternalState(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger("str1", true);
assertSame(logger, FlexLogger.getLogger("str1", true));
}
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java
index 7f2964c2..99c343c0 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java
@@ -3,13 +3,14 @@
* ONAP-Logging
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* 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.
@@ -27,13 +28,12 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.UUID;
-
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.mockito.Mockito;
import org.onap.policy.common.logging.eelf.MessageCodes;
-import org.onap.policy.common.logging.util.TestUtils;
+import org.powermock.reflect.Whitebox;
public class Logger4JTest {
@@ -53,7 +53,7 @@ public class Logger4JTest {
@Test
public void testDebugObject() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
Mockito.when(logger.isDebugEnabled()).thenReturn(true);
logger4J.setTransId("transactionId");
logger4J.debug("message");
@@ -63,7 +63,7 @@ public class Logger4JTest {
@Test
public void testErrorObject() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.setTransId("transactionId");
logger4J.error("message");
Mockito.verify(logger).error("transactionId|Logger4JTest|message");
@@ -72,7 +72,7 @@ public class Logger4JTest {
@Test
public void testInfoObject() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.setTransId("transactionId");
logger4J.info("message");
Mockito.verify(logger).info("transactionId|Logger4JTest|message");
@@ -81,7 +81,7 @@ public class Logger4JTest {
@Test
public void testWarnObject() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.setTransId("transactionId");
logger4J.warn("message");
Mockito.verify(logger).warn("transactionId|Logger4JTest|message");
@@ -90,7 +90,7 @@ public class Logger4JTest {
@Test
public void testTraceObject() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.setTransId("transactionId");
logger4J.trace("message");
Mockito.verify(logger).trace("transactionId|Logger4JTest|message");
@@ -99,7 +99,7 @@ public class Logger4JTest {
@Test
public void testIsDebugEnabled() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
Mockito.when(logger.isDebugEnabled()).thenReturn(true).thenReturn(false);
assertTrue(logger4J.isDebugEnabled());
assertFalse(logger4J.isDebugEnabled());
@@ -108,7 +108,7 @@ public class Logger4JTest {
@Test
public void testIsErrorEnabled() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
Mockito.when(logger.isEnabledFor(Level.ERROR)).thenReturn(true).thenReturn(false);
assertTrue(logger4J.isErrorEnabled());
assertFalse(logger4J.isErrorEnabled());
@@ -117,7 +117,7 @@ public class Logger4JTest {
@Test
public void testIsInfoEnabled() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
Mockito.when(logger.isInfoEnabled()).thenReturn(true).thenReturn(false);
assertTrue(logger4J.isInfoEnabled());
assertFalse(logger4J.isInfoEnabled());
@@ -126,7 +126,7 @@ public class Logger4JTest {
@Test
public void testIsWarnEnabled() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
Mockito.when(logger.isEnabledFor(Level.WARN)).thenReturn(true).thenReturn(false);
assertTrue(logger4J.isWarnEnabled());
assertFalse(logger4J.isWarnEnabled());
@@ -135,7 +135,7 @@ public class Logger4JTest {
@Test
public void testAuditObject() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.audit("str1");
Mockito.verify(logger).info("Logger4JTest|str1");
}
@@ -143,15 +143,15 @@ public class Logger4JTest {
@Test
public void testRecordAuditEventStartString() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.recordAuditEventEnd("eventId", "rule");
Mockito.verify(logger).info("Logger4JTest|eventId:rule");
}
@Test
- public void testRecordAuditEventStartUUID() {
+ public void testRecordAuditEventStartUuid() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
UUID uuid = UUID.randomUUID();
logger4J.recordAuditEventStart(uuid);
Mockito.verify(logger).info("Logger4JTest|recordAuditEventStart with eventId " + uuid.toString());
@@ -160,15 +160,15 @@ public class Logger4JTest {
@Test
public void testRecordAuditEventEndStringStringString() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.recordAuditEventEnd("eventId", "rule", "policyVersion");
Mockito.verify(logger).info("Logger4JTest|eventId:rule");
}
@Test
- public void testRecordAuditEventEndUUIDStringString() {
+ public void testRecordAuditEventEndUuidStringString() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
UUID uuid = UUID.randomUUID();
logger4J.recordAuditEventEnd(uuid, "rule", "policyVersion");
Mockito.verify(logger).info("Logger4JTest|" + uuid.toString() + ":rule");
@@ -177,15 +177,15 @@ public class Logger4JTest {
@Test
public void testRecordAuditEventEndStringString() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.recordAuditEventEnd("eventId", "rule");
Mockito.verify(logger).info("Logger4JTest|eventId:rule");
}
@Test
- public void testRecordAuditEventEndUUIDString() {
+ public void testRecordAuditEventEndUuidString() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
UUID uuid = UUID.randomUUID();
logger4J.recordAuditEventEnd(uuid, "rule");
Mockito.verify(logger).info("Logger4JTest|" + uuid.toString() + ":rule");
@@ -194,15 +194,15 @@ public class Logger4JTest {
@Test
public void testRecordMetricEventStringString() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.recordMetricEvent("eventId", "str1");
Mockito.verify(logger).info("Logger4JTest|eventId:str1");
}
@Test
- public void testRecordMetricEventUUIDString() {
+ public void testRecordMetricEventUuidString() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
UUID uuid = UUID.randomUUID();
logger4J.recordMetricEvent(uuid, "str1");
Mockito.verify(logger).info("Logger4JTest|" + uuid.toString() + ":str1");
@@ -211,7 +211,7 @@ public class Logger4JTest {
@Test
public void testMetrics() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.metrics("str1");
Mockito.verify(logger).info("str1");
}
@@ -219,7 +219,7 @@ public class Logger4JTest {
@Test
public void testErrorMessageCodesThrowableStringArray() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.setTransId("transactionId");
logger4J.error(MessageCodes.GENERAL_ERROR, new NullPointerException(), "str1", "str2");
Mockito.verify(logger)
@@ -229,7 +229,7 @@ public class Logger4JTest {
@Test
public void testErrorMessageCodesStringArray() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.setTransId("transactionId");
logger4J.error(MessageCodes.GENERAL_ERROR, "str1", "str2");
Mockito.verify(logger)
@@ -237,14 +237,14 @@ public class Logger4JTest {
}
@Test
- public void testPostMDCInfoForEventString() {
- String returnedTransactionId = logger4J.postMDCInfoForEvent("transactionId");
+ public void testPostMdcInfoForEventString() {
+ String returnedTransactionId = logger4J.postMdcInfoForEvent("transactionId");
assertEquals("transactionId", returnedTransactionId);
}
@Test
- public void testPostMDCInfoForEventEmptyString() {
- String returnedTransactionId = logger4J.postMDCInfoForEvent("");
+ public void testPostMdcInfoForEventEmptyString() {
+ String returnedTransactionId = logger4J.postMdcInfoForEvent("");
assertNotNull("", returnedTransactionId);
assertNotEquals("", returnedTransactionId);
}
@@ -252,7 +252,7 @@ public class Logger4JTest {
@Test
public void testWarnMessageCodesStringArray() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.warn(MessageCodes.GENERAL_ERROR, "str1", "str2");
Mockito.verify(logger).warn("Logger4JTest|MessageCodes:" + MessageCodes.GENERAL_ERROR + "[str1, str2]");
}
@@ -260,7 +260,7 @@ public class Logger4JTest {
@Test
public void testWarnMessageCodesThrowableStringArray() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.setTransId("transactionId");
logger4J.warn(MessageCodes.GENERAL_ERROR, new NullPointerException(), "str1", "str2");
Mockito.verify(logger).warn("Logger4JTest|MessageCodes:" + MessageCodes.GENERAL_ERROR + "[str1, str2]");
@@ -269,7 +269,7 @@ public class Logger4JTest {
@Test
public void testDebugObjectThrowable() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.setTransId("transactionId");
Exception exception = new NullPointerException();
logger4J.debug("message", exception);
@@ -279,7 +279,7 @@ public class Logger4JTest {
@Test
public void testErrorObjectThrowable() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.setTransId("transactionId");
Exception exception = new NullPointerException();
logger4J.error("message", exception);
@@ -289,7 +289,7 @@ public class Logger4JTest {
@Test
public void testInfoObjectThrowable() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.setTransId("transactionId");
Exception exception = new NullPointerException();
logger4J.info("message", exception);
@@ -299,7 +299,7 @@ public class Logger4JTest {
@Test
public void testWarnObjectThrowable() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
Exception exception = new NullPointerException();
logger4J.warn("message", exception);
Mockito.verify(logger).warn("message", exception);
@@ -308,7 +308,7 @@ public class Logger4JTest {
@Test
public void testTraceObjectThrowable() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
Exception exception = new NullPointerException();
logger4J.trace("message", exception);
Mockito.verify(logger).trace("message", exception);
@@ -317,7 +317,7 @@ public class Logger4JTest {
@Test
public void testAuditObjectThrowable() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
Exception exception = new NullPointerException();
logger4J.audit("message", exception);
Mockito.verify(logger).info("message", exception);
@@ -326,24 +326,24 @@ public class Logger4JTest {
@Test
public void testIsTraceEnabled() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
+ Whitebox.setInternalState(logger4J, "log", logger);
logger4J.isTraceEnabled();
Mockito.verify(logger).isTraceEnabled();
}
@Test
- public void testPostMDCInfoForTriggeredRule() {
+ public void testPostMdcInfoForTriggeredRule() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
- logger4J.postMDCInfoForTriggeredRule("transactionId");
+ Whitebox.setInternalState(logger4J, "log", logger);
+ logger4J.postMdcInfoForTriggeredRule("transactionId");
Mockito.verify(logger).info("transactionId");
}
@Test
- public void testPostMDCInfoForEventObject() {
+ public void testPostMdcInfoForEventObject() {
Logger logger = Mockito.mock(Logger.class);
- TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
- logger4J.postMDCInfoForEvent(1);
+ Whitebox.setInternalState(logger4J, "log", logger);
+ logger4J.postMdcInfoForEvent(1);
Mockito.verify(logger).info(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 cd16a3fd..92df0297 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
@@ -3,13 +3,14 @@
* ONAP-Logging
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* 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.
@@ -222,7 +223,7 @@ public class SystemOutLoggerTest {
}
@Test
- public void testRecordAuditEventStartUUID() {
+ public void testRecordAuditEventStartUuid() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
@@ -253,7 +254,7 @@ public class SystemOutLoggerTest {
}
@Test
- public void testRecordAuditEventEndUUIDStringString() {
+ public void testRecordAuditEventEndUuidStringString() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
@@ -284,7 +285,7 @@ public class SystemOutLoggerTest {
}
@Test
- public void testRecordAuditEventEndUUIDString() {
+ public void testRecordAuditEventEndUuidString() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
@@ -315,7 +316,7 @@ public class SystemOutLoggerTest {
}
@Test
- public void testRecordMetricEventUUIDString() {
+ public void testRecordMetricEventUuidString() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
@@ -379,8 +380,8 @@ public class SystemOutLoggerTest {
}
@Test
- public void testPostMDCInfoForEventString() {
- assertEquals("transactionId", systemOutLogger.postMDCInfoForEvent("transactionId"));
+ public void testPostMdcInfoForEventString() {
+ assertEquals("transactionId", systemOutLogger.postMdcInfoForEvent("transactionId"));
}
@Test
@@ -525,13 +526,13 @@ public class SystemOutLoggerTest {
}
@Test
- public void testPostMDCInfoForTriggeredRule() {
+ public void testPostMdcInfoForTriggeredRule() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
try {
System.setOut(ps);
- systemOutLogger.postMDCInfoForTriggeredRule("transactionId");
+ systemOutLogger.postMdcInfoForTriggeredRule("transactionId");
assertTrue(baos.toString(), baos.toString().contains("transactionId"));
} finally {
System.out.flush();
@@ -540,13 +541,13 @@ public class SystemOutLoggerTest {
}
@Test
- public void testPostMDCInfoForEventObject() {
+ public void testPostMdcInfoForEventObject() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
try {
System.setOut(ps);
- systemOutLogger.postMDCInfoForEvent(1);
+ systemOutLogger.postMdcInfoForEvent(1);
assertTrue(baos.toString(), baos.toString().contains("1"));
} finally {
System.out.flush();
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/util/TestUtils.java b/common-logging/src/test/java/org/onap/policy/common/logging/util/TestUtils.java
deleted file mode 100644
index 94bfbb74..00000000
--- a/common-logging/src/test/java/org/onap/policy/common/logging/util/TestUtils.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*-
- * ============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.util;
-
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-
-public class TestUtils {
-
- /**
- * Override a field.
- *
- * @param clazz the class the field belongs to
- * @param object the instance of the class
- * @param fieldName the name of the field
- * @param newValue the value to set the field to
- */
- public static void overrideField(@SuppressWarnings("rawtypes") final Class clazz, final Object object,
- 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);
-
- field.set(object, newValue);
- } catch (final Exception e) {
- fail(e.toString());
- }
- }
-
- /**
- * Override a static field.
- *
- * @param clazz the class the field belongs to
- * @param fieldName the name of the field
- * @param newValue the value to set the field to
- */
- public 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());
- }
- }
-
-}