aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2018-06-27 20:36:49 +0300
committervempo <vitaliy.emporopulo@amdocs.com>2018-06-27 20:36:49 +0300
commitc6a769eff2930fcf4f4dadb8106937abf86d8638 (patch)
tree2d4ed94def6a22c64f8a84c4283f0f1455346fb2 /openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core
parent0cc593ea8c181cfbcde343be45b8cf1cdd6ddbff (diff)
Improvements in audit logger for onboarding
A few optimizations, more unit-tests, log via the handling resource's logger instead of filter's logger. Change-Id: I40cef2c86a82b25ded1f8fdca1ec3b0f2fe062d8 Issue-ID: SDC-1451 Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core')
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/pom.xml8
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/RoutingTest.java224
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/HostAddressCacheTest.java10
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/InstanceIdTest.java4
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminatorTest.java48
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/CallableContextPropagationTest.java61
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextPropagationTestHelper.java14
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextTest.java16
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/GlobalContextProviderTest.java4
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/LoggerFactoryTest.java20
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/LoggingContextTest.java24
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/RequestContextProviderTest.java26
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/RunnableContextPropagationTest.java67
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java28
14 files changed, 289 insertions, 265 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/pom.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/pom.xml
index c231facfce..b30857620a 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/pom.xml
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/pom.xml
@@ -34,9 +34,9 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <version>${testng.version}</version>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -59,7 +59,7 @@
</dependency>
<dependency>
<groupId>org.powermock</groupId>
- <artifactId>powermock-module-testng</artifactId>
+ <artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/RoutingTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/RoutingTest.java
index adc1d8e71d..7be90264d6 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/RoutingTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/RoutingTest.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,132 +21,130 @@ import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.sift.SiftingAppender;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
-import org.openecomp.sdc.logging.logback.EventTypeDiscriminator;
-import org.openecomp.sdc.logging.slf4j.Markers;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openecomp.sdc.logging.logback.EventTypeDiscriminator;
+import org.openecomp.sdc.logging.slf4j.Markers;
+import org.slf4j.LoggerFactory;
/**
- * TODO: Add more negative tests
+ * Routing of events to the correct appender.
*
* @author EVITALIY
* @since 17/08/2016.
*/
public class RoutingTest {
- private static final String ERROR = "Error";
- private static final String DEBUG = "Debug";
- private static final String AUDIT = "Audit";
- private static final String METRICS = "Metrics";
-
- private Logger logger;
- private final Map<String, TestAppender> result = new ConcurrentHashMap<>();
-
- @BeforeClass
- public void setUp() {
-
- SiftingAppender appender = new SiftingAppender();
-
- EventTypeDiscriminator discriminator = new EventTypeDiscriminator();
- discriminator.start();
-
- appender.setDiscriminator(discriminator);
- appender.setAppenderFactory((context, discriminatingValue) ->
- result.computeIfAbsent(discriminatingValue, f -> {
- TestAppender tmp = new TestAppender();
- tmp.start();
- return tmp;
- }));
-
- appender.start();
-
- logger = (Logger) LoggerFactory.getLogger(RoutingTest.class.getName());
- // prevent from writing into appenders attached via parent loggers
- logger.setAdditive(false);
- logger.addAppender(appender);
- logger.setLevel(Level.DEBUG);
- }
-
- @Test
- public void testWarning() {
- String msg = "This is a test warning";
- logger.warn(msg);
- TestAppender appender = result.get(ERROR);
- Assert.assertTrue(appender.contains((event) ->
- Level.WARN.equals(event.getLevel()) && msg.equals(event.getFormattedMessage())));
- }
-
- @Test
- public void testError() {
- String msg = "This is a test error";
- logger.error(msg);
- TestAppender appender = result.get(ERROR);
- Assert.assertTrue(appender.contains((event) ->
- Level.ERROR.equals(event.getLevel()) && msg.equals(event.getFormattedMessage())));
- }
-
- @Test
- public void testDebug() {
- String msg = "This is a test debug";
- logger.debug(msg);
- TestAppender appender = result.get(DEBUG);
- Assert.assertTrue(appender.contains((event) ->
- Level.DEBUG.equals(event.getLevel()) && msg.equals(event.getFormattedMessage())));
- }
-
- @Test
- public void testInfo() {
- String msg = "This is a test info";
- logger.info(msg);
- TestAppender appender = result.get(ERROR);
- Assert.assertTrue(appender.contains((event) ->
- Level.INFO.equals(event.getLevel()) && msg.equals(event.getFormattedMessage())));
- }
-
- @Test
- public void testAudit() {
- String msg = "This is a test audit";
- logger.info(Markers.AUDIT, msg);
- TestAppender appender = result.get(AUDIT);
- Assert.assertTrue(appender.contains((event) ->
- Level.INFO.equals(event.getLevel()) && msg.equals(event.getFormattedMessage())));
- }
-
- @Test
- public void testMetrics() {
- String msg = "This is a test metrics";
- logger.info(Markers.METRICS, msg);
- TestAppender appender = result.get(METRICS);
- Assert.assertTrue(appender.contains((event) ->
- Level.INFO.equals(event.getLevel()) && msg.equals(event.getFormattedMessage())));
- }
-
- /**
- * An appender that just accumulates messages in a list and enables to inspect them
- *
- * @author EVITALIY
- * @since 17/08/2016.
- */
- private static class TestAppender extends AppenderBase<ILoggingEvent> {
-
- private final List<ILoggingEvent> events = Collections.synchronizedList(new ArrayList<>(10));
-
- @Override
- protected void append(ILoggingEvent event) {
- this.events.add(event);
+ private static final String ERROR = "Error";
+ private static final String DEBUG = "Debug";
+ private static final String AUDIT = "Audit";
+ private static final String METRICS = "Metrics";
+ private static final Map<String, TestAppender> result = new ConcurrentHashMap<>();
+ private static Logger logger;
+
+ @BeforeClass
+ public static void setUp() {
+
+ SiftingAppender appender = new SiftingAppender();
+
+ EventTypeDiscriminator discriminator = new EventTypeDiscriminator();
+ discriminator.start();
+
+ appender.setDiscriminator(discriminator);
+ appender.setAppenderFactory((context,
+ discriminatingValue) -> result.computeIfAbsent(discriminatingValue, f -> {
+ TestAppender tmp = new TestAppender();
+ tmp.start();
+ return tmp;
+ }));
+
+ appender.start();
+
+ logger = (Logger) LoggerFactory.getLogger(RoutingTest.class.getName());
+ // prevent from writing into appenders attached via parent loggers
+ logger.setAdditive(false);
+ logger.addAppender(appender);
+ logger.setLevel(Level.DEBUG);
}
- boolean contains(Predicate<ILoggingEvent> predicate) {
- return events.stream().anyMatch(predicate);
+ @Test
+ public void testWarning() {
+ String msg = "This is a test warning";
+ logger.warn(msg);
+ TestAppender appender = result.get(ERROR);
+ Assert.assertTrue(appender.contains(
+ (event) -> Level.WARN.equals(event.getLevel()) && msg.equals(event.getFormattedMessage())));
+ }
+
+ @Test
+ public void testError() {
+ String msg = "This is a test error";
+ logger.error(msg);
+ TestAppender appender = result.get(ERROR);
+ Assert.assertTrue(appender.contains(
+ (event) -> Level.ERROR.equals(event.getLevel()) && msg.equals(event.getFormattedMessage())));
+ }
+
+ @Test
+ public void testDebug() {
+ String msg = "This is a test debug";
+ logger.debug(msg);
+ TestAppender appender = result.get(DEBUG);
+ Assert.assertTrue(appender.contains(
+ (event) -> Level.DEBUG.equals(event.getLevel()) && msg.equals(event.getFormattedMessage())));
+ }
+
+ @Test
+ public void testInfo() {
+ String msg = "This is a test info";
+ logger.info(msg);
+ TestAppender appender = result.get(ERROR);
+ Assert.assertTrue(appender.contains(
+ (event) -> Level.INFO.equals(event.getLevel()) && msg.equals(event.getFormattedMessage())));
+ }
+
+ @Test
+ public void testAudit() {
+ String msg = "This is a test audit";
+ logger.info(Markers.AUDIT, msg);
+ TestAppender appender = result.get(AUDIT);
+ Assert.assertTrue(appender.contains(
+ (event) -> Level.INFO.equals(event.getLevel()) && msg.equals(event.getFormattedMessage())));
+ }
+
+ @Test
+ public void testMetrics() {
+ String msg = "This is a test metrics";
+ logger.info(Markers.METRICS, msg);
+ TestAppender appender = result.get(METRICS);
+ Assert.assertTrue(appender.contains(
+ (event) -> Level.INFO.equals(event.getLevel()) && msg.equals(event.getFormattedMessage())));
+ }
+
+ /**
+ * An appender that just accumulates messages in a list and enables to inspect them.
+ *
+ * @author EVITALIY
+ * @since 17/08/2016.
+ */
+ private static class TestAppender extends AppenderBase<ILoggingEvent> {
+
+ private final List<ILoggingEvent> events = Collections.synchronizedList(new ArrayList<>(10));
+
+ @Override
+ protected void append(ILoggingEvent event) {
+ this.events.add(event);
+ }
+
+ boolean contains(Predicate<ILoggingEvent> predicate) {
+ return events.stream().anyMatch(predicate);
+ }
}
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/HostAddressCacheTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/HostAddressCacheTest.java
index f75b634177..512de191c0 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/HostAddressCacheTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/HostAddressCacheTest.java
@@ -16,15 +16,16 @@
package org.openecomp.sdc.logging.context;
-import static org.testng.Assert.assertTrue;
+import static org.junit.Assert.assertTrue;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.easymock.EasyMock;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.testng.PowerMockTestCase;
-import org.testng.annotations.Test;
+import org.powermock.modules.junit4.PowerMockRunner;
/**
* Retrieval and caching of host address.
@@ -33,7 +34,8 @@ import org.testng.annotations.Test;
* @since 28 Mar 2018
*/
@PrepareForTest(InetAddress.class)
-public class HostAddressCacheTest extends PowerMockTestCase {
+@RunWith(PowerMockRunner.class)
+public class HostAddressCacheTest {
@Test
public void hostAddressIsAlwaysPopulated() {
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/InstanceIdTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/InstanceIdTest.java
index 984cb3bade..7afa3a2512 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/InstanceIdTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/InstanceIdTest.java
@@ -16,9 +16,9 @@
package org.openecomp.sdc.logging.context;
-import static org.testng.Assert.assertNotNull;
+import static org.junit.Assert.assertNotNull;
-import org.testng.annotations.Test;
+import org.junit.Test;
/**
* Retrieval of instance ID.
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminatorTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminatorTest.java
index 050c583346..2a71f72063 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminatorTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminatorTest.java
@@ -16,15 +16,17 @@
package org.openecomp.sdc.logging.logback;
+import static org.junit.Assert.assertEquals;
+
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.LoggingEvent;
+import org.junit.Test;
import org.openecomp.sdc.logging.slf4j.Markers;
import org.slf4j.MarkerFactory;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
/**
+ * Test categorizing of events.
+ *
* @author EVITALIY
* @since 17/08/2016.
*/
@@ -37,7 +39,7 @@ public class EventTypeDiscriminatorTest {
public void testGetDefaultDiscriminatingValue() {
EventTypeDiscriminator discriminator = new EventTypeDiscriminator();
LoggingEvent event = new LoggingEvent();
- assertEquals(discriminator.getDiscriminatingValue(event), DEBUG);
+ assertEquals(DEBUG, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -45,7 +47,7 @@ public class EventTypeDiscriminatorTest {
EventTypeDiscriminator discriminator = new EventTypeDiscriminator();
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.ERROR);
- assertEquals(discriminator.getDiscriminatingValue(event), ERROR);
+ assertEquals(ERROR, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -53,7 +55,7 @@ public class EventTypeDiscriminatorTest {
EventTypeDiscriminator discriminator = new EventTypeDiscriminator();
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.WARN);
- assertEquals(discriminator.getDiscriminatingValue(event), ERROR);
+ assertEquals(ERROR, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -61,7 +63,7 @@ public class EventTypeDiscriminatorTest {
EventTypeDiscriminator discriminator = new EventTypeDiscriminator();
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.INFO);
- assertEquals(discriminator.getDiscriminatingValue(event), ERROR);
+ assertEquals(ERROR, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -69,7 +71,7 @@ public class EventTypeDiscriminatorTest {
EventTypeDiscriminator discriminator = new EventTypeDiscriminator();
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.TRACE);
- assertEquals(discriminator.getDiscriminatingValue(event), DEBUG);
+ assertEquals(DEBUG, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -78,7 +80,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.ERROR);
event.setMarker(Markers.AUDIT);
- assertEquals(discriminator.getDiscriminatingValue(event), ERROR);
+ assertEquals(ERROR, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -87,7 +89,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.ERROR);
event.setMarker(Markers.METRICS);
- assertEquals(discriminator.getDiscriminatingValue(event), ERROR);
+ assertEquals(ERROR, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -96,7 +98,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.WARN);
event.setMarker(Markers.AUDIT);
- assertEquals(discriminator.getDiscriminatingValue(event), ERROR);
+ assertEquals(ERROR, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -105,7 +107,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.WARN);
event.setMarker(Markers.METRICS);
- assertEquals(discriminator.getDiscriminatingValue(event), ERROR);
+ assertEquals(ERROR, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -114,7 +116,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.DEBUG);
event.setMarker(Markers.AUDIT);
- assertEquals(discriminator.getDiscriminatingValue(event), DEBUG);
+ assertEquals(DEBUG, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -123,7 +125,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.DEBUG);
event.setMarker(Markers.METRICS);
- assertEquals(discriminator.getDiscriminatingValue(event), DEBUG);
+ assertEquals(DEBUG, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -132,7 +134,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.TRACE);
event.setMarker(Markers.AUDIT);
- assertEquals(discriminator.getDiscriminatingValue(event), DEBUG);
+ assertEquals(DEBUG, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -141,7 +143,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.TRACE);
event.setMarker(Markers.METRICS);
- assertEquals(discriminator.getDiscriminatingValue(event), DEBUG);
+ assertEquals(DEBUG, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -150,7 +152,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.ERROR);
event.setMarker(MarkerFactory.getMarker("Dummy"));
- assertEquals(discriminator.getDiscriminatingValue(event), ERROR);
+ assertEquals(ERROR, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -159,7 +161,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.WARN);
event.setMarker(MarkerFactory.getMarker("Dummy"));
- assertEquals(discriminator.getDiscriminatingValue(event), ERROR);
+ assertEquals(ERROR, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -168,7 +170,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.DEBUG);
event.setMarker(MarkerFactory.getMarker("Dummy"));
- assertEquals(discriminator.getDiscriminatingValue(event), DEBUG);
+ assertEquals(DEBUG, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -177,7 +179,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.TRACE);
event.setMarker(MarkerFactory.getMarker("Dummy"));
- assertEquals(discriminator.getDiscriminatingValue(event), DEBUG);
+ assertEquals(DEBUG, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -186,7 +188,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.INFO);
event.setMarker(MarkerFactory.getMarker("Dummy"));
- assertEquals(discriminator.getDiscriminatingValue(event), ERROR);
+ assertEquals(ERROR, discriminator.getDiscriminatingValue(event));
}
@Test
@@ -195,7 +197,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.INFO);
event.setMarker(Markers.AUDIT);
- assertEquals(discriminator.getDiscriminatingValue(event), "Audit");
+ assertEquals("Audit", discriminator.getDiscriminatingValue(event));
}
@Test
@@ -204,7 +206,7 @@ public class EventTypeDiscriminatorTest {
LoggingEvent event = new LoggingEvent();
event.setLevel(Level.INFO);
event.setMarker(Markers.METRICS);
- assertEquals(discriminator.getDiscriminatingValue(event), "Metrics");
+ assertEquals("Metrics", discriminator.getDiscriminatingValue(event));
}
@Test
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/CallableContextPropagationTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/CallableContextPropagationTest.java
index 897a87193f..e8aaa47649 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/CallableContextPropagationTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/CallableContextPropagationTest.java
@@ -16,6 +16,8 @@
package org.openecomp.sdc.logging.slf4j;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.EXPECT_EMPTY;
import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.EXPECT_EXCEPTION_FROM_INNER;
import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.EXPECT_INNER_RUN;
@@ -32,7 +34,6 @@ import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.IS_SU
import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.assertContextEmpty;
import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.assertContextFields;
import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.putUniqueValues;
-import static org.testng.Assert.assertTrue;
import java.util.Map;
import java.util.concurrent.Callable;
@@ -41,8 +42,9 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.junit.Before;
+import org.junit.Test;
import org.openecomp.sdc.logging.spi.LoggingContextService;
-import org.testng.annotations.Test;
/**
* Tests propagation of logging fields to Callable via the logging service.
@@ -55,7 +57,12 @@ public class CallableContextPropagationTest {
private final LoggingContextService ctxService = new SLF4JLoggingServiceProvider();
- @Test(enabled = IS_SUITABLE_LOGBACK_VERSION)
+ @Before
+ public void checkSuitableLogbackVersion() {
+ assumeTrue(IS_SUITABLE_LOGBACK_VERSION);
+ }
+
+ @Test
public void testContextPropagated() throws Exception {
Map<ContextField, String> values = putUniqueValues();
@@ -63,16 +70,16 @@ public class CallableContextPropagationTest {
// pass the callable to the context service first
execute(ctxService.copyToCallable(() -> {
- assertContextFields(values, EXPECT_PROPAGATED_TO_CHILD);
+ assertContextFields(EXPECT_PROPAGATED_TO_CHILD, values);
complete.set(true);
return null;
}));
- assertContextFields(values, EXPECT_RETAINED_IN_CURRENT);
- assertTrue(complete.get(), EXPECT_INNER_RUN);
+ assertContextFields(EXPECT_RETAINED_IN_CURRENT, values);
+ assertTrue(EXPECT_INNER_RUN, complete.get());
}
- @Test(enabled = IS_SUITABLE_LOGBACK_VERSION)
+ @Test
public void testContextReplacement() throws Exception {
Map<ContextField, String> innerValues = putUniqueValues();
@@ -80,7 +87,7 @@ public class CallableContextPropagationTest {
// should run with the context of main thread
Callable inner = ctxService.copyToCallable(() -> {
- assertContextFields(innerValues, EXPECT_PROPAGATED_TO_CHILD);
+ assertContextFields(EXPECT_PROPAGATED_TO_CHILD, innerValues);
innerComplete.set(true);
return null;
});
@@ -90,17 +97,17 @@ public class CallableContextPropagationTest {
execute(() -> {
Map<ContextField, String> outerValues = putUniqueValues();
inner.call();
- assertContextFields(outerValues, EXPECT_REPLACED_WITH_STORED);
+ assertContextFields(EXPECT_REPLACED_WITH_STORED, outerValues);
outerComplete.set(true);
return null;
});
- assertContextFields(innerValues, EXPECT_RETAINED_IN_CURRENT);
- assertTrue(outerComplete.get(), EXPECT_OUTER_RUN);
- assertTrue(innerComplete.get(), EXPECT_INNER_RUN);
+ assertContextFields(EXPECT_RETAINED_IN_CURRENT, innerValues);
+ assertTrue(EXPECT_OUTER_RUN, outerComplete.get());
+ assertTrue(EXPECT_INNER_RUN, innerComplete.get());
}
- @Test(enabled = IS_SUITABLE_LOGBACK_VERSION)
+ @Test
public void testContextRemainsEmpty() throws Exception {
ctxService.clear();
@@ -114,10 +121,10 @@ public class CallableContextPropagationTest {
}));
assertContextEmpty(EXPECT_EMPTY);
- assertTrue(complete.get(), EXPECT_INNER_RUN);
+ assertTrue(EXPECT_INNER_RUN, complete.get());
}
- @Test(enabled = IS_SUITABLE_LOGBACK_VERSION)
+ @Test
public void testContextCleanedUp() throws Exception {
Map<ContextField, String> innerValues = putUniqueValues();
@@ -125,7 +132,7 @@ public class CallableContextPropagationTest {
AtomicBoolean innerComplete = new AtomicBoolean(false);
// should run with the context of main thread
Callable inner = ctxService.copyToCallable((() -> {
- assertContextFields(innerValues, EXPECT_PROPAGATED_TO_CHILD);
+ assertContextFields(EXPECT_PROPAGATED_TO_CHILD, innerValues);
innerComplete.set(true);
return null;
}));
@@ -140,12 +147,12 @@ public class CallableContextPropagationTest {
return null;
});
- assertContextFields(innerValues, EXPECT_RETAINED_IN_PARENT);
- assertTrue(outerComplete.get(), EXPECT_OUTER_RUN);
- assertTrue(innerComplete.get(), EXPECT_INNER_RUN);
+ assertContextFields(EXPECT_RETAINED_IN_PARENT, innerValues);
+ assertTrue(EXPECT_OUTER_RUN, outerComplete.get());
+ assertTrue(EXPECT_INNER_RUN, innerComplete.get());
}
- @Test(enabled = IS_SUITABLE_LOGBACK_VERSION)
+ @Test
public void testCleanupAfterError() throws Exception {
Map<ContextField, String> innerValues = putUniqueValues();
@@ -153,7 +160,7 @@ public class CallableContextPropagationTest {
// should run with the context of main thread
AtomicBoolean innerComplete = new AtomicBoolean(false);
Callable inner = ctxService.copyToCallable(() -> {
- assertContextFields(innerValues, EXPECT_PROPAGATED_TO_CHILD);
+ assertContextFields(EXPECT_PROPAGATED_TO_CHILD, innerValues);
innerComplete.set(true);
throw new IllegalArgumentException();
});
@@ -164,24 +171,24 @@ public class CallableContextPropagationTest {
execute(() -> {
Map<ContextField, String> outerValues = putUniqueValues();
- assertContextFields(outerValues, EXPECT_POPULATED);
+ assertContextFields(EXPECT_POPULATED, outerValues);
try {
inner.call();
} catch (IllegalArgumentException e) {
exceptionThrown.set(true);
} finally {
- assertContextFields(outerValues, EXPECT_REVERTED_ON_EXCEPTION);
+ assertContextFields(EXPECT_REVERTED_ON_EXCEPTION, outerValues);
outerComplete.set(true);
}
return null;
});
- assertContextFields(innerValues, EXPECT_RETAINED_IN_PARENT);
- assertTrue(outerComplete.get(), EXPECT_OUTER_RUN);
- assertTrue(innerComplete.get(), EXPECT_INNER_RUN);
- assertTrue(exceptionThrown.get(), EXPECT_EXCEPTION_FROM_INNER);
+ assertContextFields(EXPECT_RETAINED_IN_PARENT, innerValues);
+ assertTrue(EXPECT_OUTER_RUN, outerComplete.get());
+ assertTrue(EXPECT_INNER_RUN, innerComplete.get());
+ assertTrue(EXPECT_EXCEPTION_FROM_INNER, exceptionThrown.get());
}
private void execute(Callable<Object> callable) throws Exception {
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextPropagationTestHelper.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextPropagationTestHelper.java
index fccc6ba59a..eb74e2a05c 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextPropagationTestHelper.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextPropagationTestHelper.java
@@ -16,8 +16,8 @@
package org.openecomp.sdc.logging.slf4j;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import java.util.EnumMap;
import java.util.Map;
@@ -44,6 +44,10 @@ class ContextPropagationTestHelper {
static final String EXPECT_REVERTED_ON_EXCEPTION = "Expected context data to be reverted even in case of exception";
static final String EXPECT_EXCEPTION_FROM_INNER = "Expected the inner class to throw exception";
+ private ContextPropagationTestHelper() {
+ // prevent instantiation
+ }
+
static Map<ContextField, String> putUniqueValues() {
Map<ContextField, String> values = new EnumMap<>(ContextField.class);
@@ -59,17 +63,17 @@ class ContextPropagationTestHelper {
return values;
}
- static void assertContextFields(Map<ContextField, String> values, String error) {
+ static void assertContextFields(String error, Map<ContextField, String> values) {
for (ContextField f : ContextField.values()) {
- assertEquals(MDC.get(f.asKey()), values.get(f), error);
+ assertEquals(error, MDC.get(f.asKey()), values.get(f));
}
}
static void assertContextEmpty(String error) {
for (ContextField key : ContextField.values()) {
- assertNull(MDC.get(key.asKey()), error);
+ assertNull(error, MDC.get(key.asKey()));
}
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextTest.java
index bed5cec20e..192e66031a 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/ContextTest.java
@@ -16,13 +16,13 @@
package org.openecomp.sdc.logging.slf4j;
-import static org.testng.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
import java.util.EnumMap;
import java.util.Map;
+import org.junit.After;
+import org.junit.Test;
import org.slf4j.MDC;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.Test;
/**
* Unit-tests context replacement on MDC.
@@ -36,7 +36,7 @@ public class ContextTest {
private static final String KEY = FIELD.asKey();
private static final String VALUE = "service-name-value";
- @AfterMethod
+ @After
public void clearMdc() {
MDC.clear();
}
@@ -49,7 +49,7 @@ public class ContextTest {
MDC.put(KEY, "modified-" + VALUE);
context.replace();
- assertEquals(MDC.get(KEY), VALUE);
+ assertEquals(VALUE, MDC.get(KEY));
}
@Test
@@ -57,8 +57,8 @@ public class ContextTest {
MDC.put(KEY, VALUE);
Map<ContextField, String> old = new Context().replace();
- assertEquals(old.size(), 1);
- assertEquals(old.get(FIELD), VALUE);
+ assertEquals(1, old.size());
+ assertEquals(VALUE, old.get(FIELD));
}
@Test
@@ -68,6 +68,6 @@ public class ContextTest {
Map<ContextField, String> values = new EnumMap<>(ContextField.class);
values.put(FIELD, VALUE);
context.revert(values);
- assertEquals(MDC.get(KEY), VALUE);
+ assertEquals(VALUE, MDC.get(KEY));
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/GlobalContextProviderTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/GlobalContextProviderTest.java
index d1e4be38a6..e58c6e9b55 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/GlobalContextProviderTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/GlobalContextProviderTest.java
@@ -16,10 +16,10 @@
package org.openecomp.sdc.logging.slf4j;
-import static org.testng.Assert.assertNotNull;
+import static org.junit.Assert.assertNotNull;
import java.util.Map;
-import org.testng.annotations.Test;
+import org.junit.Test;
/**
* Tests data supplied by the global logging context.
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/LoggerFactoryTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/LoggerFactoryTest.java
index e04af23a91..ad3c27c247 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/LoggerFactoryTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/LoggerFactoryTest.java
@@ -16,13 +16,15 @@
package org.openecomp.sdc.logging.slf4j;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
/**
+ * Make sure the logger factory returns correct loggers.
+ *
* @author EVITALIY
* @since 08 Jan 18
*/
@@ -33,23 +35,23 @@ public class LoggerFactoryTest {
@Test
public void returnSlf4jLoggerWhenGetByClass() {
Logger logger = LoggerFactory.getLogger(LoggerFactoryTest.class);
- assertEquals(logger.getClass(), SLF4JLoggerWrapper.class);
- assertEquals(logger.getName(), CLASS_NAME);
+ assertEquals(SLF4JLoggerWrapper.class, logger.getClass());
+ assertEquals(CLASS_NAME, logger.getName());
}
@Test
public void returnSlf4jLoggerWhenGetByName() {
Logger logger = LoggerFactory.getLogger(CLASS_NAME);
- assertEquals(logger.getClass(), SLF4JLoggerWrapper.class);
- assertEquals(logger.getName(), CLASS_NAME);
+ assertEquals(SLF4JLoggerWrapper.class, logger.getClass());
+ assertEquals(CLASS_NAME, logger.getName());
}
- @Test(expectedExceptions = NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void throwNpeWhenGetByNameWithNull() {
LoggerFactory.getLogger((String) null);
}
- @Test(expectedExceptions = NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void throwNpeWhenGetByClassWithNull() {
LoggerFactory.getLogger((Class<LoggerFactoryTest>) null);
}
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/LoggingContextTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/LoggingContextTest.java
index c2cef88899..1e7cfe834f 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/LoggingContextTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/LoggingContextTest.java
@@ -16,16 +16,16 @@
package org.openecomp.sdc.logging.slf4j;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.util.UUID;
+import org.junit.After;
+import org.junit.Test;
import org.openecomp.sdc.logging.api.ContextData;
import org.openecomp.sdc.logging.api.LoggingContext;
import org.slf4j.MDC;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.Test;
/**
* Unit-testing logging context service via its facade.
@@ -35,27 +35,27 @@ import org.testng.annotations.Test;
*/
public class LoggingContextTest {
- @AfterMethod
+ @After
public void clearMdc() {
MDC.clear();
}
@Test
public void returnMdcWrapperWhenToRunnableCalled() {
- assertEquals(LoggingContext.copyToRunnable(() -> { }).getClass(), MDCRunnableWrapper.class);
+ assertEquals(MDCRunnableWrapper.class, LoggingContext.copyToRunnable(() -> { }).getClass());
}
- @Test(expectedExceptions = NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void throwNpeWhenToRunnableWithNull() {
LoggingContext.copyToRunnable(null);
}
@Test
public void returnMdcWrapperWhenToCallableCalled() {
- assertEquals(LoggingContext.copyToCallable(() -> "").getClass(), MDCCallableWrapper.class);
+ assertEquals(MDCCallableWrapper.class, LoggingContext.copyToCallable(() -> "").getClass());
}
- @Test(expectedExceptions = NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void throwNpeWhenToCallableWithNull() {
LoggingContext.copyToCallable(null);
}
@@ -82,7 +82,7 @@ public class LoggingContextTest {
MDC.put(randomKey, randomValue);
LoggingContext.clear();
- assertEquals(MDC.get(randomKey), randomValue);
+ assertEquals(randomValue, MDC.get(randomKey));
}
@Test
@@ -94,7 +94,7 @@ public class LoggingContextTest {
assertEquals(random, MDC.get(ContextField.SERVICE_NAME.asKey()));
}
- @Test(expectedExceptions = NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void throwNpeWhenContextDataNull() {
LoggingContext.put(null);
}
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/RequestContextProviderTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/RequestContextProviderTest.java
index a2d36ef085..c4c1677637 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/RequestContextProviderTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/RequestContextProviderTest.java
@@ -16,13 +16,15 @@
package org.openecomp.sdc.logging.slf4j;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
-import java.util.HashMap;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.Map;
+import org.junit.Test;
import org.openecomp.sdc.logging.api.ContextData;
-import org.testng.annotations.Test;
/**
* Unit-test retrieving values from client-provided request data.
@@ -43,7 +45,7 @@ public class RequestContextProviderTest {
final String service = "supplied-service-name";
RequestContextProvider provider =
RequestContextProvider.from(ContextData.builder().serviceName(service).build());
- assertEquals(provider.values().get(ContextField.SERVICE_NAME), service);
+ assertEquals(service, provider.values().get(ContextField.SERVICE_NAME));
}
@Test
@@ -51,7 +53,7 @@ public class RequestContextProviderTest {
final String partner = "supplied-partner-name";
RequestContextProvider provider =
RequestContextProvider.from(ContextData.builder().partnerName(partner).build());
- assertEquals(provider.values().get(ContextField.PARTNER_NAME), partner);
+ assertEquals(partner, provider.values().get(ContextField.PARTNER_NAME));
}
@Test
@@ -59,12 +61,12 @@ public class RequestContextProviderTest {
final String request = "supplied-request-id";
RequestContextProvider provider =
RequestContextProvider.from(ContextData.builder().requestId(request).build());
- assertEquals(provider.values().get(ContextField.REQUEST_ID), request);
+ assertEquals(request, provider.values().get(ContextField.REQUEST_ID));
}
@Test
public void dataEmptyWhenValuesEmpty() {
- ContextData data = RequestContextProvider.to(new HashMap<>());
+ ContextData data = RequestContextProvider.to(Collections.emptyMap());
assertNull(data.getPartnerName());
assertNull(data.getRequestId());
assertNull(data.getServiceName());
@@ -73,7 +75,7 @@ public class RequestContextProviderTest {
@Test
public void serviceNameInDataWhenSuppliedInValues() {
final String service = "values-service-name";
- HashMap<ContextField, String> values = new HashMap<>();
+ Map<ContextField, String> values = new EnumMap<>(ContextField.class);
values.put(ContextField.SERVICE_NAME, service);
ContextData data = RequestContextProvider.to(values);
assertEquals(data.getServiceName(), service);
@@ -82,7 +84,7 @@ public class RequestContextProviderTest {
@Test
public void partnerNameInDataWhenSuppliedInValues() {
final String partner = "values-partner-name";
- HashMap<ContextField, String> values = new HashMap<>();
+ Map<ContextField, String> values = new EnumMap<>(ContextField.class);
values.put(ContextField.PARTNER_NAME, partner);
ContextData data = RequestContextProvider.to(values);
assertEquals(data.getPartnerName(), partner);
@@ -91,7 +93,7 @@ public class RequestContextProviderTest {
@Test
public void requestIdInDataWhenSuppliedInValues() {
final String request = "values-request-id";
- HashMap<ContextField, String> values = new HashMap<>();
+ Map<ContextField, String> values = new EnumMap<>(ContextField.class);
values.put(ContextField.REQUEST_ID, request);
ContextData data = RequestContextProvider.to(values);
assertEquals(data.getRequestId(), request);
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/RunnableContextPropagationTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/RunnableContextPropagationTest.java
index 6f988c22d5..772a89e86f 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/RunnableContextPropagationTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/RunnableContextPropagationTest.java
@@ -16,6 +16,8 @@
package org.openecomp.sdc.logging.slf4j;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.EXPECT_EMPTY;
import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.EXPECT_EXCEPTION_FROM_INNER;
import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.EXPECT_INNER_RUN;
@@ -32,12 +34,12 @@ import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.IS_SU
import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.assertContextEmpty;
import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.assertContextFields;
import static org.openecomp.sdc.logging.slf4j.ContextPropagationTestHelper.putUniqueValues;
-import static org.testng.Assert.assertTrue;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.junit.Before;
+import org.junit.Test;
import org.openecomp.sdc.logging.spi.LoggingContextService;
-import org.testng.annotations.Test;
/**
* Unit-testing logging context propagation to Runnable.
@@ -50,7 +52,12 @@ public class RunnableContextPropagationTest {
private final LoggingContextService ctxService = new SLF4JLoggingServiceProvider();
- @Test(enabled = IS_SUITABLE_LOGBACK_VERSION)
+ @Before
+ public void checkSuitableLogbackVersion() {
+ assumeTrue(IS_SUITABLE_LOGBACK_VERSION);
+ }
+
+ @Test
public void contextNotCopiedToChildThreadByDefault() throws InterruptedException {
Map<ContextField, String> values = putUniqueValues();
@@ -66,11 +73,11 @@ public class RunnableContextPropagationTest {
thread.start();
thread.join();
- assertContextFields(values, EXPECT_RETAINED_IN_CURRENT);
- assertTrue(complete.get(), EXPECT_INNER_RUN);
+ assertContextFields(EXPECT_RETAINED_IN_CURRENT, values);
+ assertTrue(EXPECT_INNER_RUN, complete.get());
}
- @Test(enabled = IS_SUITABLE_LOGBACK_VERSION)
+ @Test
public void contextCopiedWhenToRunnableCalled() throws InterruptedException {
Map<ContextField, String> values = putUniqueValues();
@@ -78,18 +85,18 @@ public class RunnableContextPropagationTest {
// pass the runnable to the context service first
Thread thread = new Thread(ctxService.copyToRunnable(() -> {
- assertContextFields(values, EXPECT_PROPAGATED_TO_CHILD);
+ assertContextFields(EXPECT_PROPAGATED_TO_CHILD, values);
complete.set(true);
}));
thread.start();
thread.join();
- assertContextFields(values, EXPECT_RETAINED_IN_CURRENT);
- assertTrue(complete.get(), EXPECT_INNER_RUN);
+ assertContextFields(EXPECT_RETAINED_IN_CURRENT, values);
+ assertTrue(EXPECT_INNER_RUN, complete.get());
}
- @Test(enabled = IS_SUITABLE_LOGBACK_VERSION)
+ @Test
public void copiedContextRetainedEvenWhenAnotherPushed() throws InterruptedException {
Map<ContextField, String> innerValues = putUniqueValues();
@@ -97,7 +104,7 @@ public class RunnableContextPropagationTest {
// should run with the context of main thread
Runnable inner = ctxService.copyToRunnable(() -> {
- assertContextFields(innerValues, EXPECT_PROPAGATED_TO_CHILD);
+ assertContextFields(EXPECT_PROPAGATED_TO_CHILD, innerValues);
innerComplete.set(true);
});
@@ -106,19 +113,19 @@ public class RunnableContextPropagationTest {
Thread outer = new Thread(() -> {
Map<ContextField, String> outerValues = putUniqueValues();
inner.run();
- assertContextFields(outerValues, EXPECT_REPLACED_WITH_STORED);
+ assertContextFields(EXPECT_REPLACED_WITH_STORED, outerValues);
outerComplete.set(true);
});
outer.start();
outer.join();
- assertContextFields(innerValues, EXPECT_RETAINED_IN_CURRENT);
- assertTrue(outerComplete.get(), EXPECT_OUTER_RUN);
- assertTrue(innerComplete.get(), EXPECT_INNER_RUN);
+ assertContextFields(EXPECT_RETAINED_IN_CURRENT, innerValues);
+ assertTrue(EXPECT_OUTER_RUN, outerComplete.get());
+ assertTrue(EXPECT_INNER_RUN, innerComplete.get());
}
- @Test(enabled = IS_SUITABLE_LOGBACK_VERSION)
+ @Test
public void contextRemainsEmptyWhenParentWasEmpty() throws InterruptedException {
ctxService.clear();
@@ -135,17 +142,17 @@ public class RunnableContextPropagationTest {
thread.join();
assertContextEmpty(EXPECT_EMPTY);
- assertTrue(complete.get(), EXPECT_INNER_RUN);
+ assertTrue(EXPECT_INNER_RUN, complete.get());
}
- @Test(enabled = IS_SUITABLE_LOGBACK_VERSION)
+ @Test
public void childThreadCleanedUpAfterRunnableRuns() throws Exception {
Map<ContextField, String> innerValues = putUniqueValues();
AtomicBoolean innerComplete = new AtomicBoolean(false);
// should run with the context of main thread
Runnable inner = ctxService.copyToRunnable(() -> {
- assertContextFields(innerValues, EXPECT_PROPAGATED_TO_CHILD);
+ assertContextFields(EXPECT_PROPAGATED_TO_CHILD, innerValues);
innerComplete.set(true);
});
@@ -161,12 +168,12 @@ public class RunnableContextPropagationTest {
outer.start();
outer.join();
- assertContextFields(innerValues, EXPECT_RETAINED_IN_PARENT);
- assertTrue(outerComplete.get(), EXPECT_OUTER_RUN);
- assertTrue(innerComplete.get(), EXPECT_INNER_RUN);
+ assertContextFields(EXPECT_RETAINED_IN_PARENT, innerValues);
+ assertTrue(EXPECT_OUTER_RUN, outerComplete.get());
+ assertTrue(EXPECT_INNER_RUN, innerComplete.get());
}
- @Test(enabled = IS_SUITABLE_LOGBACK_VERSION)
+ @Test
public void childThreadCleanedUpAfterException() throws Exception {
Map<ContextField, String> innerValues = putUniqueValues();
@@ -174,7 +181,7 @@ public class RunnableContextPropagationTest {
// should run with the context of main thread
AtomicBoolean innerComplete = new AtomicBoolean(false);
Runnable inner = ctxService.copyToRunnable(() -> {
- assertContextFields(innerValues, EXPECT_PROPAGATED_TO_CHILD);
+ assertContextFields(EXPECT_PROPAGATED_TO_CHILD, innerValues);
innerComplete.set(true);
throw new IllegalArgumentException();
});
@@ -185,14 +192,14 @@ public class RunnableContextPropagationTest {
Thread outer = new Thread(() -> {
Map<ContextField, String> outerValues = putUniqueValues();
- assertContextFields(outerValues, EXPECT_POPULATED);
+ assertContextFields(EXPECT_POPULATED, outerValues);
try {
inner.run();
} catch (IllegalArgumentException e) {
exceptionThrown.set(true);
} finally {
- assertContextFields(outerValues, EXPECT_REVERTED_ON_EXCEPTION);
+ assertContextFields(EXPECT_REVERTED_ON_EXCEPTION, outerValues);
outerComplete.set(true);
}
});
@@ -200,9 +207,9 @@ public class RunnableContextPropagationTest {
outer.start();
outer.join();
- assertContextFields(innerValues, EXPECT_RETAINED_IN_PARENT);
- assertTrue(outerComplete.get(), EXPECT_OUTER_RUN);
- assertTrue(innerComplete.get(), EXPECT_INNER_RUN);
- assertTrue(exceptionThrown.get(), EXPECT_EXCEPTION_FROM_INNER);
+ assertContextFields(EXPECT_RETAINED_IN_PARENT, innerValues);
+ assertTrue(EXPECT_OUTER_RUN, outerComplete.get());
+ assertTrue(EXPECT_INNER_RUN, innerComplete.get());
+ assertTrue(EXPECT_EXCEPTION_FROM_INNER, exceptionThrown.get());
}
} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java
index f4a29efe8b..73dd25ccae 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/SLF4JLoggerWrapperTest.java
@@ -16,22 +16,22 @@
package org.openecomp.sdc.logging.slf4j;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.Map;
+import org.junit.Test;
import org.openecomp.sdc.logging.api.AuditData;
import org.openecomp.sdc.logging.api.MetricsData;
import org.openecomp.sdc.logging.api.StatusCode;
import org.slf4j.Logger;
import org.slf4j.MDC;
import org.slf4j.Marker;
-import org.testng.annotations.Test;
/**
* Unit-test of SLF4J implementation of Logger.
@@ -106,14 +106,14 @@ public class SLF4JLoggerWrapperTest {
public void auditStatusCodeAvailableWhenPassed() {
SpyLogger spy = createSpy();
new SLF4JLoggerWrapper(spy).audit(AuditData.builder().statusCode(StatusCode.COMPLETE).build());
- assertEquals(spy.mdc().get(AuditField.STATUS_CODE.asKey()), StatusCode.COMPLETE.name());
+ assertEquals(StatusCode.COMPLETE.name(), spy.mdc().get(AuditField.STATUS_CODE.asKey()));
}
@Test
public void metricsStatusCodeAvailableWhenPassed() {
SpyLogger spy = createSpy();
new SLF4JLoggerWrapper(spy).metrics(MetricsData.builder().statusCode(StatusCode.COMPLETE).build());
- assertEquals(spy.mdc().get(MetricsField.STATUS_CODE.asKey()), StatusCode.COMPLETE.name());
+ assertEquals(StatusCode.COMPLETE.name(), spy.mdc().get(MetricsField.STATUS_CODE.asKey()));
}
@Test
@@ -135,7 +135,7 @@ public class SLF4JLoggerWrapperTest {
final String responseCode = "AuditSpyResponse";
SpyLogger spy = createSpy();
new SLF4JLoggerWrapper(spy).audit(AuditData.builder().responseCode(responseCode).build());
- assertEquals(spy.mdc().get(AuditField.RESPONSE_CODE.asKey()), responseCode);
+ assertEquals(responseCode, spy.mdc().get(AuditField.RESPONSE_CODE.asKey()));
}
@Test
@@ -143,7 +143,7 @@ public class SLF4JLoggerWrapperTest {
final String responseCode = "MetricsSpyResponse";
SpyLogger spy = createSpy();
new SLF4JLoggerWrapper(spy).metrics(MetricsData.builder().responseCode(responseCode).build());
- assertEquals(spy.mdc().get(MetricsField.RESPONSE_CODE.asKey()), responseCode);
+ assertEquals(responseCode, spy.mdc().get(MetricsField.RESPONSE_CODE.asKey()));
}
@Test
@@ -165,7 +165,7 @@ public class SLF4JLoggerWrapperTest {
final String responseDescription = "AuditSpyDescription";
SpyLogger spy = createSpy();
new SLF4JLoggerWrapper(spy).audit(AuditData.builder().responseDescription(responseDescription).build());
- assertEquals(spy.mdc().get(AuditField.RESPONSE_DESCRIPTION.asKey()), responseDescription);
+ assertEquals(responseDescription, spy.mdc().get(AuditField.RESPONSE_DESCRIPTION.asKey()));
}
@Test
@@ -173,7 +173,7 @@ public class SLF4JLoggerWrapperTest {
final String responseDescription = "MetricsSpyDescription";
SpyLogger spy = createSpy();
new SLF4JLoggerWrapper(spy).metrics(MetricsData.builder().responseDescription(responseDescription).build());
- assertEquals(spy.mdc().get(MetricsField.RESPONSE_DESCRIPTION.asKey()), responseDescription);
+ assertEquals(responseDescription, spy.mdc().get(MetricsField.RESPONSE_DESCRIPTION.asKey()));
}
@Test
@@ -195,7 +195,7 @@ public class SLF4JLoggerWrapperTest {
final String ipAddress = "10.56.20.20";
SpyLogger spy = createSpy();
new SLF4JLoggerWrapper(spy).audit(AuditData.builder().clientIpAddress(ipAddress).build());
- assertEquals(spy.mdc().get(AuditField.CLIENT_IP_ADDRESS.asKey()), ipAddress);
+ assertEquals(ipAddress, spy.mdc().get(AuditField.CLIENT_IP_ADDRESS.asKey()));
}
@Test
@@ -203,7 +203,7 @@ public class SLF4JLoggerWrapperTest {
final String ipAddress = "10.56.20.22";
SpyLogger spy = createSpy();
new SLF4JLoggerWrapper(spy).metrics(MetricsData.builder().clientIpAddress(ipAddress).build());
- assertEquals(spy.mdc().get(MetricsField.CLIENT_IP_ADDRESS.asKey()), ipAddress);
+ assertEquals(ipAddress, spy.mdc().get(MetricsField.CLIENT_IP_ADDRESS.asKey()));
}
@Test
@@ -225,7 +225,7 @@ public class SLF4JLoggerWrapperTest {
final String targetEntity = "MetricsTargetEntity";
SpyLogger spy = createSpy();
new SLF4JLoggerWrapper(spy).metrics(MetricsData.builder().targetEntity(targetEntity).build());
- assertEquals(spy.mdc().get(MetricsField.TARGET_ENTITY.asKey()), targetEntity);
+ assertEquals(targetEntity, spy.mdc().get(MetricsField.TARGET_ENTITY.asKey()));
}
@Test
@@ -240,7 +240,7 @@ public class SLF4JLoggerWrapperTest {
final String targetEntity = "MetricsTargetVirtualEntity";
SpyLogger spy = createSpy();
new SLF4JLoggerWrapper(spy).metrics(MetricsData.builder().targetVirtualEntity(targetEntity).build());
- assertEquals(spy.mdc().get(MetricsField.TARGET_VIRTUAL_ENTITY.asKey()), targetEntity);
+ assertEquals(targetEntity, spy.mdc().get(MetricsField.TARGET_VIRTUAL_ENTITY.asKey()));
}
@Test