summaryrefslogtreecommitdiffstats
path: root/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils
diff options
context:
space:
mode:
Diffstat (limited to 'eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils')
-rw-r--r--eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/BaseLogbackUnitTest.java157
-rw-r--r--eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImplTest.java66
-rw-r--r--eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImplTest.java53
-rw-r--r--eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImplTest.java61
-rw-r--r--eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImplTest.java67
5 files changed, 404 insertions, 0 deletions
diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/BaseLogbackUnitTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/BaseLogbackUnitTest.java
new file mode 100644
index 0000000..fda4355
--- /dev/null
+++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/BaseLogbackUnitTest.java
@@ -0,0 +1,157 @@
+/*
+ * ================================================================================
+ * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback;
+
+
+import org.onap.dcae.utils.eelf.logger.api.info.CodeLogInfo;
+import org.onap.dcae.utils.eelf.logger.api.info.CustomFieldsLogInfo;
+import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo;
+import org.onap.dcae.utils.eelf.logger.api.info.MessageLogInfo;
+import org.onap.dcae.utils.eelf.logger.api.info.MiscLogInfo;
+import org.onap.dcae.utils.eelf.logger.api.info.NagiosAlertLevel;
+import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo;
+import org.onap.dcae.utils.eelf.logger.api.info.RequestStatusCode;
+import org.onap.dcae.utils.eelf.logger.api.info.RequestTimingLogInfo;
+import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo;
+import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo;
+import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo;
+import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec;
+import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec;
+import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec;
+import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec;
+import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec;
+import org.onap.dcae.utils.eelf.logger.model.info.CodeLogInfoImpl;
+import org.onap.dcae.utils.eelf.logger.model.info.CustomFieldsLogInfoImpl;
+import org.onap.dcae.utils.eelf.logger.model.info.ErrorLogInfoImpl;
+import org.onap.dcae.utils.eelf.logger.model.info.MessageLogInfoImpl;
+import org.onap.dcae.utils.eelf.logger.model.info.MiscLogInfoImpl;
+import org.onap.dcae.utils.eelf.logger.model.info.RequestIdLogInfoImpl;
+import org.onap.dcae.utils.eelf.logger.model.info.RequestTimingLogInfoImpl;
+import org.onap.dcae.utils.eelf.logger.model.info.ResponseLogInfoImpl;
+import org.onap.dcae.utils.eelf.logger.model.info.ServiceLogInfoImpl;
+import org.onap.dcae.utils.eelf.logger.model.info.TargetServiceLogInfoImpl;
+import org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl;
+import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl;
+import org.onap.dcae.utils.eelf.logger.model.spec.ErrorLogSpecImpl;
+import org.onap.dcae.utils.eelf.logger.model.spec.MetricLogSpecImpl;
+import org.onap.dcae.utils.eelf.logger.model.spec.OptionalLogSpecImpl;
+
+import java.util.Date;
+
+/**
+ * Base Logback Unit Test.
+ *
+ * @author Rajiv Singla
+ */
+public abstract class BaseLogbackUnitTest {
+
+ protected static final String TEST_SERVICE_INSTANCE_ID = "testServiceInstanceID";
+ protected static final String TEST_INSTANCE_UUID = "";
+
+ static {
+ System.setProperty("ServiceInstanceId", TEST_SERVICE_INSTANCE_ID);
+ System.setProperty("InstanceUUID", TEST_INSTANCE_UUID);
+ }
+
+ protected static final String TEST_REQUEST_ID = "403cdad8-4de7-450d-b441-561001decdd6";
+ protected static final String TEST_SERVICE_NAME = "testServiceName";
+ protected static final String TEST_PARTNER_NAME = "testPartnerName";
+ protected static final String TEST_CLIENT_IP_ADDRESS = "";
+
+ protected static final Date START_DATE = new Date();
+ protected static final Date END_DATE = new Date(new Date().getTime() + 30_000);
+ protected static final Long ELAPSED_TIME = END_DATE.getTime() - START_DATE.getTime();
+
+ protected static final Integer RESPONSE_CODE = 200;
+ protected static final String RESPONSE_DESCRIPTION = "TEST RESPONSE DESCRIPTION";
+
+ protected static final String TEST_TARGET_ENTITY = "testTargetEntity";
+ protected static final String TEST_TARGET_SERVICE_NAME = "testTargetServiceName";
+ protected static final String TEST_TARGET_VIRTUAL_ENTITY = "testTargetVirtualEntity";
+
+
+ protected static final String TEST_THREAD_ID = "testThreadId";
+ protected static final String TEST_CLASS_NAME = "testClassName";
+
+ protected static final String TEST_CUSTOM_FIELD1 = "testCustomField1";
+ protected static final String TEST_CUSTOM_FIELD2 = "testCustomField2";
+ protected static final String TEST_CUSTOM_FIELD3 = "testCustomField3";
+ protected static final String TEST_CUSTOM_FIELD4 = "testCustomField4";
+
+ protected static final String TEST_PROCESS_KEY = "testProcessId";
+
+ protected static final Integer TEST_ERROR_CODE = 500;
+ protected static final String TEST_ERROR_CODE_DESCRIPTION = "TEST ERROR CODE DESCRIPTION";
+
+
+ protected static RequestIdLogInfo getTestRequestIdLogInfo() {
+ return new RequestIdLogInfoImpl(TEST_REQUEST_ID);
+ }
+
+ protected static ServiceLogInfo getTestServiceLogInfo() {
+ return new ServiceLogInfoImpl(TEST_SERVICE_NAME, TEST_PARTNER_NAME, TEST_CLIENT_IP_ADDRESS);
+ }
+
+ protected static RequestTimingLogInfo getTestRequestTimingInfo() {
+ return new RequestTimingLogInfoImpl(START_DATE, END_DATE, ELAPSED_TIME);
+ }
+
+ protected static ResponseLogInfo getTestResponseLogInfo() {
+ return new ResponseLogInfoImpl(RESPONSE_CODE, RESPONSE_DESCRIPTION);
+ }
+
+ protected static AuditLogSpec getTestAuditLogSpec() {
+ return new AuditLogSpecImpl(getTestRequestIdLogInfo(), getTestServiceLogInfo(),
+ getTestRequestTimingInfo(), getTestResponseLogInfo());
+ }
+
+ protected static DebugLogSpec getTestDebugLogSpec() {
+ return new DebugLogSpecImpl(getTestRequestIdLogInfo());
+ }
+
+ protected static TargetServiceLogInfo getTestTargetServiceLogInfo() {
+ return new TargetServiceLogInfoImpl(TEST_TARGET_ENTITY, TEST_TARGET_SERVICE_NAME, TEST_TARGET_VIRTUAL_ENTITY);
+ }
+
+ protected static MetricLogSpec getTestMetricLogSpec() {
+ return new MetricLogSpecImpl(getTestRequestIdLogInfo(), getTestServiceLogInfo(),
+ getTestRequestTimingInfo(), getTestResponseLogInfo(), getTestTargetServiceLogInfo());
+ }
+
+ protected static ErrorLogInfo getTestErrorLogInfo() {
+ return new ErrorLogInfoImpl(TEST_ERROR_CODE, TEST_ERROR_CODE_DESCRIPTION);
+ }
+
+ protected static ErrorLogSpec getTestErrorLogSpec() {
+ return new ErrorLogSpecImpl(getTestRequestIdLogInfo(), getTestServiceLogInfo(), getTestTargetServiceLogInfo()
+ , getTestErrorLogInfo());
+ }
+
+ protected static OptionalLogSpec getTestOptionalLogSpec() {
+ final MessageLogInfo messageLogInfo = new MessageLogInfoImpl(new Date(), RequestStatusCode.COMPLETE,
+ NagiosAlertLevel.OK);
+ final CodeLogInfo codeLogInfo = new CodeLogInfoImpl(TEST_THREAD_ID, TEST_CLASS_NAME);
+ final CustomFieldsLogInfo customFieldsLogInfo = new CustomFieldsLogInfoImpl(TEST_CUSTOM_FIELD1,
+ TEST_CUSTOM_FIELD2, TEST_CUSTOM_FIELD3, TEST_CUSTOM_FIELD4);
+ final MiscLogInfo miscLogInfo = new MiscLogInfoImpl(TEST_PROCESS_KEY, "");
+ return new OptionalLogSpecImpl(messageLogInfo, codeLogInfo, customFieldsLogInfo, miscLogInfo);
+ }
+
+}
diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImplTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImplTest.java
new file mode 100644
index 0000000..02b377a
--- /dev/null
+++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/AuditLogImplTest.java
@@ -0,0 +1,66 @@
+/*
+ * ================================================================================
+ * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log;
+
+import org.junit.Test;
+import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory;
+import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger;
+import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec;
+import org.onap.dcae.utils.eelf.logger.logback.BaseLogbackUnitTest;
+import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults;
+import org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl;
+
+/**
+ * Tests for Audit log implementations.
+ *
+ * @author Rajiv Singla
+ */
+public class AuditLogImplTest extends BaseLogbackUnitTest {
+
+ private static final EELFLogger LOG = EELFLogFactory.getLogger(AuditLogImplTest.class);
+
+ @Test
+ public void auditLoggerTest() throws Exception {
+
+ LOG.auditLog().info("Test Audit info message: {}",
+ getTestAuditLogSpec(), getTestOptionalLogSpec(), "infoArg");
+
+ final AuditLogSpec emptyAuditLog = new AuditLogSpecImpl(null, null,
+ null, null);
+
+ LOG.auditLog().info("Test Empty Audit info message.", emptyAuditLog,
+ EELFLoggerDefaults.DEFAULT_OPTIONAL_LOG_SPEC);
+
+ }
+
+
+ @Test
+ public void auditLoggerTestWithWarnLogLevel() throws Exception {
+ LOG.auditLog().warn("Test Audit warn message: {}",
+ getTestAuditLogSpec(), getTestOptionalLogSpec(), "warnArg");
+ }
+
+ @Test
+ public void auditLoggerTestWithErrorLogLevel() throws Exception {
+ LOG.auditLog().error("Test Audit error message: {}",
+ getTestAuditLogSpec(), getTestOptionalLogSpec(), "errorArg");
+
+ }
+}
diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImplTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImplTest.java
new file mode 100644
index 0000000..76d41f9
--- /dev/null
+++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/DebugLogImplTest.java
@@ -0,0 +1,53 @@
+/*
+ * ================================================================================
+ * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log;
+
+import org.junit.Test;
+import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory;
+import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger;
+import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec;
+import org.onap.dcae.utils.eelf.logger.logback.BaseLogbackUnitTest;
+import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults;
+import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl;
+
+
+/**
+ * Test for Debug log implementation.
+ *
+ * @author Rajiv Singla
+ */
+public class DebugLogImplTest extends BaseLogbackUnitTest {
+
+ private static final EELFLogger LOG = EELFLogFactory.getLogger(DebugLogImplTest.class);
+
+ @Test
+ public void debugLoggerTest() throws Exception {
+
+ LOG.debugLog().debug("Test DebugLog debug message: {}",
+ getTestDebugLogSpec(), getTestOptionalLogSpec(), "debugArg");
+
+ final DebugLogSpec emptyDebugLog = new DebugLogSpecImpl(null);
+
+ LOG.debugLog().debug("Test Empty DebugLog debug message.", emptyDebugLog,
+ EELFLoggerDefaults.DEFAULT_OPTIONAL_LOG_SPEC);
+
+ }
+
+}
diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImplTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImplTest.java
new file mode 100644
index 0000000..0b96be5
--- /dev/null
+++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/ErrorLogImplTest.java
@@ -0,0 +1,61 @@
+/*
+ * ================================================================================
+ * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log;
+
+import org.junit.Test;
+import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory;
+import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger;
+import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec;
+import org.onap.dcae.utils.eelf.logger.logback.BaseLogbackUnitTest;
+import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults;
+import org.onap.dcae.utils.eelf.logger.model.spec.ErrorLogSpecImpl;
+
+
+/**
+ * Tests for Error Log implementation.
+ *
+ * @author Rajiv Singla
+ */
+public class ErrorLogImplTest extends BaseLogbackUnitTest {
+
+ private static final EELFLogger LOG = EELFLogFactory.getLogger(ErrorLogImplTest.class);
+
+ @Test
+ public void errorLoggerTest() throws Exception {
+ LOG.errorLog().error("Test ErrorLog error message: {}",
+ getTestErrorLogSpec(), getTestOptionalLogSpec(), "errorArg");
+
+ final ErrorLogSpec emptyErrorLog = new ErrorLogSpecImpl(null, null,
+ null, null);
+
+ LOG.errorLog().error("Test Empty ErrorLog error message", emptyErrorLog,
+ EELFLoggerDefaults.DEFAULT_OPTIONAL_LOG_SPEC);
+
+ }
+
+ @Test
+ public void errorLoggerTestWithWarnLogLevel() throws Exception {
+ LOG.errorLog().warn("Test errorLog warn message: {}", getTestErrorLogSpec(), getTestOptionalLogSpec(),
+ "warnArg");
+
+ }
+
+
+}
diff --git a/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImplTest.java b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImplTest.java
new file mode 100644
index 0000000..8df1e9c
--- /dev/null
+++ b/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/log/MetricLogImplTest.java
@@ -0,0 +1,67 @@
+/*
+ * ================================================================================
+ * Copyright (c) 2018 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.dcae.utils.eelf.logger.logback.log;
+
+import org.junit.Test;
+import org.onap.dcae.utils.eelf.logger.api.log.EELFLogFactory;
+import org.onap.dcae.utils.eelf.logger.api.log.EELFLogger;
+import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec;
+import org.onap.dcae.utils.eelf.logger.logback.BaseLogbackUnitTest;
+import org.onap.dcae.utils.eelf.logger.logback.EELFLoggerDefaults;
+import org.onap.dcae.utils.eelf.logger.model.spec.MetricLogSpecImpl;
+
+
+/**
+ * Tests for Metric Log implementation.
+ *
+ * @author Rajiv Singla
+ */
+public class MetricLogImplTest extends BaseLogbackUnitTest {
+
+ private static final EELFLogger LOG = EELFLogFactory.getLogger(MetricLogImplTest.class);
+
+ @Test
+ public void metricLoggerTest() throws Exception {
+
+ LOG.metricLog().info("test Metric info message: {}", getTestMetricLogSpec(), getTestOptionalLogSpec(),
+ "infoArg");
+
+ final MetricLogSpec emptyMetricLog = new MetricLogSpecImpl(null, null, null, null, null);
+
+ LOG.metricLog().info("Test Empty Metric info message", emptyMetricLog,
+ EELFLoggerDefaults.DEFAULT_OPTIONAL_LOG_SPEC);
+ }
+
+ @Test
+ public void metricLoggerTestWithWarnLogLevel() throws Exception {
+ LOG.metricLog().warn("test Metric warn message: {}", getTestMetricLogSpec(), getTestOptionalLogSpec(),
+ "warnArg");
+
+ }
+
+ @Test
+ public void metricLoggerTestWithErrorLogLevel() throws Exception {
+ LOG.metricLog().warn("test Metric error message: {}", getTestMetricLogSpec(), getTestOptionalLogSpec(),
+ "errorArg");
+
+
+ }
+
+}