aboutsummaryrefslogtreecommitdiffstats
path: root/common-logging/src/test/java
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2024-08-29 15:58:06 +0100
committeradheli.tavares <adheli.tavares@est.tech>2024-08-29 15:59:31 +0100
commitf875828ecc091dc505697ac98256ba06aff9a20a (patch)
tree62f23931de0fa3dce16021bc8badd6822cdd615a /common-logging/src/test/java
parent63d23a4aa0f3aeae9d6470b95dfa8f87b2d85aa8 (diff)
Remove modules not being used
Remove modules common-logging, integrity-audity and integrity-monitor as they are not being used in any component. Issue-ID: POLICY-5123 Change-Id: I571f17236a3c8bb9e8e52c99d0298f4098cb5ca9 Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'common-logging/src/test/java')
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPdpMdcInfoTest.java43
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/ErrorCodeMapTest.java62
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java172
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java130
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java131
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java718
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java390
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java112
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/PropertyUtilTest.java172
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java558
10 files changed, 0 insertions, 2488 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
deleted file mode 100644
index ba72f36b..00000000
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPdpMdcInfoTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP Policy Engine - Common Modules
- * ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation
- * ================================================================================
- * 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.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-import com.att.eelf.configuration.Configuration;
-import org.junit.jupiter.api.Test;
-
-class DroolsPdpMdcInfoTest {
-
- /**
- * Test method for {@link org.onap.policy.common.logging.eelf.DroolsPdpMdcInfo#getMdcInfo()}.
- */
- @Test
- void testGetMdcInfo() {
- DroolsPdpMdcInfo di = new DroolsPdpMdcInfo();
-
- 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/ErrorCodeMapTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/ErrorCodeMapTest.java
deleted file mode 100644
index 764b41b2..00000000
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/ErrorCodeMapTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP-Logging
- * ================================================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 AT&T.
- * Modifications Copyright (C) 2024 Nordix Foundation
- * ================================================================================
- * 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.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-import org.junit.jupiter.api.Test;
-import org.onap.policy.common.logging.eelf.ErrorCodeMap.ErrorCodeInfo;
-
-class ErrorCodeMapTest {
-
- @Test
- 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
- void testErrorCodeInfoGetErrorCode() {
- ErrorCodeInfo errorCodeInfo = ErrorCodeMap.getErrorCodeInfo(MessageCodes.EXCEPTION_ERROR);
- assertEquals("500", errorCodeInfo.getErrorCode());
- }
-
- @Test
- 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/EventDataTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java
deleted file mode 100644
index 6e518c22..00000000
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP Policy Engine - Common Modules
- * ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation
- * ================================================================================
- * 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.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-import java.time.Instant;
-import org.junit.jupiter.api.Test;
-
-class EventDataTest {
- private static final Instant istart = Instant.ofEpochMilli(100000L);
- private static final Instant iend = Instant.ofEpochMilli(200000L);
-
- /**
- * Test method for {@link EventData#EventData()}.
- */
- @Test
- void testEventData() {
- EventData eventData = new EventData();
-
- assertNull(eventData.getEndTime());
- assertNull(eventData.getRequestId());
- assertNull(eventData.getStartTime());
- }
-
- /**
- * Test method for {@link EventData#EventData(String, Instant, Instant)}.
- */
- @Test
- void testEventDataStringInstantInstant() {
- EventData eventData = new EventData("myreq", istart, iend);
-
- assertEquals("myreq", eventData.getRequestId());
- assertEquals(istart, eventData.getStartTime());
- assertEquals(iend, eventData.getEndTime());
- }
-
- /**
- * Test method for {@link EventData#getRequestId()} and {@link EventData#setRequestId(String)}.
- */
- @Test
- void testGetSetRequestId() {
- EventData eventData = new EventData();
- assertNull(eventData.getRequestId());
-
- eventData.setRequestId("abc");
- assertEquals("abc", eventData.getRequestId());
-
- eventData.setRequestId("def");
- assertEquals("def", eventData.getRequestId());
- }
-
- /**
- * Test method for {@link EventData#getStartTime()} and {@link EventData#setStartTime(Instant)}.
- */
- @Test
- void testGetSetStartTime() {
- EventData eventData = new EventData();
- assertNull(eventData.getStartTime());
-
- eventData.setStartTime(istart);
- assertEquals(istart, eventData.getStartTime());
-
- eventData.setStartTime(iend);
- assertEquals(iend, eventData.getStartTime());
-
- // setting end-time should not effect start-time
- eventData.setEndTime(istart);
- assertEquals(iend, eventData.getStartTime());
- }
-
- /**
- * Test method for {@link EventData#getEndTime()} and {@link EventData#setEndTime(Instant)}.
- */
- @Test
- void testGetSetEndTime() {
- EventData eventData = new EventData();
- assertNull(eventData.getEndTime());
-
- eventData.setEndTime(iend);
- assertEquals(iend, eventData.getEndTime());
-
- eventData.setEndTime(istart);
- assertEquals(istart, eventData.getEndTime());
-
- // setting start-time should not effect end-time
- eventData.setStartTime(iend);
- assertEquals(istart, eventData.getEndTime());
- }
-
- /**
- * Test method for {@link EventData#toString()}.
- */
- @Test
- void testToString() {
- EventData eventData = new EventData("myreq", istart, iend);
- assertEquals("myreq Starting Time : 1970-01-01T00:01:40Z Ending Time : 1970-01-01T00:03:20Z",
- eventData.toString());
- }
-
- /**
- * Test method for {@link EventData#hashCode()}.
- */
- @Test
- void testHashCode() {
- int hc1 = new EventData("abc", istart, iend).hashCode();
-
- assertNotEquals(hc1, new EventData("abd", istart, iend).hashCode());
- assertEquals(hc1, new EventData("abc", iend, istart).hashCode());
- }
-
- /**
- * Test method for {@link EventData#equals(Object)}.
- */
- @Test
- void testEqualsObject() {
- final EventData d1 = new EventData("abc", istart, iend);
- final EventData d2 = new EventData("abd", istart, iend);
- final EventData d3 = new EventData("abc", iend, istart);
-
- // same object
- assertEquals(d1, d1);
-
- // compare with null
- assertNotEquals(null, d1);
-
- // compare with request id
- // note: ignoring sonar because we want to test d1.equals(), not "abc".equals()
- assertEquals(d1, "abc"); // NOSONAR
- assertNotEquals("abd", d1);
-
- // compare with int - different class type
- assertNotEquals(10, d1);
-
- // "this" has null request id
- assertNotEquals(new EventData(), d1);
-
- // both null
- assertEquals(new EventData(), new EventData());
-
- // this request id is not null, other is null
- assertNotEquals(d1, new EventData());
-
- // neither null, same
- assertEquals(d1, d3);
-
- // neither null, diff
- assertNotEquals(d1, d2);
- }
-
-}
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java
deleted file mode 100644
index 92d24009..00000000
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP Policy Engine - Common Modules
- * ================================================================================
- * Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation
- * ================================================================================
- * 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.jupiter.api.Assertions.assertEquals;
-
-import java.time.Instant;
-import java.util.concurrent.ConcurrentMap;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-class EventTrackInfoHandlerTest {
-
- private static final Instant inow = Instant.now();
- private static final Instant iexpired = Instant.ofEpochMilli(10000L);
-
- private static final EventData data1 = new EventData("abc", inow, inow);
- private static final EventData data2 = new EventData("def", inow, inow);
-
- private static EventTrackInfo tracker;
- private static ConcurrentMap<String, EventData> info;
-
- private EventTrackInfoHandler hdlr;
-
- @BeforeAll
- public static void setUpBeforeClass() {
- tracker = PolicyLogger.getEventTracker();
- info = tracker.getEventInfo();
- }
-
- /**
- * Perform set up for test cases.
- */
- @BeforeEach
- void setUp() {
- info.clear();
-
- hdlr = new EventTrackInfoHandler();
- }
-
- @Test
- void testNoEvents() {
- hdlr.run();
- assertEquals(0, info.size());
- }
-
- @Test
- void testNothingExpired() {
- tracker.storeEventData(data1);
- tracker.storeEventData(data2);
-
- hdlr.run();
- assertEquals(2, info.size());
- }
-
- @Test
- void testSomeExpired() {
- // not expired
- tracker.storeEventData(data1);
- tracker.storeEventData(data2);
-
- // start time is expired
- tracker.storeEventData(new EventData("expiredA", iexpired, inow));
- tracker.storeEventData(new EventData("expiredB", iexpired, inow));
-
- // end time is expired, but that has no impact - these should be retained
- EventData oka = new EventData("okA", inow, iexpired);
- EventData okb = new EventData("okB", inow, iexpired);
-
- tracker.storeEventData(oka);
- tracker.storeEventData(okb);
-
- hdlr.run();
- assertEquals(4, info.size());
-
- assertEquals(data1, info.get("abc"));
- assertEquals(data2, info.get("def"));
- assertEquals(oka, info.get("okA"));
- assertEquals(okb, info.get("okB"));
- }
-
- @Test
- void testMultipleRuns() {
-
- hdlr.run();
- assertEquals(0, info.size());
-
- // not expired
- tracker.storeEventData(data1);
- tracker.storeEventData(data2);
-
- hdlr.run();
- assertEquals(2, info.size());
-
- // start time is expired
- tracker.storeEventData(new EventData("expiredA", iexpired, inow));
- tracker.storeEventData(new EventData("expiredB", iexpired, inow));
-
- // end time is expired, but that has no impact - these should be retained
- tracker.storeEventData(new EventData("okA", inow, iexpired));
- tracker.storeEventData(new EventData("okB", inow, iexpired));
-
- hdlr.run();
- assertEquals(4, info.size());
-
- hdlr.run();
- assertEquals(4, info.size());
- }
-
-}
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
deleted file mode 100644
index 49a3463f..00000000
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP Policy Engine - Common Modules
- * ================================================================================
- * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation
- * ================================================================================
- * 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.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertSame;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.time.Instant;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-class EventTrackInfoTest {
-
- private static final Instant istart = Instant.ofEpochMilli(100000L);
- private static final Instant iend = Instant.ofEpochMilli(200000L);
-
- private static final EventData data1 = new EventData("abc", istart, iend);
- private static final EventData data2 = new EventData("def", iend, istart);
-
- private EventTrackInfo info;
-
- @BeforeEach
- void setUp() {
- info = new EventTrackInfo();
-
- }
-
- /**
- * Test method for {@link EventTrackInfo#EventTrackInfo()}.
- */
- @Test
- void testEventTrackInfo() {
- assertNotNull(info.getEventInfo());
- }
-
- /**
- * Test method for {@link EventTrackInfo#getEventDataByRequestId(String)}.
- */
- @Test
- void testGetEventDataByRequestId() {
- info.storeEventData(data1);
- info.storeEventData(data2);
-
- assertSame(data1, info.getEventDataByRequestId("abc"));
- assertSame(data2, info.getEventDataByRequestId("def"));
- assertNull(info.getEventDataByRequestId("hello"));
- }
-
- /**
- * Test method for {@link EventTrackInfo#storeEventData(EventData)}.
- */
- @Test
- void testStoreEventData() {
- // should ignore null
- info.storeEventData(null);
- assertTrue(info.getEventInfo().isEmpty());
-
- // should ignore if request id is null or empty
- info.storeEventData(new EventData());
- info.storeEventData(new EventData("", istart, iend));
- assertTrue(info.getEventInfo().isEmpty());
-
- info.storeEventData(data1);
- info.storeEventData(data2);
- assertEquals(2, info.getEventInfo().size());
-
- // look-up by request id
- assertSame(data1, info.getEventDataByRequestId("abc"));
- assertSame(data2, info.getEventDataByRequestId("def"));
-
- // doesn't replace existing value
- info.storeEventData(new EventData("abc", iend, istart));
- assertEquals(2, info.getEventInfo().size());
- assertSame(data1, info.getEventDataByRequestId("abc"));
- assertSame(data2, info.getEventDataByRequestId("def"));
- }
-
- /**
- * Test method for {@link EventTrackInfo#remove(String)}.
- */
- @Test
- void testRemove() {
- info.storeEventData(data1);
- info.storeEventData(data2);
-
- info.remove("abc");
-
- // ensure only that item was removed
- assertEquals(1, info.getEventInfo().size());
-
- // look-up by request id
- assertNull(info.getEventDataByRequestId("abc"));
- assertSame(data2, info.getEventDataByRequestId("def"));
- }
-
- /**
- * Test method for {@link EventTrackInfo#getEventInfo()}.
- */
- @Test
- void testGetEventInfo() {
- info.storeEventData(data1);
- info.storeEventData(data2);
-
- assertEquals(2, info.getEventInfo().size());
- assertSame(data1, info.getEventInfo().get("abc"));
- assertSame(data2, info.getEventInfo().get("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
deleted file mode 100644
index d7239f4e..00000000
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java
+++ /dev/null
@@ -1,718 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP-Logging
- * ================================================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023-2024 Nordix Foundation.
- * ================================================================================
- * 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.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.never;
-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;
-import java.time.Instant;
-import java.util.Properties;
-import java.util.UUID;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-import org.slf4j.MDC;
-import org.springframework.test.util.ReflectionTestUtils;
-
-class PolicyLoggerTest {
-
- /**
- * Perform set up for test cases.
- */
- @BeforeEach
- void setUp() {
- Properties properties = new Properties();
- properties.setProperty("policy.component", "XACML");
- PolicyLogger.init(properties);
- }
-
- @Test
- void testSetAndGetDebugLevelLevel() {
- PolicyLogger.setDebugLevel(Level.INFO);
- assertEquals(Level.INFO, PolicyLogger.getDebugLevel());
- PolicyLogger.setDebugLevel(Level.DEBUG);
- assertEquals(Level.DEBUG, PolicyLogger.getDebugLevel());
- }
-
- @Test
- void testSetAndGetAuditLevelLevel() {
- PolicyLogger.setAuditLevel(Level.INFO);
- assertEquals(Level.INFO, PolicyLogger.getAuditLevel());
- PolicyLogger.setAuditLevel(Level.DEBUG);
- assertEquals(Level.DEBUG, PolicyLogger.getAuditLevel());
- }
-
- @Test
- void testSetAndGetMetricsLevelLevel() {
- PolicyLogger.setMetricsLevel(Level.INFO);
- assertEquals(Level.INFO, PolicyLogger.getMetricsLevel());
- PolicyLogger.setMetricsLevel(Level.DEBUG);
- assertEquals(Level.DEBUG, PolicyLogger.getMetricsLevel());
- }
-
- @Test
- void testSetAndGetErrorLevelLevel() {
- PolicyLogger.setErrorLevel(Level.INFO);
- assertEquals(Level.INFO, PolicyLogger.getErrorLevel());
- PolicyLogger.setErrorLevel(Level.DEBUG);
- assertEquals(Level.DEBUG, PolicyLogger.getErrorLevel());
- }
-
- @Test
- void testSetAndGetClassname() {
- assertEquals("ClassName", PolicyLogger.getClassname());
- PolicyLogger.setClassname("PolicyLoggerTest");
- assertEquals("PolicyLoggerTest", PolicyLogger.getClassname());
- }
-
- @Test
- 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
- 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
- void testSetAndGetTransId() {
- PolicyLogger.setTransId("123456");
- assertEquals("123456", PolicyLogger.getTransId());
- }
-
- @Test
- 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
- 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
- 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
- void testInfoMessageCodesStringStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
- Mockito.verify(mockLogger).info(MessageCodes.ERROR_DATA_ISSUE, "str2");
- }
-
- @Test
- void testInfoStringString() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.info("str1", "str2");
- Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
- Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
- PolicyLogger.info("str1", "str2");
- Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "str2");
- }
-
- @Test
- void testInfoObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.info("str1");
- Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "str1");
- }
-
- @Test
- void testInfoMessageCodesThrowableStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(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
- void testInfoMessageCodesStringThrowableStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(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
- void testWarnMessageCodesStringStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "str1");
- Mockito.verify(mockLogger).warn(MessageCodes.ERROR_DATA_ISSUE);
- }
-
- @Test
- void testWarnStringString() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.warn("str1", "str2");
- Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
- Mockito.when(mockLogger.isWarnEnabled()).thenReturn(true);
- PolicyLogger.warn("str1", "str2");
- Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_INFO, "str2");
- }
-
- @Test
- void testWarnObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.warn(1);
- Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_WARNING, "1");
- }
-
- @Test
- void testWarnMessageCodesThrowableStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(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
- void testWarnMessageCodesStringThrowableStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(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
- void testWarnString() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.warn("str1");
- Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_WARNING, "str1");
- }
-
- @Test
- void testErrorStringString() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
- PolicyLogger.error("str1", "str2");
- Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
- Mockito.when(mockLogger.isErrorEnabled()).thenReturn(true);
- PolicyLogger.error("str1", "str2");
- Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str2");
- assertEquals("500", MDC.get("ErrorCode"));
- assertEquals("This is a general error message during the process. Please check the error message for detail "
- + "information", MDC.get("ErrorDescription"));
- }
-
- @Test
- void testErrorString() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
- PolicyLogger.error("str1");
- Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str1");
- assertEquals("ERROR", MDC.get("ErrorCategory"));
- assertEquals("500", 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
- void testErrorObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
- PolicyLogger.error(1);
- Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "1");
- assertEquals("ERROR", MDC.get("ErrorCategory"));
- assertEquals("500", 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
- void testErrorMessageCodesThrowableStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(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
- void testErrorMessageCodesStringThrowableStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(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
- void testErrorMessageCodesStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
- Mockito.verify(mockLogger).error(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
- }
-
- @Test
- void testDebugMessageCodesStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
- Mockito.verify(mockLogger).debug(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
- }
-
- @Test
- void testDebugStringString() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.debug("str1", "str2");
- Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
- Mockito.when(mockLogger.isDebugEnabled()).thenReturn(true);
- PolicyLogger.debug("str1", "str2");
- Mockito.verify(mockLogger).debug(MessageCodes.GENERAL_INFO, "str2");
- }
-
- @Test
- void testDebugString() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.debug("str1");
- Mockito.verify(mockLogger).debug("str1");
- }
-
- @Test
- void testDebugObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.debug(1);
- Mockito.verify(mockLogger).debug("{}", 1);
- }
-
- @Test
- void testAuditStringObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "auditLogger", mockLogger);
- PolicyLogger.audit("PolicyLoggerTest", 1);
- Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
- Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
- PolicyLogger.audit("PolicyLoggerTest", 1);
- assertEquals("PolicyLoggerTest", MDC.get("ClassName"));
- assertEquals("COMPLETE", MDC.get("StatusCode"));
- Mockito.verify(mockLogger).info("{}", "1");
- }
-
- @Test
- void testAuditObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "auditLogger", mockLogger);
- PolicyLogger.audit(1);
- assertEquals("", MDC.get("ClassName"));
- assertEquals("COMPLETE", MDC.get("StatusCode"));
- Mockito.verify(mockLogger).info("{}", 1);
- }
-
- @Test
- void testDebugMessageCodesThrowableStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(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
- void testDebugMessageCodesStringThrowableStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(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
- void testIsDebugEnabled() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
- assertFalse(PolicyLogger.isDebugEnabled());
- assertTrue(PolicyLogger.isDebugEnabled());
- }
-
- @Test
- void testIsErrorEnabled() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
- Mockito.when(mockLogger.isErrorEnabled()).thenReturn(false).thenReturn(true);
- assertFalse(PolicyLogger.isErrorEnabled());
- assertTrue(PolicyLogger.isErrorEnabled());
- }
-
- @Test
- void testIsWarnEnabled() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- Mockito.when(mockLogger.isWarnEnabled()).thenReturn(false).thenReturn(true);
- assertFalse(PolicyLogger.isWarnEnabled());
- assertTrue(PolicyLogger.isWarnEnabled());
- }
-
- @Test
- void testIsInfoEnabled1() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
- assertFalse(PolicyLogger.isInfoEnabled1());
- assertTrue(PolicyLogger.isInfoEnabled1());
- }
-
- @Test
- void testIsAuditEnabled() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
- assertFalse(PolicyLogger.isAuditEnabled());
- assertTrue(PolicyLogger.isAuditEnabled());
- }
-
- @Test
- void testIsInfoEnabled() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
- assertFalse(PolicyLogger.isInfoEnabled());
- assertTrue(PolicyLogger.isInfoEnabled());
- }
-
- @Test
- void testTraceStringString() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.trace("str1", "str2");
- Mockito.verify(mockLogger).trace(MessageCodes.GENERAL_INFO, "str2");
- }
-
- @Test
- void testTraceObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.trace(1);
- Mockito.verify(mockLogger).trace("{}", 1);
- }
-
- @Test
- void testRecordAuditEventStartAndEnd() {
- PolicyLogger.recordAuditEventStart("eventId");
- assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
-
- PolicyLogger.recordAuditEventEnd("eventId", "rule");
- assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
- }
-
- @Test
- 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
- void testRecordAuditEventEndStringStringString() {
- PolicyLogger.recordAuditEventStart("eventId");
- assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
-
- PolicyLogger.recordAuditEventEnd("eventId", "rule", "policyVersion");
- assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
- }
-
- @Test
- 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
- void testCreatAuditEventTrackingRecordStringStringString() {
- PolicyLogger.recordAuditEventStart("eventId");
- assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
-
- PolicyLogger.creatAuditEventTrackingRecord("eventId", "rule", "policyVersion");
- assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
- }
-
- @Test
- 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
- void testRecordAuditEventStartToEnd() {
- PolicyLogger.recordAuditEventStartToEnd("eventId", "rule", Instant.now(), Instant.now(), "policyVersion");
- assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID));
- }
-
- @Test
- void testRecordMetricEventStringString() {
- PolicyLogger.recordMetricEvent("eventId", "str1");
- assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID));
- }
-
- @Test
- void testRecordMetricEventStringStringString() {
- PolicyLogger.recordMetricEvent("eventId", "PolicyLoggerTest", "str1");
- assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID));
- }
-
- @Test
- void testRecordMetricEventUuidString() {
- UUID uuid = UUID.randomUUID();
- PolicyLogger.recordMetricEvent(uuid, "str1");
- assertEquals(uuid.toString(), MDC.get(MDC_KEY_REQUEST_ID));
- }
-
- @Test
- void testRecordMetricEventString() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
- PolicyLogger.recordMetricEvent("eventId");
- Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
- Mockito.eq("eventId"));
- }
-
- @Test
- void testMetricsString() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
- PolicyLogger.metrics("str1");
- Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
- Mockito.eq("str1"));
- }
-
- @Test
- void testMetricsStringObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
- PolicyLogger.metrics("PolicyLoggerTest", 1);
- Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
- Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
- PolicyLogger.metrics("PolicyLoggerTest", 1);
- Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
- Mockito.eq("1"));
- }
-
- @Test
- void testMetricsObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
- PolicyLogger.metrics(1);
- Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
- Mockito.eq("1"));
- }
-
- @Test
- void testMetricsPrintln() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
- PolicyLogger.metricsPrintln("str1");
- Mockito.verify(mockLogger).info("str1");
- }
-
- @Test
- void testInitNullProperties() {
- assertThatCode(() -> PolicyLogger.init(null)).doesNotThrowAnyException();
- }
-
- @Test
- 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");
-
- assertThatCode(() -> PolicyLogger.init(properties)).doesNotThrowAnyException();
- }
-
- @Test
- void testSetDebugLevelString() {
- PolicyLogger.setOverrideLogbackLevel(true);
- PolicyLogger.setDebugLevel("TRACE");
- assertEquals(Level.TRACE, PolicyLogger.getDebugLevel());
- }
-
- @Test
- void testSetErrorLevelStringOff() {
- PolicyLogger.setOverrideLogbackLevel(true);
- PolicyLogger.setErrorLevel("OFF");
- assertEquals(Level.OFF, PolicyLogger.getErrorLevel());
- }
-
- @Test
- void testSetErrorLevelStringOther() {
- PolicyLogger.setOverrideLogbackLevel(true);
- PolicyLogger.setErrorLevel("INFO");
- assertEquals(Level.ERROR, PolicyLogger.getErrorLevel());
- }
-
- @Test
- void testSetMetricsLevelStringOff() {
- PolicyLogger.setOverrideLogbackLevel(true);
- PolicyLogger.setMetricsLevel("OFF");
- assertEquals(Level.OFF, PolicyLogger.getMetricsLevel());
- }
-
- @Test
- void testSetMetricsLevelStringOther() {
- PolicyLogger.setOverrideLogbackLevel(true);
- PolicyLogger.setMetricsLevel("ERROR");
- assertEquals(Level.INFO, PolicyLogger.getMetricsLevel());
- }
-
- @Test
- void testSetAuditLevelStringOff() {
- PolicyLogger.setOverrideLogbackLevel(true);
- PolicyLogger.setAuditLevel("OFF");
- assertEquals(Level.OFF, PolicyLogger.getAuditLevel());
- }
-
- @Test
- void testSetAuditLevelStringOther() {
- PolicyLogger.setOverrideLogbackLevel(true);
- PolicyLogger.setAuditLevel("ERROR");
- assertEquals(Level.INFO, PolicyLogger.getAuditLevel());
- }
-
- @Test
- void testSetAndIsOverrideLogbackLevel() {
- PolicyLogger.setOverrideLogbackLevel(false);
- assertFalse(PolicyLogger.isOverrideLogbackLevel());
- PolicyLogger.setOverrideLogbackLevel(true);
- assertTrue(PolicyLogger.isOverrideLogbackLevel());
- }
-
- @Test
- void testSetServerInfo() {
- PolicyLogger.setServerInfo("serverHost", "serverPort");
- assertEquals("serverHost:serverPort", MDC.get(SERVER_NAME));
- }
-
-}
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
deleted file mode 100644
index 66b48e07..00000000
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java
+++ /dev/null
@@ -1,390 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP-Logging
- * ================================================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023-2024 Nordix Foundation.
- * ================================================================================
- * 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.flexlogger;
-
-import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.never;
-
-import com.att.eelf.configuration.EELFLogger;
-import java.util.UUID;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-import org.onap.policy.common.logging.eelf.MessageCodes;
-import org.onap.policy.common.logging.eelf.PolicyLogger;
-import org.slf4j.MDC;
-import org.springframework.test.util.ReflectionTestUtils;
-
-class EelfLoggerTest {
-
- EelfLogger eelfLogger = new EelfLogger("EelfLoggerTest", "transactionId");
-
- @Test
- void testEelfLoggerClassOfQ() {
- new EelfLogger(this.getClass());
- assertNotNull(PolicyLogger.getTransId());
- assertFalse(PolicyLogger.getTransId().isEmpty());
- }
-
- @Test
- void testEelfLoggerString() {
- new EelfLogger("EelfLoggerTest");
- assertNotNull(PolicyLogger.getTransId());
- assertFalse(PolicyLogger.getTransId().isEmpty());
- }
-
- @Test
- void testEelfLoggerClassOfQBoolean() {
- new EelfLogger(this.getClass(), true);
- assertNotNull(PolicyLogger.getTransId());
- assertFalse(PolicyLogger.getTransId().isEmpty());
- }
-
- @Test
- void testEelfLoggerStringBoolean() {
- new EelfLogger("EelfLoggerTest", true);
- assertNotNull(PolicyLogger.getTransId());
- assertFalse(PolicyLogger.getTransId().isEmpty());
- }
-
- @Test
- void testEelfLoggerClassOfQString() {
- new EelfLogger(this.getClass(), "transactionId");
- assertEquals("transactionId", PolicyLogger.getTransId());
- }
-
- @Test
- void testEelfLoggerStringString() {
- new EelfLogger("EelfLoggerTest", "transactionId");
- assertEquals("transactionId", PolicyLogger.getTransId());
- }
-
- @Test
- void testSetAndGetTransId() {
- assertEquals("transactionId", eelfLogger.getTransId());
- eelfLogger.setTransId("transactionId2");
- assertEquals("transactionId2", eelfLogger.getTransId());
- }
-
- @Test
- void testDebugObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- eelfLogger.debug("message");
- Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
- Mockito.when(mockLogger.isDebugEnabled()).thenReturn(true);
- eelfLogger.debug("message");
- Mockito.verify(mockLogger).debug(MessageCodes.GENERAL_INFO, "message");
- }
-
- @Test
- void testErrorObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
- eelfLogger.error("message");
- Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
- Mockito.when(mockLogger.isErrorEnabled()).thenReturn(true);
- eelfLogger.error("message");
- Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "message");
- }
-
- @Test
- void testInfoObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- eelfLogger.info("message");
- Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
- Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
- eelfLogger.info("message");
- Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "message");
- }
-
- @Test
- void testWarnObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- eelfLogger.warn("message");
- Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
- Mockito.when(mockLogger.isWarnEnabled()).thenReturn(true);
- eelfLogger.warn("message");
- Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_INFO, "message");
- }
-
- @Test
- void testTraceObject() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- eelfLogger.trace("message");
- Mockito.verify(mockLogger).trace(MessageCodes.GENERAL_INFO, "message");
- }
-
- @Test
- void testIsDebugEnabled() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
- assertFalse(eelfLogger.isDebugEnabled());
- assertTrue(eelfLogger.isDebugEnabled());
-
- }
-
- @Test
- void testIsInfoEnabled() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true);
- assertFalse(eelfLogger.isInfoEnabled());
- assertTrue(eelfLogger.isInfoEnabled());
- }
-
- @Test
- void testIsWarnEnabled() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- Mockito.when(mockLogger.isWarnEnabled()).thenReturn(false).thenReturn(true);
- assertFalse(eelfLogger.isWarnEnabled());
- assertTrue(eelfLogger.isWarnEnabled());
- }
-
- @Test
- void testIsErrorEnabled() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
- Mockito.when(mockLogger.isErrorEnabled()).thenReturn(false).thenReturn(true);
- assertFalse(eelfLogger.isErrorEnabled());
- assertTrue(eelfLogger.isErrorEnabled());
- }
-
- @Test
- void testIsMetricsEnabled() {
- PolicyLogger.setOverrideLogbackLevel(true);
- PolicyLogger.setMetricsLevel("ERROR");
- assertTrue(eelfLogger.isMetricsEnabled());
- }
-
- @Test
- void testIsTraceEnabled() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
- assertFalse(eelfLogger.isTraceEnabled());
- assertTrue(eelfLogger.isTraceEnabled());
- }
-
- @Test
- void testAuditObject() {
- PolicyLogger.setOverrideLogbackLevel(true);
- PolicyLogger.setAuditLevel("ERROR");
- assertTrue(eelfLogger.isAuditEnabled());
- }
-
- @Test
- void testDebugObjectThrowable() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- eelfLogger.debug("message", new NullPointerException());
- Mockito.verify(mockLogger).debug((MessageCodes) Mockito.any(),
- Mockito.startsWith("message:java.lang.NullPointerException"));
- }
-
- @Test
- void testErrorObjectThrowable() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
- eelfLogger.error("message", new NullPointerException());
- Mockito.verify(mockLogger).error((MessageCodes) Mockito.any(),
- Mockito.startsWith("message:java.lang.NullPointerException"));
- eelfLogger.error("message", new NullPointerException());
- }
-
- @Test
- void testInfoObjectThrowable() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- eelfLogger.info("message", new NullPointerException());
- Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
- Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
- Mockito.verify(mockLogger).info((MessageCodes) Mockito.any(),
- Mockito.startsWith("message:java.lang.NullPointerException"));
- }
-
- @Test
- void testWarnObjectThrowable() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- eelfLogger.warn("message", new NullPointerException());
- Mockito.verify(mockLogger).warn((MessageCodes) Mockito.any(),
- Mockito.startsWith("message:java.lang.NullPointerException"));
- }
-
- @Test
- void testTraceObjectThrowable() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- eelfLogger.trace("message", new NullPointerException());
- Mockito.verify(mockLogger).trace("{}", "message");
- }
-
- @Test
- void testAuditObjectThrowable() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "auditLogger", mockLogger);
- eelfLogger.audit("message", new NullPointerException());
- Mockito.verify(mockLogger).info("{}", "message");
- }
-
- @Test
- void testRecordAuditEventStartString() {
- eelfLogger.recordAuditEventStart("eventId");
- assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
- }
-
- @Test
- void testRecordAuditEventStartUuid() {
- UUID uuid = UUID.randomUUID();
- eelfLogger.recordAuditEventStart(uuid);
- assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
- }
-
- @Test
- void testRecordAuditEventEndStringStringString() {
- eelfLogger.recordAuditEventStart("eventId");
- assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
-
- eelfLogger.recordAuditEventEnd("eventId", "rule", "policyVersion");
- assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
- }
-
- @Test
- void testRecordAuditEventEndUuidStringString() {
- UUID uuid = UUID.randomUUID();
- eelfLogger.recordAuditEventStart(uuid);;
- assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
-
- eelfLogger.recordAuditEventEnd(uuid, "rule", "policyVersion");
- assertNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
- }
-
- @Test
- void testRecordAuditEventEndStringString() {
- eelfLogger.recordAuditEventStart("eventId");
- assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
-
- eelfLogger.recordAuditEventEnd("eventId", "rule");
- assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
- }
-
- @Test
- void testRecordAuditEventEndUuidString() {
- UUID uuid = UUID.randomUUID();
- eelfLogger.recordAuditEventStart(uuid);;
- assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
-
- eelfLogger.recordAuditEventEnd(uuid, "rule");
- assertNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
- }
-
- @Test
- void testRecordMetricEventStringString() {
- eelfLogger.recordMetricEvent("eventId", "str1");
- assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID));
- }
-
- @Test
- void testRecordMetricEventUuidString() {
- UUID uuid = UUID.randomUUID();
- eelfLogger.recordMetricEvent(uuid, "str2");
- assertEquals(uuid.toString(), MDC.get(MDC_KEY_REQUEST_ID));
- }
-
- @Test
- void testMetrics() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger);
- eelfLogger.metrics(1);
- Mockito.verify(mockLogger, never()).info(Mockito.anyString(), Mockito.anyString());
- Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true);
- eelfLogger.metrics(1);
- Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
- Mockito.eq("1"));
- }
-
- @Test
- void testErrorMessageCodesThrowableStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(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"));
- }
-
- @Test
- void testErrorMessageCodesStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger);
- eelfLogger.error(MessageCodes.GENERAL_ERROR, "str1", "str2");
- Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str1", "str2");
-
- }
-
- @Test
- void testPostMdcInfoForEventString() {
- eelfLogger.postMdcInfoForEvent("transactionId");
- assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
- }
-
- @Test
- void testWarnMessageCodesStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger);
- eelfLogger.warn(MessageCodes.GENERAL_ERROR, "str1", "str2");
- Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_ERROR, "str1", "str2");
- }
-
- @Test
- void testWarnMessageCodesThrowableStringArray() {
- EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
- ReflectionTestUtils.setField(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"));
-
- }
-
- @Test
- void testPostMdcInfoForTriggeredRule() {
- eelfLogger.postMdcInfoForTriggeredRule("transactionId");
- assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
- }
-
- @Test
- 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
deleted file mode 100644
index 3c78785b..00000000
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP-Logging
- * ================================================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023-2024 Nordix Foundation.
- * ================================================================================
- * 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.flexlogger;
-
-import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.assertSame;
-
-import java.util.HashSet;
-import java.util.Set;
-import org.junit.jupiter.api.Test;
-import org.onap.policy.common.logging.flexlogger.FlexLogger.PropertiesCallBack;
-import org.springframework.test.util.ReflectionTestUtils;
-
-class FlexLoggerTest {
-
- @Test
- void testGetLoggerClassOfQEelf() {
- ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF);
- Logger logger = FlexLogger.getLogger((Class<?>) null);
- assertSame(logger, FlexLogger.getLogger((Class<?>) null));
- assertNotEquals(logger, FlexLogger.getLogger(String.class));
- }
-
- @Test
- void testGetLoggerClassOfQSystemOut() {
- ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
- Logger logger = FlexLogger.getLogger(this.getClass());
- assertSame(logger, FlexLogger.getLogger(this.getClass()));
- }
-
- @Test
- void testGetLoggerStringEelf() {
- ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF);
- Logger logger = FlexLogger.getLogger();
- assertSame(logger, FlexLogger.getLogger());
- }
-
- @Test
- void testGetLoggerStringSystemOut() {
- ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
- Logger logger = FlexLogger.getLogger();
- assertSame(logger, FlexLogger.getLogger());
- }
-
- @Test
- void testGetLoggerClassOfQBooleanEelf() {
- ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF);
- Logger logger = FlexLogger.getLogger(this.getClass(), true);
- assertSame(logger, FlexLogger.getLogger(this.getClass(), true));
- }
-
- @Test
- void testGetLoggerClassOfQBooleanSystemOut() {
- ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
- Logger logger = FlexLogger.getLogger(this.getClass(), true);
- assertSame(logger, FlexLogger.getLogger(this.getClass(), true));
- }
-
- @Test
- void testGetLoggerStringBooleanEelf() {
- ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF);
- Logger logger = FlexLogger.getLogger(true);
- assertSame(logger, FlexLogger.getLogger(true));
- }
-
- @Test
- void testGetLoggerStringBooleanSystemOut() {
- ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
- Logger logger = FlexLogger.getLogger(true);
- assertSame(logger, FlexLogger.getLogger(true));
- }
-
- @Test
- void testGetClassName() {
- assertNotEquals("FlexLogger", new FlexLogger().getClassName());
- }
-
- @Test
- void testPropertiesCallBack() {
- Set<String> changedKeys = new HashSet<>();
- changedKeys.add("debugLogger.level");
- changedKeys.add("metricsLogger.level");
- changedKeys.add("error.level");
- changedKeys.add("audit.level");
- PropertiesCallBack propertiesCallBack = new PropertiesCallBack("name");
- assertThatCode(() -> propertiesCallBack
- .propertiesChanged(PropertyUtil.getProperties("config/policyLogger.properties"), changedKeys))
- .doesNotThrowAnyException();
- }
-
-}
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/PropertyUtilTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/PropertyUtilTest.java
deleted file mode 100644
index 75c512b2..00000000
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/PropertyUtilTest.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP-Logging
- * ================================================================================
- * Copyright (C) 2018-2020 Ericsson, AT&T. All rights reserved.
- * Modifications Copyright (C) 2023-2024 Nordix Foundation.
- * ================================================================================
- * 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.flexlogger;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyLong;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Properties;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.onap.policy.common.logging.flexlogger.PropertyUtil.Listener;
-import org.springframework.test.util.ReflectionTestUtils;
-
-class PropertyUtilTest {
-
- private static final String TIMER_FIELD = "timer";
- private static final File FILE = new File("target/test.properties");
- private static Timer saveTimer;
-
- private TimerTask task;
- private Timer timer;
- private TestListener testListener;
-
- @BeforeAll
- public static void setUpBeforeClass() {
- saveTimer = (Timer) ReflectionTestUtils.getField(PropertyUtil.LazyHolder.class, TIMER_FIELD);
-
- }
-
- @AfterAll
- public static void tearDownAfterClass() {
- ReflectionTestUtils.setField(PropertyUtil.LazyHolder.class, TIMER_FIELD, saveTimer);
-
- }
-
- /**
- * Perform test case set up.
- */
- @BeforeEach
- void setUp() throws IOException {
- task = null;
- timer = mock(Timer.class);
- ReflectionTestUtils.setField(PropertyUtil.LazyHolder.class, TIMER_FIELD, timer);
-
- doAnswer(args -> {
- task = args.getArgument(0, TimerTask.class);
- return null;
- }).when(timer).schedule(any(TimerTask.class), anyLong(), anyLong());
-
- testListener = new TestListener();
-
- FileOutputStream fileOutputStream = new FileOutputStream(FILE);
- Properties properties = new Properties();
- properties.put("testProperty", "testValue");
- properties.store(fileOutputStream, "");
- fileOutputStream.close();
- }
-
- @AfterEach
- void tearDown() throws IOException {
- PropertyUtil.stopListening(FILE, testListener);
- FILE.delete();
- }
-
- @Test
- void testTimer() {
- assertNotNull(saveTimer);
- }
-
- @Test
- void testGetProperties() throws IOException {
- FileOutputStream fileOutputStream = new FileOutputStream(FILE);
- Properties properties = new Properties();
- properties.put("testProperty", "testValue");
- properties.store(fileOutputStream, "");
- fileOutputStream.close();
-
- Properties readProperties = PropertyUtil.getProperties(FILE, testListener);
- assertEquals("testValue", readProperties.getProperty("testProperty"));
- }
-
- @Test
- void testPropertiesChanged() throws IOException, InterruptedException {
- PropertyUtil.getProperties(FILE, testListener);
-
- FileOutputStream fileOutputStream = new FileOutputStream(FILE);
- Properties newProperties = new Properties();
- newProperties.put("testProperty", "testValueNew");
- newProperties.store(fileOutputStream, "");
-
- // fire task and verify that it notifies the listener
- task.run();
- assertTrue(testListener.isPropertiesChangedInvoked());
-
- }
-
- @Test
- void testStopListening() throws IOException {
- FileOutputStream fileOutputStream = new FileOutputStream(FILE);
- Properties properties = new Properties();
- properties.put("testProperty", "testValue");
- properties.store(fileOutputStream, "");
-
- Properties readProperties = PropertyUtil.getProperties(FILE, testListener);
- assertEquals("testValue", readProperties.getProperty("testProperty"));
-
- PropertyUtil.stopListening(FILE, testListener);
-
- properties.put("testProperty", "testValueNew");
- properties.store(fileOutputStream, "");
- fileOutputStream.close();
- readProperties = PropertyUtil.getProperties(FILE, testListener);
- // If stopListening did not remove the listener, the properties file will not be re-read
- // until poll expires and
- // hence "testValue" will be returned here instead of "testNewValue"
- assertEquals("testValueNew", readProperties.getProperty("testProperty"));
- }
-
- /**
- * The {@link #propertiesChanged(Properties, Set)} method is invoked via a background
- * thread, thus we have to use a latch to wait for it to be invoked.
- */
- private class TestListener implements Listener {
-
- private CountDownLatch latch = new CountDownLatch(1);
-
- @Override
- public void propertiesChanged(Properties properties, Set<String> changedKeys) {
- latch.countDown();
- }
-
- public boolean isPropertiesChangedInvoked() throws InterruptedException {
- return latch.await(5, TimeUnit.SECONDS);
- }
- }
-
-}
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
deleted file mode 100644
index 343eea9c..00000000
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java
+++ /dev/null
@@ -1,558 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP-Logging
- * ================================================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation
- * ================================================================================
- * 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.flexlogger;
-
-import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import com.att.eelf.configuration.EELFLogger.Level;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.util.UUID;
-import org.junit.jupiter.api.Test;
-import org.onap.policy.common.logging.eelf.MessageCodes;
-import org.onap.policy.common.logging.eelf.PolicyLogger;
-
-class SystemOutLoggerTest {
-
- SystemOutLogger systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
-
- @Test
- void testSystemOutLoggerClassOfQ() {
- assertThatCode(() -> new SystemOutLogger(SystemOutLoggerTest.class)).doesNotThrowAnyException();
- }
-
- @Test
- void testSetAndGetTransId() {
- systemOutLogger.setTransId("transactionId");
- assertEquals("transactionId", systemOutLogger.getTransId());
- }
-
- @Test
- void testDebugObject() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- systemOutLogger.setTransId("transactionId");
- System.setOut(ps);
- systemOutLogger.debug("message");
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : message"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testErrorObject() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- systemOutLogger.setTransId("transactionId");
- System.setOut(ps);
- systemOutLogger.error("message");
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : message"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testInfoObject() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- systemOutLogger.setTransId("transactionId");
- System.setOut(ps);
- systemOutLogger.info("message");
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : message"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testWarnObject() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- systemOutLogger.setTransId("transactionId");
- System.setOut(ps);
- systemOutLogger.warn("message");
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : message"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testTraceObject() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- systemOutLogger.setTransId("transactionId");
- System.setOut(ps);
- systemOutLogger.trace("message");
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : message"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testIsDebugEnabled() {
- PolicyLogger.setDebugLevel(Level.DEBUG);
- systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
- assertTrue(systemOutLogger.isDebugEnabled());
- PolicyLogger.setDebugLevel(Level.INFO);
- systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
- assertFalse(systemOutLogger.isDebugEnabled());
- }
-
- @Test
- void testIsWarnEnabled() {
- PolicyLogger.setDebugLevel(Level.WARN);
- systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
- assertTrue(systemOutLogger.isWarnEnabled());
- PolicyLogger.setDebugLevel(Level.OFF);
- systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
- assertFalse(systemOutLogger.isWarnEnabled());
- }
-
- @Test
- void testIsInfoEnabled() {
- PolicyLogger.setDebugLevel(Level.INFO);
- systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
- assertTrue(systemOutLogger.isInfoEnabled());
- PolicyLogger.setDebugLevel(Level.OFF);
- systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
- assertFalse(systemOutLogger.isInfoEnabled());
- }
-
- @Test
- void testIsErrorEnabled() {
- PolicyLogger.setErrorLevel(Level.ERROR);
- systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
- assertTrue(systemOutLogger.isErrorEnabled());
- PolicyLogger.setErrorLevel(Level.OFF);
- systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
- assertFalse(systemOutLogger.isErrorEnabled());
- }
-
- @Test
- void testIsAuditEnabled() {
- PolicyLogger.setAuditLevel(Level.INFO);
- systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
- assertTrue(systemOutLogger.isAuditEnabled());
- PolicyLogger.setAuditLevel(Level.OFF);
- systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
- assertFalse(systemOutLogger.isAuditEnabled());
- }
-
- @Test
- void testIsMetricsEnabled() {
- PolicyLogger.setMetricsLevel(Level.INFO);
- systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
- assertTrue(systemOutLogger.isMetricsEnabled());
- PolicyLogger.setMetricsLevel(Level.OFF);
- systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
- assertFalse(systemOutLogger.isMetricsEnabled());
- }
-
- @Test
- void testAuditObject() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- systemOutLogger.setTransId("transactionId");
- System.setOut(ps);
- systemOutLogger.audit("message");
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : message"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testRecordAuditEventStartString() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- systemOutLogger.setTransId("transactionId");
- System.setOut(ps);
- systemOutLogger.recordAuditEventStart("eventId");
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : eventId"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testRecordAuditEventStartUuid() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- UUID uuid = UUID.randomUUID();
- System.setOut(ps);
- systemOutLogger.recordAuditEventStart(uuid);
- assertTrue(baos.toString().contains(uuid.toString()));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testRecordAuditEventEndStringStringString() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.recordAuditEventEnd("eventId", "rule", "policyVersion");
- assertTrue(baos.toString().contains("SystemOutLoggerTest : eventId:rule:policyVersion"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testRecordAuditEventEndUuidStringString() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- UUID uuid = UUID.randomUUID();
- System.setOut(ps);
- systemOutLogger.recordAuditEventEnd(uuid, "rule", "policyVersion");
- assertTrue(baos.toString().contains("SystemOutLoggerTest : " + uuid + ":rule:policyVersion"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testRecordAuditEventEndStringString() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.recordAuditEventEnd("eventId", "rule");
- assertTrue(baos.toString().contains("SystemOutLoggerTest : eventId:rule"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testRecordAuditEventEndUuidString() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- UUID uuid = UUID.randomUUID();
- System.setOut(ps);
- systemOutLogger.recordAuditEventEnd(uuid, "rule");
- assertTrue(baos.toString().contains("SystemOutLoggerTest : " + uuid + ":rule"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testRecordMetricEventStringString() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.recordMetricEvent("eventId", "rule");
- assertTrue(baos.toString().contains("SystemOutLoggerTest : eventId:eventIdmessage:rule"), baos.toString());
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testRecordMetricEventUuidString() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- UUID uuid = UUID.randomUUID();
- System.setOut(ps);
- systemOutLogger.recordMetricEvent(uuid, "str1");
- assertTrue(baos.toString().contains("SystemOutLoggerTest : " + uuid + ":str1"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testMetrics() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.metrics("message");
- assertTrue(baos.toString().contains("SystemOutLoggerTest : message"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testErrorMessageCodesThrowableStringArray() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.error(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
- assertTrue(baos.toString()
- .contains("SystemOutLoggerTest : MessageCodes :" + MessageCodes.ERROR_DATA_ISSUE + "[str1, str2]"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testErrorMessageCodesStringArray() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.setTransId("transactionId");
- systemOutLogger.error(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : MessageCode:"
- + MessageCodes.ERROR_DATA_ISSUE + "[str1, str2]"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testPostMdcInfoForEventString() {
- assertEquals("transactionId", systemOutLogger.postMdcInfoForEvent("transactionId"));
- }
-
- @Test
- void testWarnMessageCodesStringArray() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.setTransId("transactionId");
- systemOutLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2");
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : MessageCodes:"
- + MessageCodes.ERROR_DATA_ISSUE + "[str1, str2]"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testWarnMessageCodesThrowableStringArray() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.setTransId("transactionId");
- systemOutLogger.warn(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : MessageCodes:"
- + MessageCodes.ERROR_DATA_ISSUE + "[str1, str2]"));
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testDebugObjectThrowable() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.setTransId("transactionId");
- systemOutLogger.debug("1", new NullPointerException());
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"),
- baos.toString());
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testErrorObjectThrowable() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.setTransId("transactionId");
- systemOutLogger.error("1", new NullPointerException());
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"),
- baos.toString());
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testInfoObjectThrowable() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.setTransId("transactionId");
- systemOutLogger.info("1", new NullPointerException());
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"),
- baos.toString());
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testWarnObjectThrowable() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.setTransId("transactionId");
- systemOutLogger.warn("1", new NullPointerException());
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"),
- baos.toString());
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testTraceObjectThrowable() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.setTransId("transactionId");
- systemOutLogger.trace(1, new NullPointerException());
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"),
- baos.toString());
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testAuditObjectThrowable() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.setTransId("transactionId");
- systemOutLogger.audit("1", new NullPointerException());
- assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"),
- baos.toString());
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testIsTraceEnabled() {
- assertFalse(systemOutLogger.isTraceEnabled());
- }
-
- @Test
- void testPostMdcInfoForTriggeredRule() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.postMdcInfoForTriggeredRule("transactionId");
- assertTrue(baos.toString().contains("transactionId"), baos.toString());
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
- @Test
- void testPostMdcInfoForEventObject() {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(baos);
- PrintStream old = System.out;
- try {
- System.setOut(ps);
- systemOutLogger.postMdcInfoForEvent(1);
- assertTrue(baos.toString().contains("1"), baos.toString());
- } finally {
- System.out.flush();
- System.setOut(old);
- }
- }
-
-}