From e219ab7cc03e144c7217f639aec52921ab49d0d5 Mon Sep 17 00:00:00 2001 From: "Smokowski, Kevin (ks6305)" Date: Wed, 11 Sep 2019 15:07:17 +0000 Subject: Restore MDC Setup MDCSetup was renamed to AbstractFilter and made abstract. This reverts those changes Issue-ID: LOG-1128 Signed-off-by: Smokowski, Kevin (ks6305) Change-Id: I861ea441a66e5bc929e2efea22b690b4fddc3059 --- .../filter/base/AbstractAuditLogFilter.java | 2 +- .../onap/logging/filter/base/AbstractFilter.java | 222 --------------- .../filter/base/AbstractMetricLogFilter.java | 2 +- .../org/onap/logging/filter/base/MDCSetup.java | 222 +++++++++++++++ .../logging/filter/base/AbstractFilterTest.java | 301 --------------------- .../org/onap/logging/filter/base/MDCSetupTest.java | 301 +++++++++++++++++++++ .../filter/spring/SpringClientFilterTest.java | 4 +- 7 files changed, 527 insertions(+), 527 deletions(-) delete mode 100644 reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractFilter.java create mode 100644 reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java delete mode 100644 reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/AbstractFilterTest.java create mode 100644 reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java index fd4e95a..ce2f448 100644 --- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java +++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractAuditLogFilter.java @@ -26,7 +26,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; -public abstract class AbstractAuditLogFilter extends AbstractFilter { +public abstract class AbstractAuditLogFilter extends MDCSetup { protected static final Logger logger = LoggerFactory.getLogger(AbstractAuditLogFilter.class); protected void pre(SimpleMap headers, GenericRequest request, HttpServletRequest httpServletRequest) { diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractFilter.java deleted file mode 100644 index 13c88b0..0000000 --- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractFilter.java +++ /dev/null @@ -1,222 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - Logging - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.logging.filter.base; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoUnit; -import java.util.UUID; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; -import org.onap.logging.ref.slf4j.ONAPLogConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.MDC; - -public abstract class AbstractFilter { - - protected static Logger logger = LoggerFactory.getLogger(AbstractFilter.class); - - private static final String INSTANCE_UUID = UUID.randomUUID().toString(); - - protected void setInstanceID() { - MDC.put(ONAPLogConstants.MDCs.INSTANCE_UUID, INSTANCE_UUID); - } - - protected void setServerFQDN() { - String serverFQDN = ""; - InetAddress addr = null; - try { - addr = InetAddress.getLocalHost(); - serverFQDN = addr.getCanonicalHostName(); - MDC.put(ONAPLogConstants.MDCs.SERVER_IP_ADDRESS, addr.getHostAddress()); - } catch (UnknownHostException e) { - logger.warn("Cannot Resolve Host Name"); - serverFQDN = ""; - } - MDC.put(ONAPLogConstants.MDCs.SERVER_FQDN, serverFQDN); - } - - protected void setClientIPAddress(HttpServletRequest httpServletRequest) { - String clientIpAddress = ""; - if (httpServletRequest != null) { - // This logic is to avoid setting the client ip address to that of the load - // balancer in front of the application - String getForwadedFor = httpServletRequest.getHeader("X-Forwarded-For"); - if (getForwadedFor != null) { - clientIpAddress = getForwadedFor; - } else { - clientIpAddress = httpServletRequest.getRemoteAddr(); - } - } - MDC.put(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS, clientIpAddress); - } - - protected void setEntryTimeStamp() { - MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, - ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); - } - - protected String getRequestId(SimpleMap headers) { - logger.trace("Checking X-ONAP-RequestID header for requestId."); - String requestId = headers.get(ONAPLogConstants.Headers.REQUEST_ID); - if (requestId != null && !requestId.isEmpty()) { - return requestId; - } - - logger.trace("No valid X-ONAP-RequestID header value. Checking X-RequestID header for requestId."); - requestId = headers.get(Constants.HttpHeaders.HEADER_REQUEST_ID); - if (requestId != null && !requestId.isEmpty()) { - return requestId; - } - - logger.trace("No valid X-RequestID header value. Checking X-TransactionID header for requestId."); - requestId = headers.get(Constants.HttpHeaders.TRANSACTION_ID); - if (requestId != null && !requestId.isEmpty()) { - return requestId; - } - - logger.trace("No valid X-TransactionID header value. Checking X-ECOMP-RequestID header for requestId."); - requestId = headers.get(Constants.HttpHeaders.ECOMP_REQUEST_ID); - if (requestId != null && !requestId.isEmpty()) { - return requestId; - } - - logger.trace("No valid requestId headers. Generating requestId: {}", requestId); - return UUID.randomUUID().toString(); - } - - protected void setInvocationId(SimpleMap headers) { - String invocationId = headers.get(ONAPLogConstants.Headers.INVOCATION_ID); - if (invocationId == null || invocationId.isEmpty()) - invocationId = UUID.randomUUID().toString(); - MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId); - } - - protected void setInvocationIdFromMDC() { - String invocationId = MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID); - if (invocationId == null || invocationId.isEmpty()) - invocationId = UUID.randomUUID().toString(); - MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId); - } - - protected void setMDCPartnerName(SimpleMap headers) { - logger.trace("Checking X-ONAP-PartnerName header for partnerName."); - String partnerName = headers.get(ONAPLogConstants.Headers.PARTNER_NAME); - if (partnerName == null || partnerName.isEmpty()) { - logger.trace("No valid X-ONAP-PartnerName header value. Checking User-Agent header for partnerName."); - partnerName = headers.get(HttpHeaders.USER_AGENT); - if (partnerName == null || partnerName.isEmpty()) { - logger.trace("No valid User-Agent header value. Checking X-ClientID header for partnerName."); - partnerName = headers.get(Constants.HttpHeaders.CLIENT_ID); - if (partnerName == null || partnerName.isEmpty()) { - logger.trace("No valid partnerName headers. Defaulting partnerName to UNKNOWN."); - partnerName = Constants.DefaultValues.UNKNOWN; - } - } - } - MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName); - } - - protected void setLogTimestamp() { - MDC.put(ONAPLogConstants.MDCs.LOG_TIMESTAMP, - ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); - } - - protected void setElapsedTime() { - DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME; - ZonedDateTime entryTimestamp = - ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP), timeFormatter); - ZonedDateTime endTimestamp = ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter); - - MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME, - Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp))); - } - - protected void setElapsedTimeInvokeTimestamp() { - DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME; - ZonedDateTime entryTimestamp = - ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP), timeFormatter); - ZonedDateTime endTimestamp = ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter); - - MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME, - Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp))); - } - - protected void setResponseStatusCode(int code) { - String statusCode; - if (Response.Status.Family.familyOf(code).equals(Response.Status.Family.SUCCESSFUL)) { - statusCode = ONAPLogConstants.ResponseStatus.COMPLETE.toString(); - } else { - statusCode = ONAPLogConstants.ResponseStatus.ERROR.toString(); - setErrorCode(code); - setErrorDesc(code); - } - MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, statusCode); - } - - protected void setTargetEntity(ONAPComponents targetEntity) { - MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, targetEntity.toString()); - } - - protected void clearClientMDCs() { - MDC.remove(ONAPLogConstants.MDCs.INVOCATION_ID); - MDC.remove(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION); - MDC.remove(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE); - MDC.remove(ONAPLogConstants.MDCs.RESPONSE_CODE); - MDC.remove(ONAPLogConstants.MDCs.TARGET_ENTITY); - MDC.remove(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME); - MDC.remove(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP); - MDC.remove(ONAPLogConstants.MDCs.ERROR_CODE); - MDC.remove(ONAPLogConstants.MDCs.ERROR_DESC); - } - - protected void setResponseDescription(int statusCode) { - MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, Response.Status.fromStatusCode(statusCode).toString()); - } - - protected void setErrorCode(int statusCode) { - MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, String.valueOf(statusCode)); - } - - protected void setErrorDesc(int statusCode) { - MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, Response.Status.fromStatusCode(statusCode).toString()); - } - - protected String getProperty(String property) { - logger.info("Checking for system property [{}]", property); - String propertyValue = System.getProperty(property); - if (propertyValue == null || propertyValue.isEmpty()) { - logger.info("System property was null or empty. Checking environment variable for: {}", property); - propertyValue = System.getenv(property); - if (propertyValue == null || propertyValue.isEmpty()) { - logger.info("Environment variable: {} was null or empty. Returning value: {}", property, - Constants.DefaultValues.UNKNOWN); - propertyValue = Constants.DefaultValues.UNKNOWN; - } - } - return propertyValue; - } -} diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java index 7857af9..79649a2 100644 --- a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java +++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/AbstractMetricLogFilter.java @@ -31,7 +31,7 @@ import org.slf4j.MDC; import org.slf4j.Marker; import org.slf4j.MarkerFactory; -public abstract class AbstractMetricLogFilter extends AbstractFilter { +public abstract class AbstractMetricLogFilter extends MDCSetup { protected static final Logger logger = LoggerFactory.getLogger(AbstractMetricLogFilter.class); private final String partnerName; private static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN"); diff --git a/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java new file mode 100644 index 0000000..cc31c4f --- /dev/null +++ b/reference/logging-filter/logging-filter-base/src/main/java/org/onap/logging/filter/base/MDCSetup.java @@ -0,0 +1,222 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - Logging + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.logging.filter.base; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.UUID; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; + +public class MDCSetup { + + protected static Logger logger = LoggerFactory.getLogger(MDCSetup.class); + + private static final String INSTANCE_UUID = UUID.randomUUID().toString(); + + public void setInstanceID() { + MDC.put(ONAPLogConstants.MDCs.INSTANCE_UUID, INSTANCE_UUID); + } + + public void setServerFQDN() { + String serverFQDN = ""; + InetAddress addr = null; + try { + addr = InetAddress.getLocalHost(); + serverFQDN = addr.getCanonicalHostName(); + MDC.put(ONAPLogConstants.MDCs.SERVER_IP_ADDRESS, addr.getHostAddress()); + } catch (UnknownHostException e) { + logger.warn("Cannot Resolve Host Name"); + serverFQDN = ""; + } + MDC.put(ONAPLogConstants.MDCs.SERVER_FQDN, serverFQDN); + } + + public void setClientIPAddress(HttpServletRequest httpServletRequest) { + String clientIpAddress = ""; + if (httpServletRequest != null) { + // This logic is to avoid setting the client ip address to that of the load + // balancer in front of the application + String getForwadedFor = httpServletRequest.getHeader("X-Forwarded-For"); + if (getForwadedFor != null) { + clientIpAddress = getForwadedFor; + } else { + clientIpAddress = httpServletRequest.getRemoteAddr(); + } + } + MDC.put(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS, clientIpAddress); + } + + public void setEntryTimeStamp() { + MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, + ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); + } + + public String getRequestId(SimpleMap headers) { + logger.trace("Checking X-ONAP-RequestID header for requestId."); + String requestId = headers.get(ONAPLogConstants.Headers.REQUEST_ID); + if (requestId != null && !requestId.isEmpty()) { + return requestId; + } + + logger.trace("No valid X-ONAP-RequestID header value. Checking X-RequestID header for requestId."); + requestId = headers.get(Constants.HttpHeaders.HEADER_REQUEST_ID); + if (requestId != null && !requestId.isEmpty()) { + return requestId; + } + + logger.trace("No valid X-RequestID header value. Checking X-TransactionID header for requestId."); + requestId = headers.get(Constants.HttpHeaders.TRANSACTION_ID); + if (requestId != null && !requestId.isEmpty()) { + return requestId; + } + + logger.trace("No valid X-TransactionID header value. Checking X-ECOMP-RequestID header for requestId."); + requestId = headers.get(Constants.HttpHeaders.ECOMP_REQUEST_ID); + if (requestId != null && !requestId.isEmpty()) { + return requestId; + } + + logger.trace("No valid requestId headers. Generating requestId: {}", requestId); + return UUID.randomUUID().toString(); + } + + public void setInvocationId(SimpleMap headers) { + String invocationId = headers.get(ONAPLogConstants.Headers.INVOCATION_ID); + if (invocationId == null || invocationId.isEmpty()) + invocationId = UUID.randomUUID().toString(); + MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId); + } + + public void setInvocationIdFromMDC() { + String invocationId = MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID); + if (invocationId == null || invocationId.isEmpty()) + invocationId = UUID.randomUUID().toString(); + MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId); + } + + public void setMDCPartnerName(SimpleMap headers) { + logger.trace("Checking X-ONAP-PartnerName header for partnerName."); + String partnerName = headers.get(ONAPLogConstants.Headers.PARTNER_NAME); + if (partnerName == null || partnerName.isEmpty()) { + logger.trace("No valid X-ONAP-PartnerName header value. Checking User-Agent header for partnerName."); + partnerName = headers.get(HttpHeaders.USER_AGENT); + if (partnerName == null || partnerName.isEmpty()) { + logger.trace("No valid User-Agent header value. Checking X-ClientID header for partnerName."); + partnerName = headers.get(Constants.HttpHeaders.CLIENT_ID); + if (partnerName == null || partnerName.isEmpty()) { + logger.trace("No valid partnerName headers. Defaulting partnerName to UNKNOWN."); + partnerName = Constants.DefaultValues.UNKNOWN; + } + } + } + MDC.put(ONAPLogConstants.MDCs.PARTNER_NAME, partnerName); + } + + public void setLogTimestamp() { + MDC.put(ONAPLogConstants.MDCs.LOG_TIMESTAMP, + ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)); + } + + public void setElapsedTime() { + DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME; + ZonedDateTime entryTimestamp = + ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP), timeFormatter); + ZonedDateTime endTimestamp = ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter); + + MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME, + Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp))); + } + + public void setElapsedTimeInvokeTimestamp() { + DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_ZONED_DATE_TIME; + ZonedDateTime entryTimestamp = + ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP), timeFormatter); + ZonedDateTime endTimestamp = ZonedDateTime.parse(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP), timeFormatter); + + MDC.put(ONAPLogConstants.MDCs.ELAPSED_TIME, + Long.toString(ChronoUnit.MILLIS.between(entryTimestamp, endTimestamp))); + } + + public void setResponseStatusCode(int code) { + String statusCode; + if (Response.Status.Family.familyOf(code).equals(Response.Status.Family.SUCCESSFUL)) { + statusCode = ONAPLogConstants.ResponseStatus.COMPLETE.toString(); + } else { + statusCode = ONAPLogConstants.ResponseStatus.ERROR.toString(); + setErrorCode(code); + setErrorDesc(code); + } + MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, statusCode); + } + + public void setTargetEntity(ONAPComponents targetEntity) { + MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, targetEntity.toString()); + } + + public void clearClientMDCs() { + MDC.remove(ONAPLogConstants.MDCs.INVOCATION_ID); + MDC.remove(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION); + MDC.remove(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE); + MDC.remove(ONAPLogConstants.MDCs.RESPONSE_CODE); + MDC.remove(ONAPLogConstants.MDCs.TARGET_ENTITY); + MDC.remove(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME); + MDC.remove(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP); + MDC.remove(ONAPLogConstants.MDCs.ERROR_CODE); + MDC.remove(ONAPLogConstants.MDCs.ERROR_DESC); + } + + public void setResponseDescription(int statusCode) { + MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, Response.Status.fromStatusCode(statusCode).toString()); + } + + public void setErrorCode(int statusCode) { + MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, String.valueOf(statusCode)); + } + + public void setErrorDesc(int statusCode) { + MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, Response.Status.fromStatusCode(statusCode).toString()); + } + + public String getProperty(String property) { + logger.info("Checking for system property [{}]", property); + String propertyValue = System.getProperty(property); + if (propertyValue == null || propertyValue.isEmpty()) { + logger.info("System property was null or empty. Checking environment variable for: {}", property); + propertyValue = System.getenv(property); + if (propertyValue == null || propertyValue.isEmpty()) { + logger.info("Environment variable: {} was null or empty. Returning value: {}", property, + Constants.DefaultValues.UNKNOWN); + propertyValue = Constants.DefaultValues.UNKNOWN; + } + } + return propertyValue; + } +} diff --git a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/AbstractFilterTest.java b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/AbstractFilterTest.java deleted file mode 100644 index cfa74ad..0000000 --- a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/AbstractFilterTest.java +++ /dev/null @@ -1,301 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - Logging - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.logging.filter.base; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.when; -import java.util.HashMap; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MultivaluedHashMap; -import javax.ws.rs.core.MultivaluedMap; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.logging.ref.slf4j.ONAPLogConstants; -import org.slf4j.MDC; - -@RunWith(MockitoJUnitRunner.class) -public class AbstractFilterTest extends AbstractFilter { - - @Mock - private HttpServletRequest httpServletRequest; - - private String requestId = "4d31fe02-4918-4975-942f-fe51a44e6a9b"; - private String invocationId = "4d31fe02-4918-4975-942f-fe51a44e6a9a"; - - @After - public void tearDown() { - MDC.clear(); - System.clearProperty("partnerName"); - } - - @Test - public void setElapsedTimeTest() { - String expected = "318"; - MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, "2019-06-18T02:09:06.024Z"); - MDC.put(ONAPLogConstants.MDCs.LOG_TIMESTAMP, "2019-06-18T02:09:06.342Z"); - - setElapsedTime(); - assertEquals(expected, MDC.get(ONAPLogConstants.MDCs.ELAPSED_TIME)); - } - - @Test - public void setElapsedTimeInvokeTimestampTest() { - String expected = "318"; - MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, "2019-06-18T02:09:06.024Z"); - MDC.put(ONAPLogConstants.MDCs.LOG_TIMESTAMP, "2019-06-18T02:09:06.342Z"); - - setElapsedTimeInvokeTimestamp(); - assertEquals(expected, MDC.get(ONAPLogConstants.MDCs.ELAPSED_TIME)); - } - - @Test - public void setRequestIdTest() { - HashMap headers = new HashMap<>(); - headers.put(ONAPLogConstants.Headers.REQUEST_ID, requestId); - String fetchedRequestId = getRequestId(new SimpleHashMap(headers)); - assertEquals(requestId, fetchedRequestId); - } - - @Test - public void setRequestIdRequestIdHeaderTest() { - HashMap headers = new HashMap<>(); - headers.put(Constants.HttpHeaders.HEADER_REQUEST_ID, requestId); - String fetchedRequestId = getRequestId(new SimpleHashMap(headers)); - assertEquals(requestId, fetchedRequestId); - } - - @Test - public void setRequestIdTransactionIdHeaderTest() { - HashMap headers = new HashMap<>(); - headers.put(Constants.HttpHeaders.TRANSACTION_ID, requestId); - String fetchedRequestId = getRequestId(new SimpleHashMap(headers)); - assertEquals(requestId, fetchedRequestId); - } - - @Test - public void setRequestIdEcompRequestIdHeaderTest() { - HashMap headers = new HashMap<>(); - headers.put(Constants.HttpHeaders.ECOMP_REQUEST_ID, requestId); - String fetchedRequestId = getRequestId(new SimpleHashMap(headers)); - assertEquals(requestId, fetchedRequestId); - } - - @Test - public void setRequestIdNoHeaderTest() { - HashMap headers = new HashMap<>(); - String fetchedRequestId = getRequestId(new SimpleHashMap(headers)); - assertNotNull(fetchedRequestId); - } - - @Test - public void setInvocationIdTest() { - HashMap headers = new HashMap<>(); - headers.put(ONAPLogConstants.Headers.INVOCATION_ID, invocationId); - setInvocationId(new SimpleHashMap(headers)); - assertEquals(invocationId, MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); - } - - @Test - public void setInvocationIdNoHeaderTest() { - HashMap headers = new HashMap<>(); - setInvocationId(new SimpleHashMap(headers)); - assertNotNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); - } - - @Test - public void setInvovationIdFromMDCTest() { - MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, "7b77143c-9b50-410c-ac2f-05758a68e3e8"); - setInvocationIdFromMDC(); - assertEquals("7b77143c-9b50-410c-ac2f-05758a68e3e8", MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); - } - - @Test - public void setInvocationIdFromMDCNoInvocationIdTest() { - setInvocationIdFromMDC(); - // InvocationId is set to a random UUID - assertNotNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); - } - - @Test - public void setResponseStatusCodeTest() { - setResponseStatusCode(200); - assertEquals("COMPLETE", MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); - } - - @Test - public void setResponseStatusCodeErrorTest() { - setResponseStatusCode(400); - assertEquals("ERROR", MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); - assertEquals("400", MDC.get(ONAPLogConstants.MDCs.ERROR_CODE)); - assertEquals("Bad Request", MDC.get(ONAPLogConstants.MDCs.ERROR_DESC)); - } - - @Test - public void clearClientMDCsTest() { - MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, "7b77143c-9b50-410c-ac2f-05758a68e3e9"); - MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, "Bad Gateway"); - MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, "Bad Gateway"); - MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, "502"); - MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, "502"); - MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, "502"); - MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, "SO"); - MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, "SDNC"); - MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, "2019-06-18T02:09:06.024Z"); - - clearClientMDCs(); - assertNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); - assertNull(MDC.get(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION)); - assertNull(MDC.get(ONAPLogConstants.MDCs.ERROR_CODE)); - assertNull(MDC.get(ONAPLogConstants.MDCs.ERROR_DESC)); - assertNull(MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); - assertNull(MDC.get(ONAPLogConstants.MDCs.RESPONSE_CODE)); - assertNull(MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY)); - assertNull(MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME)); - assertNull(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP)); - } - - @Test - public void setTargetEntityTest() { - setTargetEntity(ONAPComponents.SO); - assertEquals("SO", MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY)); - } - - @Test - public void setResponseDescriptionTest() { - setResponseDescription(502); - assertEquals("Bad Gateway", MDC.get(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION)); - } - - @Test - public void setMDCPartnerNameTest() { - MultivaluedMap headerMap = new MultivaluedHashMap<>(); - headerMap.putSingle(ONAPLogConstants.Headers.PARTNER_NAME, "SO"); - SimpleMap headers = new SimpleJaxrsHeadersMap(headerMap); - - setMDCPartnerName(headers); - - assertEquals("SO", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); - } - - @Test - public void setMDCPartnerNameUserAgentHeaderTest() { - MultivaluedMap headerMap = new MultivaluedHashMap<>(); - headerMap.putSingle(HttpHeaders.USER_AGENT, "Apache-HttpClient/4.5.8 (Java/1.8.0_191)"); - SimpleMap headers = new SimpleJaxrsHeadersMap(headerMap); - - setMDCPartnerName(headers); - - assertEquals("Apache-HttpClient/4.5.8 (Java/1.8.0_191)", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); - } - - @Test - public void setMDCPartnerNameClientIdHeaderTest() { - MultivaluedMap headerMap = new MultivaluedHashMap<>(); - headerMap.putSingle(Constants.HttpHeaders.CLIENT_ID, "SO"); - SimpleMap headers = new SimpleJaxrsHeadersMap(headerMap); - - setMDCPartnerName(headers); - - assertEquals("SO", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); - } - - @Test - public void setMDCPartnerNameNoHeaderTest() { - MultivaluedMap headerMap = new MultivaluedHashMap<>(); - SimpleMap headers = new SimpleJaxrsHeadersMap(headerMap); - - setMDCPartnerName(headers); - - assertEquals("UNKNOWN", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); - } - - @Test - public void setServerFQDNTest() { - setServerFQDN(); - assertNotNull(MDC.get(ONAPLogConstants.MDCs.SERVER_IP_ADDRESS)); - assertNotNull(MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN)); - } - - @Test - public void setClientIPAddressTest() { - when(httpServletRequest.getHeader("X-Forwarded-For")).thenReturn("127.0.0.2"); - setClientIPAddress(httpServletRequest); - - assertEquals("127.0.0.2", MDC.get(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS)); - } - - @Test - public void setClientIPAddressNoHeaderTest() { - when(httpServletRequest.getRemoteAddr()).thenReturn("127.0.0.1"); - setClientIPAddress(httpServletRequest); - - assertEquals("127.0.0.1", MDC.get(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS)); - } - - @Test - public void setClientIPAddressNullTest() { - setClientIPAddress(null); - - assertEquals("", MDC.get(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS)); - } - - @Test - public void setEntryTimeStampTest() { - setEntryTimeStamp(); - - assertNotNull(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)); - } - - @Test - public void setLogTimestampTest() { - setLogTimestamp(); - - assertNotNull(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP)); - } - - @Test - public void setInstanceIDTest() { - setInstanceID(); - - assertNotNull(MDC.get(ONAPLogConstants.MDCs.INSTANCE_UUID)); - } - - @Test - public void getPropertyTest() { - System.setProperty("partnerName", "partnerName"); - - String partnerName = getProperty("partnerName"); - assertEquals("partnerName", partnerName); - } - - @Test - public void getPropertyNullTest() { - String partnerName = getProperty("partner"); - assertEquals("UNKNOWN", partnerName); - } - -} diff --git a/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java new file mode 100644 index 0000000..31d8da6 --- /dev/null +++ b/reference/logging-filter/logging-filter-base/src/test/java/org/onap/logging/filter/base/MDCSetupTest.java @@ -0,0 +1,301 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - Logging + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.logging.filter.base; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.when; +import java.util.HashMap; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.slf4j.MDC; + +@RunWith(MockitoJUnitRunner.class) +public class MDCSetupTest extends MDCSetup { + + @Mock + private HttpServletRequest httpServletRequest; + + private String requestId = "4d31fe02-4918-4975-942f-fe51a44e6a9b"; + private String invocationId = "4d31fe02-4918-4975-942f-fe51a44e6a9a"; + + @After + public void tearDown() { + MDC.clear(); + System.clearProperty("partnerName"); + } + + @Test + public void setElapsedTimeTest() { + String expected = "318"; + MDC.put(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP, "2019-06-18T02:09:06.024Z"); + MDC.put(ONAPLogConstants.MDCs.LOG_TIMESTAMP, "2019-06-18T02:09:06.342Z"); + + setElapsedTime(); + assertEquals(expected, MDC.get(ONAPLogConstants.MDCs.ELAPSED_TIME)); + } + + @Test + public void setElapsedTimeInvokeTimestampTest() { + String expected = "318"; + MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, "2019-06-18T02:09:06.024Z"); + MDC.put(ONAPLogConstants.MDCs.LOG_TIMESTAMP, "2019-06-18T02:09:06.342Z"); + + setElapsedTimeInvokeTimestamp(); + assertEquals(expected, MDC.get(ONAPLogConstants.MDCs.ELAPSED_TIME)); + } + + @Test + public void setRequestIdTest() { + HashMap headers = new HashMap<>(); + headers.put(ONAPLogConstants.Headers.REQUEST_ID, requestId); + String fetchedRequestId = getRequestId(new SimpleHashMap(headers)); + assertEquals(requestId, fetchedRequestId); + } + + @Test + public void setRequestIdRequestIdHeaderTest() { + HashMap headers = new HashMap<>(); + headers.put(Constants.HttpHeaders.HEADER_REQUEST_ID, requestId); + String fetchedRequestId = getRequestId(new SimpleHashMap(headers)); + assertEquals(requestId, fetchedRequestId); + } + + @Test + public void setRequestIdTransactionIdHeaderTest() { + HashMap headers = new HashMap<>(); + headers.put(Constants.HttpHeaders.TRANSACTION_ID, requestId); + String fetchedRequestId = getRequestId(new SimpleHashMap(headers)); + assertEquals(requestId, fetchedRequestId); + } + + @Test + public void setRequestIdEcompRequestIdHeaderTest() { + HashMap headers = new HashMap<>(); + headers.put(Constants.HttpHeaders.ECOMP_REQUEST_ID, requestId); + String fetchedRequestId = getRequestId(new SimpleHashMap(headers)); + assertEquals(requestId, fetchedRequestId); + } + + @Test + public void setRequestIdNoHeaderTest() { + HashMap headers = new HashMap<>(); + String fetchedRequestId = getRequestId(new SimpleHashMap(headers)); + assertNotNull(fetchedRequestId); + } + + @Test + public void setInvocationIdTest() { + HashMap headers = new HashMap<>(); + headers.put(ONAPLogConstants.Headers.INVOCATION_ID, invocationId); + setInvocationId(new SimpleHashMap(headers)); + assertEquals(invocationId, MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + } + + @Test + public void setInvocationIdNoHeaderTest() { + HashMap headers = new HashMap<>(); + setInvocationId(new SimpleHashMap(headers)); + assertNotNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + } + + @Test + public void setInvovationIdFromMDCTest() { + MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, "7b77143c-9b50-410c-ac2f-05758a68e3e8"); + setInvocationIdFromMDC(); + assertEquals("7b77143c-9b50-410c-ac2f-05758a68e3e8", MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + } + + @Test + public void setInvocationIdFromMDCNoInvocationIdTest() { + setInvocationIdFromMDC(); + // InvocationId is set to a random UUID + assertNotNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + } + + @Test + public void setResponseStatusCodeTest() { + setResponseStatusCode(200); + assertEquals("COMPLETE", MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + } + + @Test + public void setResponseStatusCodeErrorTest() { + setResponseStatusCode(400); + assertEquals("ERROR", MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + assertEquals("400", MDC.get(ONAPLogConstants.MDCs.ERROR_CODE)); + assertEquals("Bad Request", MDC.get(ONAPLogConstants.MDCs.ERROR_DESC)); + } + + @Test + public void clearClientMDCsTest() { + MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, "7b77143c-9b50-410c-ac2f-05758a68e3e9"); + MDC.put(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION, "Bad Gateway"); + MDC.put(ONAPLogConstants.MDCs.ERROR_DESC, "Bad Gateway"); + MDC.put(ONAPLogConstants.MDCs.ERROR_CODE, "502"); + MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, "502"); + MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, "502"); + MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, "SO"); + MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, "SDNC"); + MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP, "2019-06-18T02:09:06.024Z"); + + clearClientMDCs(); + assertNull(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + assertNull(MDC.get(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION)); + assertNull(MDC.get(ONAPLogConstants.MDCs.ERROR_CODE)); + assertNull(MDC.get(ONAPLogConstants.MDCs.ERROR_DESC)); + assertNull(MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + assertNull(MDC.get(ONAPLogConstants.MDCs.RESPONSE_CODE)); + assertNull(MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY)); + assertNull(MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME)); + assertNull(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP)); + } + + @Test + public void setTargetEntityTest() { + setTargetEntity(ONAPComponents.SO); + assertEquals("SO", MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY)); + } + + @Test + public void setResponseDescriptionTest() { + setResponseDescription(502); + assertEquals("Bad Gateway", MDC.get(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION)); + } + + @Test + public void setMDCPartnerNameTest() { + MultivaluedMap headerMap = new MultivaluedHashMap<>(); + headerMap.putSingle(ONAPLogConstants.Headers.PARTNER_NAME, "SO"); + SimpleMap headers = new SimpleJaxrsHeadersMap(headerMap); + + setMDCPartnerName(headers); + + assertEquals("SO", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + } + + @Test + public void setMDCPartnerNameUserAgentHeaderTest() { + MultivaluedMap headerMap = new MultivaluedHashMap<>(); + headerMap.putSingle(HttpHeaders.USER_AGENT, "Apache-HttpClient/4.5.8 (Java/1.8.0_191)"); + SimpleMap headers = new SimpleJaxrsHeadersMap(headerMap); + + setMDCPartnerName(headers); + + assertEquals("Apache-HttpClient/4.5.8 (Java/1.8.0_191)", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + } + + @Test + public void setMDCPartnerNameClientIdHeaderTest() { + MultivaluedMap headerMap = new MultivaluedHashMap<>(); + headerMap.putSingle(Constants.HttpHeaders.CLIENT_ID, "SO"); + SimpleMap headers = new SimpleJaxrsHeadersMap(headerMap); + + setMDCPartnerName(headers); + + assertEquals("SO", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + } + + @Test + public void setMDCPartnerNameNoHeaderTest() { + MultivaluedMap headerMap = new MultivaluedHashMap<>(); + SimpleMap headers = new SimpleJaxrsHeadersMap(headerMap); + + setMDCPartnerName(headers); + + assertEquals("UNKNOWN", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + } + + @Test + public void setServerFQDNTest() { + setServerFQDN(); + assertNotNull(MDC.get(ONAPLogConstants.MDCs.SERVER_IP_ADDRESS)); + assertNotNull(MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN)); + } + + @Test + public void setClientIPAddressTest() { + when(httpServletRequest.getHeader("X-Forwarded-For")).thenReturn("127.0.0.2"); + setClientIPAddress(httpServletRequest); + + assertEquals("127.0.0.2", MDC.get(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS)); + } + + @Test + public void setClientIPAddressNoHeaderTest() { + when(httpServletRequest.getRemoteAddr()).thenReturn("127.0.0.1"); + setClientIPAddress(httpServletRequest); + + assertEquals("127.0.0.1", MDC.get(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS)); + } + + @Test + public void setClientIPAddressNullTest() { + setClientIPAddress(null); + + assertEquals("", MDC.get(ONAPLogConstants.MDCs.CLIENT_IP_ADDRESS)); + } + + @Test + public void setEntryTimeStampTest() { + setEntryTimeStamp(); + + assertNotNull(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)); + } + + @Test + public void setLogTimestampTest() { + setLogTimestamp(); + + assertNotNull(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP)); + } + + @Test + public void setInstanceIDTest() { + setInstanceID(); + + assertNotNull(MDC.get(ONAPLogConstants.MDCs.INSTANCE_UUID)); + } + + @Test + public void getPropertyTest() { + System.setProperty("partnerName", "partnerName"); + + String partnerName = getProperty("partnerName"); + assertEquals("partnerName", partnerName); + } + + @Test + public void getPropertyNullTest() { + String partnerName = getProperty("partner"); + assertEquals("UNKNOWN", partnerName); + } + +} diff --git a/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java b/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java index 3836ab7..8a592d2 100644 --- a/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java +++ b/reference/logging-filter/logging-filter-spring/src/test/java/org/onap/logging/filter/spring/SpringClientFilterTest.java @@ -37,7 +37,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.logging.filter.base.AbstractFilter; +import org.onap.logging.filter.base.MDCSetup; import org.onap.logging.filter.base.Constants; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.MDC; @@ -50,7 +50,7 @@ import org.springframework.http.client.ClientHttpResponse; public class SpringClientFilterTest extends SpringClientFilter { @Mock - private AbstractFilter mdcSetup; + private MDCSetup mdcSetup; @Mock private ClientHttpResponse response; -- cgit 1.2.3-korg