aboutsummaryrefslogtreecommitdiffstats
path: root/common-logging/src/test/java/org/onap/policy/common/logging/eelf
diff options
context:
space:
mode:
Diffstat (limited to 'common-logging/src/test/java/org/onap/policy/common/logging/eelf')
-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
6 files changed, 439 insertions, 407 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);