aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2018-04-25 15:28:48 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-05-01 07:29:07 +0000
commit0258442c39183fdd7e4812054d095cafdcab420d (patch)
treebb1bcfa60682f228356684145e50fa6ee94567f2 /openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org
parent65204c69a3eee5e8eeeccf9b1ed9503cdce63db5 (diff)
Expose tracing context via log context service
Tracing context must be available to application code when the application makes outbound calls. Change-Id: Ica8e1f9d8e0bd6d37688a01a64c1fbedc126801c Issue-ID: SDC-1264 Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org')
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/LoggingContextTest.java30
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/slf4j/RequestContextProviderTest.java53
2 files changed, 74 insertions, 9 deletions
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 47386d4cf3..c2cef88899 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
@@ -42,7 +42,7 @@ public class LoggingContextTest {
@Test
public void returnMdcWrapperWhenToRunnableCalled() {
- assertEquals(LoggingContext.copyToRunnable(() -> {}).getClass(), MDCRunnableWrapper.class);
+ assertEquals(LoggingContext.copyToRunnable(() -> { }).getClass(), MDCRunnableWrapper.class);
}
@Test(expectedExceptions = NullPointerException.class)
@@ -140,4 +140,32 @@ public class LoggingContextTest {
LoggingContext.put(context);
assertNotNull(MDC.get(ContextField.INSTANCE_ID.asKey()));
}
+
+ @Test
+ public void contextReturnsServiceNameWhenPut() {
+
+ String random = UUID.randomUUID().toString();
+ ContextData context = ContextData.builder().serviceName(random).build();
+ LoggingContext.put(context);
+ assertEquals(context, LoggingContext.get());
+ }
+
+ @Test
+ public void contextReturnsRequestIdWhenPut() {
+
+ String random = UUID.randomUUID().toString();
+ ContextData context = ContextData.builder().requestId(random).build();
+ LoggingContext.put(context);
+ assertEquals(context, LoggingContext.get());
+ }
+
+ @Test
+ public void contextReturnsPartnerNameWhenPut() {
+
+ String random = UUID.randomUUID().toString();
+ ContextData context = ContextData.builder().partnerName(random).build();
+ LoggingContext.put(context);
+ assertEquals(context, LoggingContext.get());
+ }
+
}
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 fa7926acef..a2d36ef085 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
@@ -17,8 +17,10 @@
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 java.util.HashMap;
import org.openecomp.sdc.logging.api.ContextData;
import org.testng.annotations.Test;
@@ -31,32 +33,67 @@ import org.testng.annotations.Test;
public class RequestContextProviderTest {
@Test
- public void valuesEmptyWhenInputEmpty() {
- RequestContextProvider provider = new RequestContextProvider(ContextData.builder().build());
+ public void valuesEmptyWhenInputDataEmpty() {
+ RequestContextProvider provider = RequestContextProvider.from(ContextData.builder().build());
assertTrue(provider.values().isEmpty());
}
@Test
- public void serviceNameReturnedWhenSupplied() {
+ public void serviceNameReturnedWhenSuppliedInData() {
final String service = "supplied-service-name";
RequestContextProvider provider =
- new RequestContextProvider(ContextData.builder().serviceName(service).build());
+ RequestContextProvider.from(ContextData.builder().serviceName(service).build());
assertEquals(provider.values().get(ContextField.SERVICE_NAME), service);
}
@Test
- public void partnerNameReturnedWhenSupplied() {
+ public void partnerNameReturnedWhenSuppliedInData() {
final String partner = "supplied-partner-name";
RequestContextProvider provider =
- new RequestContextProvider(ContextData.builder().partnerName(partner).build());
+ RequestContextProvider.from(ContextData.builder().partnerName(partner).build());
assertEquals(provider.values().get(ContextField.PARTNER_NAME), partner);
}
@Test
- public void requestIdReturnedWhenSupplied() {
+ public void requestIdReturnedWhenSuppliedInData() {
final String request = "supplied-request-id";
RequestContextProvider provider =
- new RequestContextProvider(ContextData.builder().requestId(request).build());
+ RequestContextProvider.from(ContextData.builder().requestId(request).build());
assertEquals(provider.values().get(ContextField.REQUEST_ID), request);
}
+
+ @Test
+ public void dataEmptyWhenValuesEmpty() {
+ ContextData data = RequestContextProvider.to(new HashMap<>());
+ assertNull(data.getPartnerName());
+ assertNull(data.getRequestId());
+ assertNull(data.getServiceName());
+ }
+
+ @Test
+ public void serviceNameInDataWhenSuppliedInValues() {
+ final String service = "values-service-name";
+ HashMap<ContextField, String> values = new HashMap<>();
+ values.put(ContextField.SERVICE_NAME, service);
+ ContextData data = RequestContextProvider.to(values);
+ assertEquals(data.getServiceName(), service);
+ }
+
+ @Test
+ public void partnerNameInDataWhenSuppliedInValues() {
+ final String partner = "values-partner-name";
+ HashMap<ContextField, String> values = new HashMap<>();
+ values.put(ContextField.PARTNER_NAME, partner);
+ ContextData data = RequestContextProvider.to(values);
+ assertEquals(data.getPartnerName(), partner);
+ }
+
+ @Test
+ public void requestIdInDataWhenSuppliedInValues() {
+ final String request = "values-request-id";
+ HashMap<ContextField, String> values = new HashMap<>();
+ values.put(ContextField.REQUEST_ID, request);
+ ContextData data = RequestContextProvider.to(values);
+ assertEquals(data.getRequestId(), request);
+ }
}