summaryrefslogtreecommitdiffstats
path: root/common-logging/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'common-logging/src/test/java/org')
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfoTest.java26
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/ErrorCodeMapTest.java12
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java287
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java194
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java198
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java129
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java47
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java42
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java19
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/PropertyUtilTest.java61
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java98
-rw-r--r--common-logging/src/test/java/org/onap/policy/common/logging/util/TestUtils.java28
12 files changed, 622 insertions, 519 deletions
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfoTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfoTest.java
index 1be10dae..3dd62e69 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfoTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfoTest.java
@@ -20,24 +20,22 @@
package org.onap.policy.common.logging.eelf;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import org.junit.Test;
-/**
- *
- */
public class DroolsPDPMDCInfoTest {
- /**
- * Test method for {@link org.onap.policy.common.logging.eelf.DroolsPDPMDCInfo#getMDCInfo()}.
- */
- @Test
- public void testGetMDCInfo() {
- DroolsPDPMDCInfo di = new DroolsPDPMDCInfo();
-
- assertNotNull(di.getMDCInfo());
- assertEquals("Policy.droolsPdp", di.getMDCInfo().get(Configuration.MDC_SERVICE_NAME));
- }
+ /**
+ * Test method for {@link org.onap.policy.common.logging.eelf.DroolsPDPMDCInfo#getMDCInfo()}.
+ */
+ @Test
+ public 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
index ed4c879f..781be600 100644
--- 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
@@ -17,9 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.common.logging.eelf;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import org.junit.Test;
import org.onap.policy.common.logging.eelf.ErrorCodeMap.ErrorCodeInfo;
@@ -40,17 +43,18 @@ public class ErrorCodeMapTest {
assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.ERROR_UNKNOWN));
assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.ERROR_AUDIT));
}
-
+
@Test
public void testErrorCodeInfoGetErrorCode() {
ErrorCodeInfo errorCodeInfo = ErrorCodeMap.getErrorCodeInfo(MessageCodes.EXCEPTION_ERROR);
assertEquals("POLICY-503E", errorCodeInfo.getErrorCode());
}
-
+
@Test
public void testErrorCodeInfoGetErrorDesc() {
ErrorCodeInfo errorCodeInfo = ErrorCodeMap.getErrorCodeInfo(MessageCodes.EXCEPTION_ERROR);
- assertEquals("This is an exception error message during the process. Please check the error message for detail information", errorCodeInfo.getErrorDesc());
+ 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
index edd57ee1..f7aa733a 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java
@@ -20,155 +20,154 @@
package org.onap.policy.common.logging.eelf;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.time.Instant;
import org.junit.Test;
-/**
- *
- */
public 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
- public void testEventData() {
- EventData d = new EventData();
-
- assertNull(d.getEndTime());
- assertNull(d.getRequestID());
- assertNull(d.getStartTime());
- }
-
- /**
- * Test method for {@link EventData#EventData(String, Instant, Instant)}.
- */
- @Test
- public void testEventDataStringInstantInstant() {
- EventData d = new EventData("myreq", istart, iend);
-
- assertEquals("myreq", d.getRequestID());
- assertEquals(istart, d.getStartTime());
- assertEquals(iend, d.getEndTime());
- }
-
- /**
- * Test method for {@link EventData#getRequestID()} and
- * {@link EventData#setRequestID(String)}.
- */
- @Test
- public void testGetSetRequestID() {
- EventData d = new EventData();
- assertNull(d.getRequestID());
-
- d.setRequestID("abc");
- assertEquals("abc", d.getRequestID());
-
- d.setRequestID("def");
- assertEquals("def", d.getRequestID());
- }
-
- /**
- * Test method for {@link EventData#getStartTime()} and
- * {@link EventData#setStartTime(Instant)}.
- */
- @Test
- public void testGetSetStartTime() {
- EventData d = new EventData();
- assertNull(d.getStartTime());
-
- d.setStartTime(istart);
- assertEquals(istart, d.getStartTime());
-
- d.setStartTime(iend);
- assertEquals(iend, d.getStartTime());
-
- // setting end-time should not effect start-time
- d.setEndTime(istart);
- assertEquals(iend, d.getStartTime());
- }
-
- /**
- * Test method for {@link EventData#getEndTime()} and
- * {@link EventData#setEndTime(Instant)}.
- */
- @Test
- public void testGetSetEndTime() {
- EventData d = new EventData();
- assertNull(d.getEndTime());
-
- d.setEndTime(iend);
- assertEquals(iend, d.getEndTime());
-
- d.setEndTime(istart);
- assertEquals(istart, d.getEndTime());
-
- // setting start-time should not effect end-time
- d.setStartTime(iend);
- assertEquals(istart, d.getEndTime());
- }
-
- /**
- * Test method for {@link EventData#toString()}.
- */
- @Test
- public void testToString() {
- EventData d = new EventData("myreq", istart, iend);
- assertEquals("myreq Starting Time : 1970-01-01T00:01:40Z Ending Time : 1970-01-01T00:03:20Z", d.toString());
- }
-
- /**
- * Test method for {@link EventData#hashCode()}.
- */
- @Test
- public 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
- public void testEqualsObject() {
- EventData d1 = new EventData("abc", istart, iend);
- EventData d2 = new EventData("abd", istart, iend);
- EventData d3 = new EventData("abc", iend, istart);
-
- // same object
- assertTrue(d1.equals(d1));
-
- // compare with null
- assertFalse(d1.equals(null));
-
- // compare with request id
- assertTrue(d1.equals("abc"));
- assertFalse(d1.equals("abd"));
-
- // compare with int - different class type
- assertFalse(d1.equals(10));
-
- // "this" has null request id
- assertFalse(new EventData().equals(d1));
-
- // both null
- assertTrue(new EventData().equals(new EventData()));
-
- // this request id is not null, other is null
- assertFalse(d1.equals(new EventData()));
-
- // neither null, same
- assertTrue(d1.equals(d3));
-
- // neither null, diff
- assertFalse(d1.equals(d2));
- }
+ private static final Instant istart = Instant.ofEpochMilli(100000L);
+ private static final Instant iend = Instant.ofEpochMilli(200000L);
+
+ /**
+ * Test method for {@link EventData#EventData()}.
+ */
+ @Test
+ public 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
+ public 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
+ public 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
+ public 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
+ public 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
+ public 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
+ public 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
+ public 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
+ assertTrue(d1.equals(d1));
+
+ // compare with null
+ assertFalse(d1.equals(null));
+
+ // compare with request id
+ assertTrue(d1.equals("abc"));
+ assertFalse(d1.equals("abd"));
+
+ // compare with int - different class type
+ assertFalse(d1.equals(10));
+
+ // "this" has null request id
+ assertFalse(new EventData().equals(d1));
+
+ // both null
+ assertTrue(new EventData().equals(new EventData()));
+
+ // this request id is not null, other is null
+ assertFalse(d1.equals(new EventData()));
+
+ // neither null, same
+ assertTrue(d1.equals(d3));
+
+ // neither null, diff
+ assertFalse(d1.equals(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
index 68fd52de..d1d5983d 100644
--- 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
@@ -20,7 +20,7 @@
package org.onap.policy.common.logging.eelf;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import java.time.Instant;
import java.util.concurrent.ConcurrentMap;
@@ -29,102 +29,102 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-/**
- *
- */
public 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;
-
- @BeforeClass
- public static void setUpBeforeClass() {
- tracker = PolicyLogger.getEventTracker();
- info = tracker.getEventInfo();
- }
-
- @Before
- public void setUp() {
- info.clear();
-
- hdlr = new EventTrackInfoHandler();
- }
-
- @Test
- public void testNoEvents() {
- hdlr.run();
- assertEquals(0, info.size());
- }
-
- @Test
- public void testNothingExpired() {
- tracker.storeEventData(data1);
- tracker.storeEventData(data2);
-
- hdlr.run();
- assertEquals(2, info.size());
- }
-
- @Test
- public 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
- public 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());
- }
+
+ 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;
+
+ @BeforeClass
+ public static void setUpBeforeClass() {
+ tracker = PolicyLogger.getEventTracker();
+ info = tracker.getEventInfo();
+ }
+
+ /**
+ * Perform set up for test cases.
+ */
+ @Before
+ public void setUp() {
+ info.clear();
+
+ hdlr = new EventTrackInfoHandler();
+ }
+
+ @Test
+ public void testNoEvents() {
+ hdlr.run();
+ assertEquals(0, info.size());
+ }
+
+ @Test
+ public void testNothingExpired() {
+ tracker.storeEventData(data1);
+ tracker.storeEventData(data2);
+
+ hdlr.run();
+ assertEquals(2, info.size());
+ }
+
+ @Test
+ public 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
+ public 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
index 3690bc5c..7dc8fddc 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java
@@ -20,111 +20,111 @@
package org.onap.policy.common.logging.eelf;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.time.Instant;
import org.junit.Before;
import org.junit.Test;
-/**
- *
- */
public 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;
-
- @Before
- public void setUp() {
- info = new EventTrackInfo();
-
- }
-
- /**
- * Test method for {@link EventTrackInfo#EventTrackInfo()}.
- */
- @Test
- public void testEventTrackInfo() {
- assertNotNull(info.getEventInfo());
- }
-
- /**
- * Test method for {@link EventTrackInfo#getEventDataByRequestID(String)}.
- */
- @Test
- public void testGetEventDataByRequestID() {
- info.storeEventData(data1);
- info.storeEventData(data2);
-
- assertTrue(data1 == info.getEventDataByRequestID("abc"));
- assertTrue(data2 == info.getEventDataByRequestID("def"));
- assertNull(info.getEventDataByRequestID("hello"));
- }
-
- /**
- * Test method for {@link EventTrackInfo#storeEventData(EventData)}.
- */
- @Test
- public 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
- assertTrue(data1 == info.getEventDataByRequestID("abc"));
- assertTrue(data2 == info.getEventDataByRequestID("def"));
-
- // doesn't replace existing value
- info.storeEventData(new EventData("abc", iend, istart));
- assertEquals(2, info.getEventInfo().size());
- assertTrue(data1 == info.getEventDataByRequestID("abc"));
- assertTrue(data2 == info.getEventDataByRequestID("def"));
- }
-
- /**
- * Test method for {@link EventTrackInfo#remove(String)}.
- */
- @Test
- public 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"));
- assertTrue(data2 == info.getEventDataByRequestID("def"));
- }
-
- /**
- * Test method for {@link EventTrackInfo#getEventInfo()}.
- */
- @Test
- public void testGetEventInfo() {
- info.storeEventData(data1);
- info.storeEventData(data2);
-
- assertEquals(2, info.getEventInfo().size());
- assertTrue(data1 == info.getEventInfo().get("abc"));
- assertTrue(data2 == info.getEventInfo().get("def"));
- }
+
+ 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;
+
+ @Before
+ public void setUp() {
+ info = new EventTrackInfo();
+
+ }
+
+ /**
+ * Test method for {@link EventTrackInfo#EventTrackInfo()}.
+ */
+ @Test
+ public void testEventTrackInfo() {
+ assertNotNull(info.getEventInfo());
+ }
+
+ /**
+ * Test method for {@link EventTrackInfo#getEventDataByRequestID(String)}.
+ */
+ @Test
+ public void testGetEventDataByRequestID() {
+ info.storeEventData(data1);
+ info.storeEventData(data2);
+
+ assertTrue(data1 == info.getEventDataByRequestID("abc"));
+ assertTrue(data2 == info.getEventDataByRequestID("def"));
+ assertNull(info.getEventDataByRequestID("hello"));
+ }
+
+ /**
+ * Test method for {@link EventTrackInfo#storeEventData(EventData)}.
+ */
+ @Test
+ public 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
+ assertTrue(data1 == info.getEventDataByRequestID("abc"));
+ assertTrue(data2 == info.getEventDataByRequestID("def"));
+
+ // doesn't replace existing value
+ info.storeEventData(new EventData("abc", iend, istart));
+ assertEquals(2, info.getEventInfo().size());
+ assertTrue(data1 == info.getEventDataByRequestID("abc"));
+ assertTrue(data2 == info.getEventDataByRequestID("def"));
+ }
+
+ /**
+ * Test method for {@link EventTrackInfo#remove(String)}.
+ */
+ @Test
+ public 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"));
+ assertTrue(data2 == info.getEventDataByRequestID("def"));
+ }
+
+ /**
+ * Test method for {@link EventTrackInfo#getEventInfo()}.
+ */
+ @Test
+ public void testGetEventInfo() {
+ info.storeEventData(data1);
+ info.storeEventData(data2);
+
+ assertEquals(2, info.getEventInfo().size());
+ assertTrue(data1 == info.getEventInfo().get("abc"));
+ assertTrue(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
index 18361ac1..8d6b6d68 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java
@@ -17,6 +17,8 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
+
package org.onap.policy.common.logging.eelf;
import static com.att.eelf.configuration.Configuration.MDC_ALERT_SEVERITY;
@@ -27,27 +29,37 @@ import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import static org.onap.policy.common.logging.eelf.Configuration.PARTNER_NAME;
import static org.onap.policy.common.logging.eelf.Configuration.RESPONSE_CODE;
import static org.onap.policy.common.logging.eelf.Configuration.RESPONSE_DESCRIPTION;
import static org.onap.policy.common.logging.eelf.Configuration.SERVER_NAME;
import static org.onap.policy.common.logging.eelf.Configuration.STATUS_CODE;
-import static org.onap.policy.common.logging.util.TestUtils.*;
+import static org.onap.policy.common.logging.util.TestUtils.overrideStaticField;
+
+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.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.slf4j.MDC;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFLogger.Level;
public class PolicyLoggerTest {
-
+
+ /**
+ * Perform set up for test cases.
+ */
@Before
- public void setUp(){
+ public void setUp() {
Properties properties = new Properties();
properties.setProperty("policy.component", "XACML");
PolicyLogger.init(properties);
@@ -72,9 +84,9 @@ public class PolicyLoggerTest {
@Test
public void testSetAndGetMetricsLevelLevel() {
PolicyLogger.setMetricsLevel(Level.INFO);
- assertEquals(Level.INFO, PolicyLogger.getMetricsLevel());
+ assertEquals(Level.INFO, PolicyLogger.getMetricsLevel());
PolicyLogger.setMetricsLevel(Level.DEBUG);
- assertEquals(Level.DEBUG, PolicyLogger.getMetricsLevel());
+ assertEquals(Level.DEBUG, PolicyLogger.getMetricsLevel());
}
@Test
@@ -95,7 +107,7 @@ public class PolicyLoggerTest {
@Test
public void testPostMDCInfoForEventString() {
PolicyLogger.postMDCInfoForEvent("transactionId");
-
+
assertEquals("", MDC.get(MDC_REMOTE_HOST));
assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
assertEquals("Policy.xacmlPdp", MDC.get(MDC_SERVICE_NAME));
@@ -107,15 +119,15 @@ public class PolicyLoggerTest {
assertEquals("N/A", MDC.get(RESPONSE_CODE));
assertEquals("N/A", MDC.get(RESPONSE_DESCRIPTION));
}
-
+
@Test
public void testPostMDCInfoForEventStringDrools() {
Properties properties = new Properties();
properties.setProperty("policy.component", "DROOLS");
PolicyLogger.init(properties);
-
+
PolicyLogger.postMDCInfoForEvent("transactionId");
-
+
assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
assertEquals("Policy.droolsPdp", MDC.get(MDC_SERVICE_NAME));
assertEquals("Policy.droolsPdp.event", MDC.get(MDC_SERVICE_INSTANCE_ID));
@@ -130,7 +142,7 @@ public class PolicyLoggerTest {
@Test
public void testPostMDCInfoForEventObject() {
PolicyLogger.postMDCInfoForEvent(1);
-
+
assertEquals("", MDC.get(MDC_REMOTE_HOST));
assertEquals("1", MDC.get(MDC_KEY_REQUEST_ID));
assertEquals("Policy.xacmlPdp", MDC.get(MDC_SERVICE_NAME));
@@ -146,7 +158,7 @@ public class PolicyLoggerTest {
@Test
public void testPostMDCInfoForTriggeredRule() {
PolicyLogger.postMDCInfoForTriggeredRule("transactionId");
-
+
assertEquals("", MDC.get(MDC_REMOTE_HOST));
assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID));
assertEquals("Policy.droolsPdp", MDC.get(MDC_SERVICE_NAME));
@@ -161,7 +173,7 @@ public class PolicyLoggerTest {
@Test
public void testPostMDCUUIDForTriggeredRule() {
PolicyLogger.postMDCUUIDForTriggeredRule(1);
-
+
assertEquals("", MDC.get(MDC_REMOTE_HOST));
assertEquals("1", MDC.get(MDC_KEY_REQUEST_ID));
assertEquals("Policy.droolsPdp", MDC.get(MDC_SERVICE_NAME));
@@ -187,7 +199,7 @@ public class PolicyLoggerTest {
overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info("str1", "str2");
Mockito.verify(mockLogger).info(MessageCodes.GENERAL_INFO, "str2");
- }
+ }
@Test
public void testInfoObject() {
@@ -202,17 +214,20 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
- Mockito.verify(mockLogger).info((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ Mockito.verify(mockLogger).info((MessageCodes) Mockito.any(),
+ Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
}
@Test
public void testInfoMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1", "str2");
- Mockito.verify(mockLogger).info((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1",
+ "str2");
+ Mockito.verify(mockLogger).info((MessageCodes) Mockito.any(),
+ Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
}
-
+
@Test
public void testWarnMessageCodesStringStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
@@ -227,7 +242,7 @@ public class PolicyLoggerTest {
overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn("str1", "str2");
Mockito.verify(mockLogger).warn(MessageCodes.GENERAL_INFO, "str2");
- }
+ }
@Test
public void testWarnObject() {
@@ -242,15 +257,18 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
- Mockito.verify(mockLogger).warn((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ Mockito.verify(mockLogger).warn((MessageCodes) Mockito.any(),
+ Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
}
@Test
public void testWarnMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1", "str2");
- Mockito.verify(mockLogger).warn((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ 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
@@ -268,7 +286,8 @@ public class PolicyLoggerTest {
PolicyLogger.error("str1", "str2");
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str2");
assertEquals("POLICY-515E", MDC.get("ErrorCode"));
- assertEquals("This is a general error message during the process. Please check the error message for detail information", MDC.get("ErrorDescription"));
+ assertEquals("This is a general error message during the process. Please check the error message for detail "
+ + "information", MDC.get("ErrorDescription"));
}
@Test
@@ -279,7 +298,8 @@ public class PolicyLoggerTest {
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str1");
assertEquals("ERROR", MDC.get("ErrorCategory"));
assertEquals("POLICY-515E", MDC.get("ErrorCode"));
- assertEquals("This is a general error message during the process. Please check the error message for detail information", MDC.get("ErrorDescription"));
+ assertEquals("This is a general error message during the process. Please check the error message for detail "
+ + "information", MDC.get("ErrorDescription"));
}
@Test
@@ -290,7 +310,8 @@ public class PolicyLoggerTest {
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "1");
assertEquals("ERROR", MDC.get("ErrorCategory"));
assertEquals("POLICY-515E", MDC.get("ErrorCode"));
- assertEquals("This is a general error message during the process. Please check the error message for detail information", MDC.get("ErrorDescription"));
+ assertEquals("This is a general error message during the process. Please check the error message for detail "
+ + "information", MDC.get("ErrorDescription"));
}
@Test
@@ -298,15 +319,18 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
- Mockito.verify(mockLogger).error((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ Mockito.verify(mockLogger).error((MessageCodes) Mockito.any(),
+ Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
}
@Test
public void testErrorMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1", "str2");
- Mockito.verify(mockLogger).error((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ 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
@@ -374,15 +398,18 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2");
- Mockito.verify(mockLogger).debug((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ Mockito.verify(mockLogger).debug((MessageCodes) Mockito.any(),
+ Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
}
@Test
public void testDebugMessageCodesStringThrowableStringArray() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
- PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1", "str2");
- Mockito.verify(mockLogger).debug((MessageCodes)Mockito.any(), Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+ 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
@@ -411,7 +438,7 @@ public class PolicyLoggerTest {
assertFalse(PolicyLogger.isWarnEnabled());
assertTrue(PolicyLogger.isWarnEnabled());
}
-
+
@Test
public void testIsInfoEnabled1() {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
@@ -459,7 +486,7 @@ public class PolicyLoggerTest {
public void testRecordAuditEventStartAndEnd() {
PolicyLogger.recordAuditEventStart("eventId");
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
-
+
PolicyLogger.recordAuditEventEnd("eventId", "rule");
assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
}
@@ -479,7 +506,7 @@ public class PolicyLoggerTest {
public void testRecordAuditEventEndStringStringString() {
PolicyLogger.recordAuditEventStart("eventId");
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
-
+
PolicyLogger.recordAuditEventEnd("eventId", "rule", "policyVersion");
assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
}
@@ -499,7 +526,7 @@ public class PolicyLoggerTest {
public void testCreatAuditEventTrackingRecordStringStringString() {
PolicyLogger.recordAuditEventStart("eventId");
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
-
+
PolicyLogger.creatAuditEventTrackingRecord("eventId", "rule", "policyVersion");
assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
}
@@ -511,7 +538,7 @@ public class PolicyLoggerTest {
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
PolicyLogger.creatAuditEventTrackingRecord(uuid, "rule");
- assertNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
+ assertNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString()));
}
@Test
@@ -544,7 +571,8 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.recordMetricEvent("eventId");
- Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(), Mockito.eq("eventId"));
+ Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
+ Mockito.eq("eventId"));
}
@Test
@@ -552,7 +580,8 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics("str1");
- Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(), Mockito.eq("str1"));
+ Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
+ Mockito.eq("str1"));
}
@Test
@@ -560,7 +589,8 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics("PolicyLoggerTest", 1);
- Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(), Mockito.eq("1"));
+ Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
+ Mockito.eq("1"));
}
@Test
@@ -568,7 +598,8 @@ public class PolicyLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
PolicyLogger.metrics(1);
- Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(), Mockito.eq("1"));
+ Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
+ Mockito.eq("1"));
}
@Test
@@ -583,7 +614,7 @@ public class PolicyLoggerTest {
public void testInitNullProperties() {
PolicyLogger.init(null);
}
-
+
@Test
public void testInit() {
Properties properties = new Properties();
@@ -597,24 +628,24 @@ public class PolicyLoggerTest {
properties.setProperty("concurrentHashMap.limit", "0");
properties.setProperty("stop.check.point", "0");
properties.setProperty("logger.property", "LOG4J");
-
+
PolicyLogger.init(properties);
}
-
+
@Test
public void testSetDebugLevelString() {
PolicyLogger.setOverrideLogbackLevel(true);
PolicyLogger.setDebugLevel("TRACE");
assertEquals(Level.TRACE, PolicyLogger.getDebugLevel());
}
-
+
@Test
public void testSetErrorLevelStringOff() {
PolicyLogger.setOverrideLogbackLevel(true);
PolicyLogger.setErrorLevel("OFF");
assertEquals(Level.OFF, PolicyLogger.getErrorLevel());
}
-
+
@Test
public void testSetErrorLevelStringOther() {
PolicyLogger.setOverrideLogbackLevel(true);
@@ -628,7 +659,7 @@ public class PolicyLoggerTest {
PolicyLogger.setMetricsLevel("OFF");
assertEquals(Level.OFF, PolicyLogger.getMetricsLevel());
}
-
+
@Test
public void testSetMetricsLevelStringOther() {
PolicyLogger.setOverrideLogbackLevel(true);
@@ -642,7 +673,7 @@ public class PolicyLoggerTest {
PolicyLogger.setAuditLevel("OFF");
assertEquals(Level.OFF, PolicyLogger.getAuditLevel());
}
-
+
@Test
public void testSetAuditLevelStringOther() {
PolicyLogger.setOverrideLogbackLevel(true);
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java
index 6d6399b2..a7e835ce 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java
@@ -17,21 +17,29 @@
* 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.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import static org.onap.policy.common.logging.util.TestUtils.overrideStaticField;
+
+import com.att.eelf.configuration.EELFLogger;
+
import java.util.UUID;
+
import org.junit.Test;
import org.mockito.Mockito;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
import org.slf4j.MDC;
-import com.att.eelf.configuration.EELFLogger;
public class EelfLoggerTest {
-
+
EelfLogger eelfLogger = new EelfLogger("EelfLoggerTest", "transactionId");
@Test
@@ -72,7 +80,7 @@ public class EelfLoggerTest {
public void testEelfLoggerStringString() {
new EelfLogger("EelfLoggerTest", "transactionId");
assertEquals("transactionId", PolicyLogger.getTransId());
- }
+ }
@Test
public void testSetAndGetTransId() {
@@ -128,7 +136,7 @@ public class EelfLoggerTest {
Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true);
assertFalse(eelfLogger.isDebugEnabled());
assertTrue(eelfLogger.isDebugEnabled());
-
+
}
@Test
@@ -193,7 +201,8 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.debug("message", new NullPointerException());
- Mockito.verify(mockLogger).debug((MessageCodes)Mockito.any(), Mockito.startsWith("message:java.lang.NullPointerException"));
+ Mockito.verify(mockLogger).debug((MessageCodes) Mockito.any(),
+ Mockito.startsWith("message:java.lang.NullPointerException"));
}
@Test
@@ -201,7 +210,8 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error("message", new NullPointerException());
- Mockito.verify(mockLogger).error((MessageCodes)Mockito.any(), Mockito.startsWith("message:java.lang.NullPointerException"));
+ Mockito.verify(mockLogger).error((MessageCodes) Mockito.any(),
+ Mockito.startsWith("message:java.lang.NullPointerException"));
eelfLogger.error("message", new NullPointerException());
}
@@ -210,7 +220,8 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.info("message", new NullPointerException());
- Mockito.verify(mockLogger).info((MessageCodes)Mockito.any(), Mockito.startsWith("message:java.lang.NullPointerException"));
+ Mockito.verify(mockLogger).info((MessageCodes) Mockito.any(),
+ Mockito.startsWith("message:java.lang.NullPointerException"));
}
@Test
@@ -218,7 +229,8 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "debugLogger", mockLogger);
eelfLogger.warn("message", new NullPointerException());
- Mockito.verify(mockLogger).warn((MessageCodes)Mockito.any(), Mockito.startsWith("message:java.lang.NullPointerException"));
+ Mockito.verify(mockLogger).warn((MessageCodes) Mockito.any(),
+ Mockito.startsWith("message:java.lang.NullPointerException"));
}
@Test
@@ -254,7 +266,7 @@ public class EelfLoggerTest {
public void testRecordAuditEventEndStringStringString() {
eelfLogger.recordAuditEventStart("eventId");
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
-
+
eelfLogger.recordAuditEventEnd("eventId", "rule", "policyVersion");
assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
}
@@ -273,7 +285,7 @@ public class EelfLoggerTest {
public void testRecordAuditEventEndStringString() {
eelfLogger.recordAuditEventStart("eventId");
assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
-
+
eelfLogger.recordAuditEventEnd("eventId", "rule");
assertNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId"));
}
@@ -306,7 +318,8 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(PolicyLogger.class, "metricsLogger", mockLogger);
eelfLogger.metrics(1);
- Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(), Mockito.eq("1"));
+ Mockito.verify(mockLogger).info(Mockito.eq(MessageCodes.RULE_METRICS_INFO), Mockito.anyString(),
+ Mockito.eq("1"));
}
@Test
@@ -314,7 +327,8 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(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"));
+ Mockito.verify(mockLogger).error((MessageCodes) Mockito.any(),
+ Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
}
@Test
@@ -323,7 +337,7 @@ public class EelfLoggerTest {
overrideStaticField(PolicyLogger.class, "errorLogger", mockLogger);
eelfLogger.error(MessageCodes.GENERAL_ERROR, "str1", "str2");
Mockito.verify(mockLogger).error(MessageCodes.GENERAL_ERROR, "str1", "str2");
-
+
}
@Test
@@ -345,8 +359,9 @@ public class EelfLoggerTest {
EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
overrideStaticField(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"));
-
+ Mockito.verify(mockLogger).warn((MessageCodes) Mockito.any(),
+ Mockito.startsWith("str1:str2:java.lang.NullPointerException"));
+
}
@Test
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java
index af7edcab..57afc9f7 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java
@@ -17,13 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.common.logging.flexlogger;
-import static org.junit.Assert.*;
-import static org.onap.policy.common.logging.util.TestUtils.*;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertSame;
+import static org.onap.policy.common.logging.util.TestUtils.overrideStaticField;
+
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
+
import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.FlexLogger.PropertiesCallBack;
@@ -32,81 +36,81 @@ public class FlexLoggerTest {
@Test
public void testGetLoggerClassOfQEelf() {
overrideStaticField(FlexLogger.class, "loggerType", LoggerType.EELF);
- Logger logger = FlexLogger.getLogger((Class)null);
- assertSame(logger, FlexLogger.getLogger((Class)null));
- assertNotEquals(logger, FlexLogger.getLogger(String.class));
+ Logger logger = FlexLogger.getLogger((Class) null);
+ assertSame(logger, FlexLogger.getLogger((Class) null));
+ assertNotEquals(logger, FlexLogger.getLogger(String.class));
}
-
+
@Test
public void testGetLoggerClassOfQLog4j() {
overrideStaticField(FlexLogger.class, "loggerType", LoggerType.LOG4J);
Logger logger = FlexLogger.getLogger(this.getClass());
assertSame(logger, FlexLogger.getLogger(this.getClass()));
}
-
+
@Test
public void testGetLoggerClassOfQSystemOut() {
overrideStaticField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger(this.getClass());
assertSame(logger, FlexLogger.getLogger(this.getClass()));
}
-
+
@Test
public void testGetLoggerStringEelf() {
overrideStaticField(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger("str1");
assertSame(logger, FlexLogger.getLogger("str1"));
}
-
+
@Test
public void testGetLoggerStringLog4j() {
overrideStaticField(FlexLogger.class, "loggerType", LoggerType.LOG4J);
Logger logger = FlexLogger.getLogger("str1");
assertSame(logger, FlexLogger.getLogger("str1"));
}
-
+
@Test
public void testGetLoggerStringSystemOut() {
overrideStaticField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger("str1");
assertSame(logger, FlexLogger.getLogger("str1"));
}
-
+
@Test
public void testGetLoggerClassOfQBooleanEelf() {
overrideStaticField(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger(this.getClass(), true);
assertSame(logger, FlexLogger.getLogger(this.getClass(), true));
}
-
+
@Test
public void testGetLoggerClassOfQBooleanLog4j() {
overrideStaticField(FlexLogger.class, "loggerType", LoggerType.LOG4J);
Logger logger = FlexLogger.getLogger(this.getClass(), true);
assertSame(logger, FlexLogger.getLogger(this.getClass(), true));
}
-
+
@Test
public void testGetLoggerClassOfQBooleanSystemOut() {
overrideStaticField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
Logger logger = FlexLogger.getLogger(this.getClass(), true);
assertSame(logger, FlexLogger.getLogger(this.getClass(), true));
}
-
+
@Test
public void testGetLoggerStringBooleanEelf() {
overrideStaticField(FlexLogger.class, "loggerType", LoggerType.EELF);
Logger logger = FlexLogger.getLogger("str1", true);
assertSame(logger, FlexLogger.getLogger("str1", true));
}
-
+
@Test
public void testGetLoggerStringBooleanLog4j() {
overrideStaticField(FlexLogger.class, "loggerType", LoggerType.LOG4J);
Logger logger = FlexLogger.getLogger("str1", true);
assertSame(logger, FlexLogger.getLogger("str1", true));
}
-
+
@Test
public void testGetLoggerStringBooleanSystemOut() {
overrideStaticField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT);
@@ -118,15 +122,15 @@ public class FlexLoggerTest {
public void testGetClassName() {
assertNotEquals("FlexLogger", new FlexLogger().getClassName());
}
-
+
@Test
- public void testPropertiesCallBack() throws IOException{
- PropertiesCallBack propertiesCallBack = new PropertiesCallBack("name");
+ public void testPropertiesCallBack() throws IOException {
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");
propertiesCallBack.propertiesChanged(PropertyUtil.getProperties("config/policyLogger.properties"), changedKeys);
}
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java
index 3650b18a..852e7f1b 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/Logger4JTest.java
@@ -17,10 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.common.logging.flexlogger;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.UUID;
+
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.junit.Test;
@@ -29,7 +36,7 @@ import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.util.TestUtils;
public class Logger4JTest {
-
+
private Logger4J logger4J = new Logger4J("str1", "Logger4JTest");
@Test
@@ -215,7 +222,8 @@ public class Logger4JTest {
TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
logger4J.setTransId("transactionId");
logger4J.error(MessageCodes.GENERAL_ERROR, new NullPointerException(), "str1", "str2");
- Mockito.verify(logger).error("transactionId|Logger4JTest|MessageCodes :" + MessageCodes.GENERAL_ERROR + "[str1, str2]");
+ Mockito.verify(logger)
+ .error("transactionId|Logger4JTest|MessageCodes :" + MessageCodes.GENERAL_ERROR + "[str1, str2]");
}
@Test
@@ -224,7 +232,8 @@ public class Logger4JTest {
TestUtils.overrideField(Logger4J.class, logger4J, "log", logger);
logger4J.setTransId("transactionId");
logger4J.error(MessageCodes.GENERAL_ERROR, "str1", "str2");
- Mockito.verify(logger).error("transactionId|Logger4JTest|MessageCode:" + MessageCodes.GENERAL_ERROR + "[str1, str2]");
+ Mockito.verify(logger)
+ .error("transactionId|Logger4JTest|MessageCode:" + MessageCodes.GENERAL_ERROR + "[str1, str2]");
}
@Test
@@ -232,7 +241,7 @@ public class Logger4JTest {
String returnedTransactionId = logger4J.postMDCInfoForEvent("transactionId");
assertEquals("transactionId", returnedTransactionId);
}
-
+
@Test
public void testPostMDCInfoForEventEmptyString() {
String returnedTransactionId = logger4J.postMDCInfoForEvent("");
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
index b4fd5362..d97df4ce 100644
--- 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
@@ -17,98 +17,105 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.common.logging.flexlogger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.logging.flexlogger.PropertyUtil.Listener;
public class PropertyUtilTest {
-
+
private static final File FILE = new File("target/test.properties");
private TestListener testListener = new TestListener();
-
+
+ /**
+ * Perform test case set up.
+ */
@Before
- public void setUp() throws IOException{
+ public void setUp() throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(FILE);
Properties properties = new Properties();
properties.put("testProperty", "testValue");
properties.store(fileOutputStream, "");
fileOutputStream.close();
}
-
+
@After
- public void tearDown() throws IOException{
+ public void tearDown() throws IOException {
PropertyUtil.stopListening(FILE, testListener);
FILE.delete();
- }
-
+ }
+
@Test
- public void testGetProperties() throws IOException{
+ public 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
- public void testPropertiesChanged() throws IOException, InterruptedException{
+ public 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, "");
-
+
assertTrue(testListener.isPropertiesChangedInvoked());
-
+
}
-
+
@Test
- public void testStopListening() throws IOException{
+ public 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
+ // 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"));
+ assertEquals("testValueNew", readProperties.getProperty("testProperty"));
}
-
+
private class TestListener implements Listener {
-
+
boolean propertiesChangedInvoked = false;
@Override
public void propertiesChanged(Properties properties, Set<String> changedKeys) {
propertiesChangedInvoked = true;
}
-
- public boolean isPropertiesChangedInvoked() throws InterruptedException{
- for (int i =0; i<20; i++){
- if (propertiesChangedInvoked){
+
+ public boolean isPropertiesChangedInvoked() throws InterruptedException {
+ for (int i = 0; i < 20; i++) {
+ if (propertiesChangedInvoked) {
return true;
}
Thread.sleep(1000);
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java
index ceec3cce..cd16a3fd 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java
@@ -17,19 +17,25 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.common.logging.flexlogger;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import com.att.eelf.configuration.EELFLogger.Level;
+
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.UUID;
+
import org.junit.Test;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.eelf.PolicyLogger;
-import com.att.eelf.configuration.EELFLogger.Level;
public class SystemOutLoggerTest {
-
+
SystemOutLogger systemOutLogger = new SystemOutLogger("SystemOutLoggerTest");
@Test
@@ -48,7 +54,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
systemOutLogger.setTransId("transactionId");
System.setOut(ps);
systemOutLogger.debug("message");
@@ -64,7 +70,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
systemOutLogger.setTransId("transactionId");
System.setOut(ps);
systemOutLogger.error("message");
@@ -80,7 +86,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
systemOutLogger.setTransId("transactionId");
System.setOut(ps);
systemOutLogger.info("message");
@@ -96,7 +102,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
systemOutLogger.setTransId("transactionId");
System.setOut(ps);
systemOutLogger.warn("message");
@@ -112,7 +118,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
systemOutLogger.setTransId("transactionId");
System.setOut(ps);
systemOutLogger.trace("message");
@@ -188,7 +194,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
systemOutLogger.setTransId("transactionId");
System.setOut(ps);
systemOutLogger.audit("message");
@@ -204,7 +210,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
systemOutLogger.setTransId("transactionId");
System.setOut(ps);
systemOutLogger.recordAuditEventStart("eventId");
@@ -220,7 +226,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
UUID uuid = UUID.randomUUID();
System.setOut(ps);
systemOutLogger.recordAuditEventStart(uuid);
@@ -236,7 +242,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
System.setOut(ps);
systemOutLogger.recordAuditEventEnd("eventId", "rule", "policyVersion");
assertTrue(baos.toString().contains("SystemOutLoggerTest : eventId:rule:policyVersion"));
@@ -251,7 +257,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
UUID uuid = UUID.randomUUID();
System.setOut(ps);
systemOutLogger.recordAuditEventEnd(uuid, "rule", "policyVersion");
@@ -267,7 +273,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
System.setOut(ps);
systemOutLogger.recordAuditEventEnd("eventId", "rule");
assertTrue(baos.toString().contains("SystemOutLoggerTest : eventId:rule"));
@@ -282,7 +288,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
UUID uuid = UUID.randomUUID();
System.setOut(ps);
systemOutLogger.recordAuditEventEnd(uuid, "rule");
@@ -298,7 +304,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
System.setOut(ps);
systemOutLogger.recordMetricEvent("eventId", "rule");
assertTrue(baos.toString(), baos.toString().contains("SystemOutLoggerTest : eventId:eventIdmessage:rule"));
@@ -313,7 +319,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
UUID uuid = UUID.randomUUID();
System.setOut(ps);
systemOutLogger.recordMetricEvent(uuid, "str1");
@@ -329,7 +335,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
System.setOut(ps);
systemOutLogger.metrics("message");
assertTrue(baos.toString().contains("SystemOutLoggerTest : message"));
@@ -344,10 +350,11 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ 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]"));
+ assertTrue(baos.toString()
+ .contains("SystemOutLoggerTest : MessageCodes :" + MessageCodes.ERROR_DATA_ISSUE + "[str1, str2]"));
} finally {
System.out.flush();
System.setOut(old);
@@ -359,11 +366,12 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ 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]"));
+ assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : MessageCode:"
+ + MessageCodes.ERROR_DATA_ISSUE + "[str1, str2]"));
} finally {
System.out.flush();
System.setOut(old);
@@ -380,11 +388,12 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ 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]"));
+ assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : MessageCodes:"
+ + MessageCodes.ERROR_DATA_ISSUE + "[str1, str2]"));
} finally {
System.out.flush();
System.setOut(old);
@@ -396,11 +405,12 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ 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]"));
+ assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : MessageCodes:"
+ + MessageCodes.ERROR_DATA_ISSUE + "[str1, str2]"));
} finally {
System.out.flush();
System.setOut(old);
@@ -412,15 +422,16 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
systemOutLogger.debug(1, new NullPointerException());
- assertTrue(baos.toString(), baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
+ assertTrue(baos.toString(),
+ baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
System.out.flush();
System.setOut(old);
- }
+ }
}
@Test
@@ -428,11 +439,12 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
systemOutLogger.error(1, new NullPointerException());
- assertTrue(baos.toString(), baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
+ assertTrue(baos.toString(),
+ baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
System.out.flush();
System.setOut(old);
@@ -444,11 +456,12 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
systemOutLogger.info(1, new NullPointerException());
- assertTrue(baos.toString(), baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
+ assertTrue(baos.toString(),
+ baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
System.out.flush();
System.setOut(old);
@@ -460,11 +473,12 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
systemOutLogger.warn(1, new NullPointerException());
- assertTrue(baos.toString(), baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
+ assertTrue(baos.toString(),
+ baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
System.out.flush();
System.setOut(old);
@@ -476,11 +490,12 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
systemOutLogger.trace(1, new NullPointerException());
- assertTrue(baos.toString(), baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
+ assertTrue(baos.toString(),
+ baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
System.out.flush();
System.setOut(old);
@@ -492,11 +507,12 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
System.setOut(ps);
systemOutLogger.setTransId("transactionId");
systemOutLogger.audit(1, new NullPointerException());
- assertTrue(baos.toString(), baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
+ assertTrue(baos.toString(),
+ baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"));
} finally {
System.out.flush();
System.setOut(old);
@@ -513,7 +529,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
System.setOut(ps);
systemOutLogger.postMDCInfoForTriggeredRule("transactionId");
assertTrue(baos.toString(), baos.toString().contains("transactionId"));
@@ -528,7 +544,7 @@ public class SystemOutLoggerTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
- try{
+ try {
System.setOut(ps);
systemOutLogger.postMDCInfoForEvent(1);
assertTrue(baos.toString(), baos.toString().contains("1"));
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/util/TestUtils.java b/common-logging/src/test/java/org/onap/policy/common/logging/util/TestUtils.java
index 17eee02a..94bfbb74 100644
--- a/common-logging/src/test/java/org/onap/policy/common/logging/util/TestUtils.java
+++ b/common-logging/src/test/java/org/onap/policy/common/logging/util/TestUtils.java
@@ -17,15 +17,27 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
+
package org.onap.policy.common.logging.util;
import static org.junit.Assert.fail;
+
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
public class TestUtils {
-
- public static void overrideField(@SuppressWarnings("rawtypes") final Class clazz, final Object object, final String fieldName, final Object newValue) {
+
+ /**
+ * Override a field.
+ *
+ * @param clazz the class the field belongs to
+ * @param object the instance of the class
+ * @param fieldName the name of the field
+ * @param newValue the value to set the field to
+ */
+ public static void overrideField(@SuppressWarnings("rawtypes") final Class clazz, final Object object,
+ final String fieldName, final Object newValue) {
try {
final Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
@@ -38,8 +50,16 @@ public class TestUtils {
fail(e.toString());
}
}
-
- public static void overrideStaticField(@SuppressWarnings("rawtypes") final Class clazz, final String fieldName, final Object newValue) {
+
+ /**
+ * Override a static field.
+ *
+ * @param clazz the class the field belongs to
+ * @param fieldName the name of the field
+ * @param newValue the value to set the field to
+ */
+ public static void overrideStaticField(@SuppressWarnings("rawtypes") final Class clazz, final String fieldName,
+ final Object newValue) {
try {
final Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);