diff options
author | gummar <raj.gumma@est.tech> | 2020-01-29 12:43:54 +0000 |
---|---|---|
committer | Raj Gumma <raj.gumma@est.tech> | 2020-01-29 17:08:26 +0000 |
commit | 7e58e9bde2e39008cc0756c7ae121dd6eea1506e (patch) | |
tree | 2ae494f47a6d038b7a2941e8c9aaf7c741b49413 /security-util-lib/src/test/java/org | |
parent | c164fb9762d3ef13c5b3903f726b5c0ebda63fa9 (diff) |
Add test cases for security-util-lib
Test files added for
a. Logger.java
b. LogFieldsMdcHandler.java
Issue-ID: SDC-2736
Change-Id: Ifbd4ba51a6d423b515d9dedf3be5c97befff0651
Signed-off-by: gummar <raj.gumma@est.tech>
Diffstat (limited to 'security-util-lib/src/test/java/org')
2 files changed, 864 insertions, 0 deletions
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/logging/elements/LogFieldsMdcHandlerTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/logging/elements/LogFieldsMdcHandlerTest.java new file mode 100644 index 0000000..bb95d15 --- /dev/null +++ b/security-util-lib/src/test/java/org/onap/sdc/security/logging/elements/LogFieldsMdcHandlerTest.java @@ -0,0 +1,469 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.sdc.security.logging.elements; + +import org.junit.Before; +import org.junit.Test; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.sdc.security.logging.api.ILogConfiguration; +import org.onap.sdc.security.logging.enums.EcompHeadersConstants; +import org.onap.sdc.security.logging.enums.Severity; +import org.slf4j.MDC; + +import javax.servlet.http.HttpServletRequest; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyInt; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class LogFieldsMdcHandlerTest { + LogFieldsMdcHandler instanceMdcWrapper; + LogFieldsMdcHandler spy; + + @Before + public void setUp() throws Exception { + LogFieldsMdcHandler.hostAddress = "TestHost"; + LogFieldsMdcHandler.fqdn = "Test"; + instanceMdcWrapper = LogFieldsMdcHandler.getInstance(); + spy = spy(instanceMdcWrapper); + } + + @Test + public void getInstance() { + assertNotNull(LogFieldsMdcHandler.getInstance()); + } + + @Test + public void startAuditTimer() { + spy.startAuditTimer(); + verify(spy, times(1)).startAuditTimer(); + assertNotNull(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP)); + } + + @Test + public void startMetricTimer() { + spy.startMetricTimer(); + verify(spy, times(1)).startMetricTimer(); + assertNotNull(MDC.get(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP)); + } + + @Test + public void stopAuditTimer() { + spy.stopAuditTimer(); + verify(spy, times(1)).stopAuditTimer(); + assertNotNull(MDC.get(ILogConfiguration.MDC_END_TIMESTAMP)); + assertNotNull(MDC.get(ILogConfiguration.MDC_ELAPSED_TIME)); + } + + @Test + public void stopMetricTimer() { + spy.stopMetricTimer(); + verify(spy, times(1)).stopMetricTimer(); + assertNotNull(MDC.get(ILogConfiguration.MDC_END_TIMESTAMP)); + assertNotNull(MDC.get(ILogConfiguration.MDC_ELAPSED_TIME)); + } + + @Test + public void setClassName() { + spy.setClassName("TestClassName"); + verify(spy, times(1)).setClassName(anyString()); + assertEquals("TestClassName", MDC.get(ILogConfiguration.MDC_CLASS_NAME)); + } + + @Test + public void setServerFQDN() { + spy.setServerFQDN("TestFQDN"); + verify(spy, times(1)).setServerFQDN(anyString()); + assertEquals("TestFQDN", MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN)); + } + + @Test + public void testServerIPAddress() { + spy.setServerIPAddress("172.0.0.0"); + verify(spy, times(1)).setServerIPAddress(anyString()); + assertEquals("172.0.0.0", MDC.get(ILogConfiguration.MDC_SERVER_IP_ADDRESS)); + assertEquals(spy.getServerIpAddress(), MDC.get(ILogConfiguration.MDC_SERVER_IP_ADDRESS)); + verify(spy, times(1)).getServerIpAddress(); + } + + @Test + public void testServerFQDNInternally() { + spy.setServerFQDNInternally(); + verify(spy, times(1)).setServerFQDNInternally(); + assertNotNull(MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN)); + assertEquals(spy.getFqdn(), MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN)); + verify(spy, times(1)).getFqdn(); + + } + + @Test + public void setServerIPAddressInternally() { + + spy.setServerIPAddressInternally(); + verify(spy, times(1)).setServerIPAddressInternally(); + assertNotNull(MDC.get(ILogConfiguration.MDC_SERVER_IP_ADDRESS)); + } + + @Test + public void setInstanceUUID() { + spy.setInstanceUUID("Test UUID"); + verify(spy, times(1)).setInstanceUUID(anyString()); + assertEquals("Test UUID", MDC.get(ONAPLogConstants.MDCs.INSTANCE_UUID)); + } + + @Test + public void setProcessKey() { + spy.setProcessKey("Test String"); + verify(spy, times(1)).setProcessKey(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_PROCESS_KEY)); + } + + @Test + public void setAlertSeverity() { + spy.setAlertSeverity(Severity.CRITICAL); + verify(spy, times(1)).setAlertSeverity(any(Severity.class)); + assertEquals(String.valueOf(Severity.CRITICAL.getSeverityType()), + MDC.get(ONAPLogConstants.MDCs.RESPONSE_SEVERITY)); + } + + @Test + public void setOptCustomField1() { + spy.setOptCustomField1("Test String"); + verify(spy, times(1)).setOptCustomField1(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_OPT_FIELD1)); + } + + @Test + public void setOptCustomField2() { + spy.setOptCustomField2("Test String"); + verify(spy, times(1)).setOptCustomField2(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_OPT_FIELD2)); + } + + @Test + public void setOptCustomField3() { + spy.setOptCustomField3("Test String"); + verify(spy, times(1)).setOptCustomField3(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_OPT_FIELD3)); + } + + @Test + public void setOptCustomField4() { + spy.setOptCustomField4("Test String"); + verify(spy, times(1)).setOptCustomField4(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_OPT_FIELD4)); + } + + @Test + public void testKeyRequestId() { + spy.setKeyRequestId("Test String"); + verify(spy, times(1)).setKeyRequestId(anyString()); + assertEquals("Test String", MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)); + assertEquals(spy.getKeyRequestId(), MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)); + verify(spy, times(1)).getKeyRequestId(); + } + + @Test + public void testKeyInvocationId() { + spy.setKeyInvocationId("Test String"); + verify(spy, times(1)).setKeyInvocationId(anyString()); + assertEquals("Test String", MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + assertNull(spy.getKeyInvocationId()); + verify(spy, times(1)).getKeyInvocationId(); + } + + @Test + public void testRemoteHost() { + spy.setRemoteHost("Test String"); + verify(spy, times(1)).setRemoteHost(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_REMOTE_HOST)); + assertEquals(spy.getRemoteHost(), MDC.get(ILogConfiguration.MDC_REMOTE_HOST)); + verify(spy, times(1)).getRemoteHost(); + } + + @Test + public void testServiceName() { + spy.setServiceName("Test String"); + verify(spy, times(1)).setServiceName(anyString()); + assertEquals("Test String", MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME)); + assertEquals("Test String", spy.getServiceName()); + verify(spy, times(1)).getServiceName(); + + } + + @Test + public void testStatusCode() { + spy.setStatusCode("Test String"); + verify(spy, times(1)).setStatusCode(anyString()); + assertEquals("Test String", MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + spy.removeStatusCode(); + assertNull(MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + verify(spy, times(1)).removeStatusCode(); + } + + @Test + public void testPartnerName() { + spy.setPartnerName("Test String"); + verify(spy, times(1)).setPartnerName(anyString()); + assertEquals("Test String", MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + assertEquals(spy.getPartnerName(), MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + verify(spy, times(1)).getPartnerName(); + spy.removePartnerName(); + assertNull(MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)); + verify(spy, times(1)).removePartnerName(); + } + + @Test + public void testResponseCode() { + spy.setResponseCode(42); + verify(spy, times(1)).setResponseCode(anyInt()); + assertEquals(Integer.toString(42), MDC.get(ONAPLogConstants.MDCs.RESPONSE_CODE)); + spy.removeResponseCode(); + assertNull(MDC.get(ONAPLogConstants.MDCs.RESPONSE_CODE)); + verify(spy, times(1)).removeResponseCode(); + } + + @Test + public void testResponseDesc() { + spy.setResponseDesc("Test String"); + verify(spy, times(1)).setResponseDesc(anyString()); + assertEquals("Test String", MDC.get(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION)); + spy.removeResponseDesc(); + assertNull(MDC.get(ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION)); + verify(spy, times(1)).removeResponseDesc(); + + } + + @Test + public void setServiceInstanceId() { + spy.setServiceInstanceId("Test String"); + verify(spy, times(1)).setServiceInstanceId(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_SERVICE_INSTANCE_ID)); + spy.removeServiceInstanceId(); + assertNull(MDC.get(ILogConfiguration.MDC_SERVICE_INSTANCE_ID)); + verify(spy, times(1)).removeServiceInstanceId(); + } + + @Test + public void testTargetEntity() { + spy.setTargetEntity("Test String"); + verify(spy, times(1)).setTargetEntity(anyString()); + assertEquals("Test String", MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY)); + assertEquals(spy.getTargetEntity(), MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY)); + verify(spy, times(1)).getTargetEntity(); + spy.removeTargetEntity(); + assertNull(MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY)); + verify(spy, times(1)).removeTargetEntity(); + } + + @Test + public void testTargetServiceName() { + spy.setTargetServiceName("Test String"); + verify(spy, times(1)).setTargetServiceName(anyString()); + assertEquals("Test String", MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME)); + assertEquals(spy.getTargetServiceName(), MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME)); + verify(spy, times(1)).getTargetServiceName(); + spy.removeTargetServiceName(); + assertNull(MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME)); + verify(spy, times(1)).removeTargetServiceName(); + } + + @Test + public void setTargetVirtualEntity() { + spy.setTargetVirtualEntity("Test String"); + verify(spy, times(1)).setTargetVirtualEntity(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_TARGET_VIRTUAL_ENTITY)); + spy.removeTargetVirtualEntity(); + assertNull(MDC.get(ILogConfiguration.MDC_TARGET_VIRTUAL_ENTITY)); + verify(spy, times(1)).removeTargetVirtualEntity(); + } + + @Test + public void testErrorCode() { + spy.setErrorCode(42); + verify(spy, times(1)).setErrorCode(anyInt()); + assertEquals("42", MDC.get(ILogConfiguration.MDC_ERROR_CODE)); + assertEquals("42", spy.getErrorCode()); + verify(spy, times(1)).getErrorCode(); + spy.removeErrorCode(); + assertNull(MDC.get(ILogConfiguration.MDC_ERROR_CODE)); + verify(spy, times(1)).removeErrorCode(); + + } + + @Test + public void testErrorCategory() { + spy.setErrorCategory("Test String"); + verify(spy, times(1)).setErrorCategory(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_ERROR_CATEGORY)); + assertEquals("Test String", spy.getErrorCategory()); + verify(spy, times(1)).getErrorCategory(); + spy.removeErrorCategory(); + assertNull(MDC.get(ILogConfiguration.MDC_ERROR_CATEGORY)); + verify(spy, times(1)).removeErrorCategory(); + } + + @Test + public void clear() { + MDC.put("Test Property", "Test Value"); + assertNotNull(MDC.get("Test Property")); + spy.clear(); + verify(spy, times(1)).clear(); + assertNull(MDC.get("Test Property")); + } + + @Test + public void isMDCParamEmpty() { + assertTrue(spy.isMDCParamEmpty("Invalid Key")); + } + + @Test + public void getHostAddress() { + assertNotNull(spy.getHostAddress()); + verify(spy, times(1)).getHostAddress(); + } + + @Test + public void testAuditMessage() { + spy.setAuditMessage("Test String"); + verify(spy, times(1)).setAuditMessage(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_AUDIT_MESSAGE)); + assertEquals("Test String", spy.getAuditMessage()); + verify(spy, times(1)).getAuditMessage(); + } + + @Test + public void testSupportablityStatusCode() { + spy.setSupportablityStatusCode("Test String"); + verify(spy, times(1)).setSupportablityStatusCode(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_STATUS_CODE)); + assertEquals("Test String", spy.getSupportablityStatusCode()); + verify(spy, times(1)).getSupportablityStatusCode(); + spy.removeSupportablityStatusCode(); + assertNull(MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_STATUS_CODE)); + verify(spy, times(1)).removeSupportablityStatusCode(); + } + + @Test + public void testSupportablityAction() { + spy.setSupportablityAction("Test String"); + verify(spy, times(1)).setSupportablityAction(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_ACTION)); + assertEquals("Test String", spy.getSupportablityAction()); + verify(spy, times(1)).getSupportablityAction(); + spy.removeSupportablityAction(); + assertNull(MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_ACTION)); + verify(spy, times(1)).removeSupportablityAction(); + } + + @Test + public void testSupportablityCsarUUID() { + spy.setSupportablityCsarUUID("Test String"); + verify(spy, times(1)).setSupportablityCsarUUID(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID)); + assertEquals("Test String", spy.getSupportablityCsarUUID()); + verify(spy, times(1)).getSupportablityCsarUUID(); + spy.removeSupportablityCsarUUID(); + assertNull(MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_UUID)); + verify(spy, times(1)).removeSupportablityCsarUUID(); + } + + @Test + public void testSupportablityCsarVersion() { + spy.setSupportablityCsarVersion("Test String"); + verify(spy, times(1)).setSupportablityCsarVersion(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION)); + assertEquals("Test String", spy.getSupportablityCsarVersion()); + verify(spy, times(1)).getSupportablityCsarVersion(); + spy.removeSupportablityCsarVersion(); + assertNull(MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION)); + verify(spy, times(1)).removeSupportablityCsarVersion(); + } + + @Test + public void getSupportablityComponentName() { + spy.setSupportablityCsarVersion("Test String"); + verify(spy, times(1)).setSupportablityCsarVersion(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION)); + assertEquals("Test String", spy.getSupportablityCsarVersion()); + verify(spy, times(1)).getSupportablityCsarVersion(); + spy.removeSupportablityCsarVersion(); + assertNull(MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_CSAR_VERSION)); + verify(spy, times(1)).removeSupportablityCsarVersion(); + } + + @Test + public void getSupportablityComponentUUID() { + spy.setSupportablityComponentUUID("Test String"); + verify(spy, times(1)).setSupportablityComponentUUID(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID)); + assertEquals("Test String", spy.getSupportablityComponentUUID()); + verify(spy, times(1)).getSupportablityComponentUUID(); + spy.removeSupportablityComponentUUID(); + assertNull(MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID)); + verify(spy, times(1)).removeSupportablityComponentUUID(); + } + + @Test + public void getSupportablityComponentVersion() { + spy.setSupportablityComponentVersion("Test String"); + verify(spy, times(1)).setSupportablityComponentVersion(anyString()); + assertEquals("Test String", MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION)); + assertEquals("Test String", spy.getSupportablityComponentVersion()); + verify(spy, times(1)).getSupportablityComponentVersion(); + spy.removeSupportablityComponentVersion(); + assertNull(MDC.get(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION)); + verify(spy, times(1)).removeSupportablityComponentVersion(); + } + + @Test + public void collectRequestInfoForErrorAndDebugLogging() { + HttpServletRequest httpRequest = mock(HttpServletRequest.class); + when(httpRequest.getHeader(EcompHeadersConstants.X_ECOMP_SERVICE_ID_HEADER)).thenReturn( + "MockServiceInstanceID"); + when(httpRequest.getHeader(EcompHeadersConstants.USER_ID_HEADER)).thenReturn("Mock_User"); + when(httpRequest.getRemoteHost()).thenReturn("Test_Host"); + when(httpRequest.getLocalAddr()).thenReturn("172.0.0.0"); + when(httpRequest.getHeader(ONAPLogConstants.Headers.REQUEST_ID)).thenReturn("Test_ID"); + when(httpRequest.getRequestURI()).thenReturn("Test_Service"); + + spy.collectRequestInfoForErrorAndDebugLogging(httpRequest); + verify(spy, times(1)). + collectRequestInfoForErrorAndDebugLogging(any(HttpServletRequest.class)); + assertEquals("Test_Service", spy.getServiceName()); + assertEquals("Test_ID", spy.getKeyRequestId()); + assertEquals("Test_Host", spy.getRemoteHost()); + assertEquals("172.0.0.0", spy.getServerIpAddress()); + assertEquals("MockServiceInstanceID", MDC.get(ILogConfiguration.MDC_SERVICE_INSTANCE_ID) ); + assertEquals("Mock_User", spy.getPartnerName()); + } + + @Test + public void addInfoForErrorAndDebugLogging() { + spy.addInfoForErrorAndDebugLogging("Test Partner"); + assertNotNull(spy.getPartnerName()); + assertEquals("Test Partner", spy.getPartnerName()); + assertNotNull(spy.getKeyRequestId()); + } +}
\ No newline at end of file diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerTest.java new file mode 100644 index 0000000..1288578 --- /dev/null +++ b/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerTest.java @@ -0,0 +1,395 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.sdc.security.logging.wrappers; + +import org.junit.Before; +import org.junit.Test; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.sdc.security.logging.elements.ErrorLogOptionalData; +import org.onap.sdc.security.logging.enums.EcompErrorSevirity; +import org.onap.sdc.security.logging.enums.EcompLoggerErrorCode; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyCollection; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +public class LoggerTest { + Logger log; + Logger spy; + Marker marker; + List<String> testList; + + @Before + public void setUp() throws Exception { + testList = Arrays.asList("Item1", "Item2"); + marker = MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()); + log = Logger.getLogger(LoggerTest.class.getName()); + spy = spy(log); + } + + + @Test + public void testGetLogger() { + assertNotNull(Logger.getLogger(LoggerTest.class)); + } + + @Test + public void isDebugEnabled() { + assertTrue("Debug level not enabled", log.isDebugEnabled()); + } + + @Test + public void getName() { + assertEquals("Logger name not as expected", "org.onap.sdc.security.logging.wrappers.LoggerTest", log.getName()); + } + + @Test + public void isTraceEnabled() { + assertFalse("Trace level should not enabled", spy.isTraceEnabled()); + } + + @Test + public void isErrorEnabled() { + assertTrue("Error level is not enabled", spy.isErrorEnabled()); + } + + @Test + public void isWarnEnabled() { + assertTrue("Warn level is not enabled", spy.isWarnEnabled()); + } + + + @Test + public void isInfoEnabled() { + assertTrue("Info level is not enabled", spy.isInfoEnabled()); + } + + @Test + public void info() { + spy.info("Test Info log"); + verify(spy, times(1)).info("Test Info log"); + } + + @Test + public void testInfoWithObject() { + spy.info("Test Info log", testList); + verify(spy, times(1)).info("Test Info log", testList); + } + + @Test + public void testInfoWith2Object() { + spy.info("Test Info log", testList, testList); + verify(spy, times(1)).info("Test Info log", testList, testList); + } + + @Test + public void debug() { + spy.debug("Test DEBUG log", testList); + verify(spy, times(1)).debug(anyString(), any(Object.class)); + } + + @Test + public void metric() { + spy.metric("Test metric log", testList); + verify(spy, times(1)).metric(anyString(), any(Object.class)); + } + + @Test + public void invoke() { + spy.invoke("Test Host", "Test Entity", "Test Service", "Test metric log", testList, testList, testList); + verify(spy, times(1)).invoke(anyString(), anyString(), anyString(), anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void invokeReturn() { + spy.invokeReturn(ONAPLogConstants.ResponseStatus.ERROR, "Test metric log", testList, testList, testList); + verify(spy, times(1)).invokeReturn(any(ONAPLogConstants.ResponseStatus.class), anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testInvokeReturn() { + spy.invokeReturn("Test metric log", testList, testList, testList); + verify(spy, times(1)).invokeReturn(anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void invokeSynchronous() { + spy.invokeSynchronous("Test metric log", testList, testList, testList); + verify(spy, times(1)).invokeSynchronous(anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testDebugThrowable() { + spy.debug("Test DEBUG throwable", new RuntimeException("Mock Exception")); + verify(spy, times(1)).debug(anyString(), any(Throwable.class)); + } + + @Test + public void testIsDebugEnabledMarker() { + assertFalse(spy.isDebugEnabled(marker)); + } + + @Test + public void testDebugMarkerMsg() { + spy.debug(marker, "Test marker debug log"); + verify(spy, times(1)).debug(any(Marker.class), anyString()); + } + + @Test + public void testDebugMarkerWithParam() { + spy.debug(marker, "Test marker debug log", testList); + verify(spy, times(1)).debug(any(Marker.class), anyString(), anyCollection()); + } + + @Test + public void testDebugMarkerWithMultipleObjects() { + spy.debug(marker, "Test marker debug log", testList, testList, testList); + verify(spy, times(1)).debug(any(Marker.class), anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testDebugWithMarker2Params() { + spy.debug(marker, "Test marker debug log", testList, testList); + verify(spy, times(1)).debug(any(Marker.class), anyString(), anyCollection(), anyCollection()); + } + + @Test + public void testDebugMarkerThrowable() { + spy.debug(marker, "Test marker debug log", new RuntimeException("Mock Exception")); + verify(spy, times(1)).debug(any(Marker.class), anyString(), any(Throwable.class)); + } + + @Test + public void testDebug() { + spy.debug("Test debug log"); + verify(spy, times(1)).debug(anyString()); + } + + @Test + public void testDebugWithParam() { + spy.debug("Test debug log", testList); + verify(spy, times(1)).debug(anyString(), anyCollection()); + } + + @Test + public void testDebugWith2Params() { + spy.debug("Test debug log", testList, testList); + verify(spy, times(1)).debug(anyString(), anyCollection(), anyCollection()); + } + + @Test + public void trace() { + spy.trace("Test trace log", testList, testList, testList); + verify(spy, times(1)).trace(anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testTraceWithThrowable() { + spy.trace("Test trace log", new RuntimeException("Mock Exception")); + verify(spy, times(1)).trace(anyString(), any(Throwable.class)); + } + + @Test + public void testIsTraceEnabled() { + assertFalse(spy.isTraceEnabled(marker)); + } + + @Test + public void testTraceWithMarker() { + spy.trace(marker, "Test trace log"); + verify(spy, times(1)).trace(any(Marker.class), anyString()); + } + + @Test + public void testTraceMarkerWithParam() { + spy.trace(marker, "Test trace log", testList); + verify(spy, times(1)).trace(any(Marker.class), anyString(), anyCollection()); + } + + @Test + public void testTraceMarkerWith2Params() { + spy.trace(marker, "Test trace log", testList, testList); + verify(spy, times(1)).trace(any(Marker.class), anyString(), anyCollection(), anyCollection()); + } + + @Test + public void testTraceMarkerWithMultipleParams() { + spy.trace(marker, "Test trace log", testList, testList, testList); + verify(spy, times(1)).trace(any(Marker.class), anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testTraceMarkerWithThrowable() { + spy.trace(marker, "Test trace log", new RuntimeException("Mock Exception")); + verify(spy, times(1)).trace(any(Marker.class), anyString(), any(Throwable.class)); + } + + @Test + public void testTrace() { + spy.trace("Test trace log"); + verify(spy, times(1)).trace(anyString()); + } + + @Test + public void testTraceWithParam() { + spy.trace("Test trace log", testList); + verify(spy, times(1)).trace(anyString(), anyCollection()); + } + + @Test + public void testTraceWith2Params() { + spy.trace("Test trace log", testList, testList); + verify(spy, times(1)).trace(anyString(), anyCollection(), anyCollection()); + } + + @Test + public void testInfoWithMultipleObjects() { + spy.info("Test Info log", testList, testList, testList); + verify(spy, times(1)).info(anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testInfoWithThrowable() { + spy.info("Test Info log", new RuntimeException("Mock Exception")); + verify(spy, times(1)).info(anyString(), any(Throwable.class)); + } + + @Test + public void testIsInfoEnabled() { + assertFalse(spy.isInfoEnabled(marker)); + } + + @Test + public void testInfoWithMarker() { + spy.info(marker, "Test info log"); + verify(spy, times(1)).info(any(Marker.class), anyString()); + } + + @Test + public void testInfoMarkerWithParam() { + spy.info(marker, "Test info log", testList); + verify(spy, times(1)).info(any(Marker.class), anyString(), anyCollection()); + } + + @Test + public void testInfoMarkerWith2Params() { + spy.info(marker, "Test info log", testList, testList); + verify(spy, times(1)).info(any(Marker.class), anyString(), anyCollection(), anyCollection()); + } + + @Test + public void testInfoMarkerWithMultipleParams() { + spy.info(marker, "Test info log", testList, testList, testList); + verify(spy, times(1)).info(any(Marker.class), anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testInfoMarkerWithThrowable() { + spy.info(marker, "Test info log", new RuntimeException("Mock Exception")); + verify(spy, times(1)).info(any(Marker.class), anyString(), any(Throwable.class)); + } + + @Test + public void testIsWarnEnabledMarker() { + assertFalse(spy.isWarnEnabled(marker)); + } + + @Test + public void testIsErrorEnabledMarker() { + assertFalse(spy.isErrorEnabled(marker)); + } + + @Test + public void testErrorWithSeverity() { + spy.error(EcompErrorSevirity.ERROR, EcompLoggerErrorCode.UNKNOWN_ERROR, + "Mock Service", "MockTargetEntity", + "Test error description", testList, testList, testList); + verify(spy, times(1)).error(any(EcompErrorSevirity.class), any(EcompLoggerErrorCode.class), + anyString(), anyString(), anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testError() { + spy.error(EcompLoggerErrorCode.UNKNOWN_ERROR, + "Mock Service", "Test error description", testList, testList, testList); + verify(spy, times(1)).error(any(EcompLoggerErrorCode.class), + anyString(), anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testErrorOptionalData() { + spy.error(EcompLoggerErrorCode.UNKNOWN_ERROR, + "Mock Service", ErrorLogOptionalData.newBuilder().build(), + "Test error description", testList, testList, testList); + verify(spy, times(1)).error(any(EcompLoggerErrorCode.class), + anyString(), any(ErrorLogOptionalData.class), anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testWarn() { + spy.warn(EcompLoggerErrorCode.UNKNOWN_ERROR, + "Mock Service", "Test warn description", testList, testList, testList); + verify(spy, times(1)).warn(any(EcompLoggerErrorCode.class), + anyString(), anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testWarnWithTargetEntity() { + spy.warn(EcompLoggerErrorCode.UNKNOWN_ERROR, + "Mock Service", "MockTargetEntity", + "Test warn description", testList, testList, testList); + verify(spy, times(1)).warn(any(EcompLoggerErrorCode.class), + anyString(), anyString(), anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testWarnOptionalData() { + spy.warn(EcompLoggerErrorCode.UNKNOWN_ERROR, + "Mock Service", ErrorLogOptionalData.newBuilder().build(), + "Test warn description", testList, testList, testList); + verify(spy, times(1)).warn(any(EcompLoggerErrorCode.class), + anyString(), any(ErrorLogOptionalData.class), anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testFatalWithTargetEntity() { + spy.fatal(EcompLoggerErrorCode.UNKNOWN_ERROR, + "Mock Service", "MockTargetEntity", + "Test fatal description", testList, testList, testList); + verify(spy, times(1)).fatal(any(EcompLoggerErrorCode.class), + anyString(), anyString(), anyString(), anyCollection(), anyCollection(), anyCollection()); + } + + @Test + public void testFatalWithOptionalData() { + spy.fatal(EcompLoggerErrorCode.UNKNOWN_ERROR, + "Mock Service", ErrorLogOptionalData.newBuilder().build(), + "Test fatal description", testList, testList, testList); + verify(spy, times(1)).fatal(any(EcompLoggerErrorCode.class), + anyString(), any(ErrorLogOptionalData.class), anyString(), anyCollection(), anyCollection(), anyCollection()); + } +}
\ No newline at end of file |