Standalone TCA with EELF Logger
[dcaegen2/analytics/tca-gen2.git] / eelf-logger / eelf-logger-logback-impl / src / test / java / org / onap / dcae / utils / eelf / logger / logback / BaseLogbackUnitTest.java
1 /*
2  * ================================================================================
3  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  *
18  */
19
20 package org.onap.dcae.utils.eelf.logger.logback;
21
22
23 import org.onap.dcae.utils.eelf.logger.api.info.CodeLogInfo;
24 import org.onap.dcae.utils.eelf.logger.api.info.CustomFieldsLogInfo;
25 import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo;
26 import org.onap.dcae.utils.eelf.logger.api.info.MessageLogInfo;
27 import org.onap.dcae.utils.eelf.logger.api.info.MiscLogInfo;
28 import org.onap.dcae.utils.eelf.logger.api.info.NagiosAlertLevel;
29 import org.onap.dcae.utils.eelf.logger.api.info.RequestIdLogInfo;
30 import org.onap.dcae.utils.eelf.logger.api.info.RequestStatusCode;
31 import org.onap.dcae.utils.eelf.logger.api.info.RequestTimingLogInfo;
32 import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo;
33 import org.onap.dcae.utils.eelf.logger.api.info.ServiceLogInfo;
34 import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo;
35 import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec;
36 import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec;
37 import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec;
38 import org.onap.dcae.utils.eelf.logger.api.spec.MetricLogSpec;
39 import org.onap.dcae.utils.eelf.logger.api.spec.OptionalLogSpec;
40 import org.onap.dcae.utils.eelf.logger.model.info.CodeLogInfoImpl;
41 import org.onap.dcae.utils.eelf.logger.model.info.CustomFieldsLogInfoImpl;
42 import org.onap.dcae.utils.eelf.logger.model.info.ErrorLogInfoImpl;
43 import org.onap.dcae.utils.eelf.logger.model.info.MessageLogInfoImpl;
44 import org.onap.dcae.utils.eelf.logger.model.info.MiscLogInfoImpl;
45 import org.onap.dcae.utils.eelf.logger.model.info.RequestIdLogInfoImpl;
46 import org.onap.dcae.utils.eelf.logger.model.info.RequestTimingLogInfoImpl;
47 import org.onap.dcae.utils.eelf.logger.model.info.ResponseLogInfoImpl;
48 import org.onap.dcae.utils.eelf.logger.model.info.ServiceLogInfoImpl;
49 import org.onap.dcae.utils.eelf.logger.model.info.TargetServiceLogInfoImpl;
50 import org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl;
51 import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl;
52 import org.onap.dcae.utils.eelf.logger.model.spec.ErrorLogSpecImpl;
53 import org.onap.dcae.utils.eelf.logger.model.spec.MetricLogSpecImpl;
54 import org.onap.dcae.utils.eelf.logger.model.spec.OptionalLogSpecImpl;
55
56 import java.util.Date;
57
58 /**
59  * Base Logback Unit Test.
60  *
61  * @author Rajiv Singla
62  */
63 public abstract class BaseLogbackUnitTest {
64
65     protected static final String TEST_SERVICE_INSTANCE_ID = "testServiceInstanceID";
66     protected static final String TEST_INSTANCE_UUID = "";
67
68     static {
69         System.setProperty("ServiceInstanceId", TEST_SERVICE_INSTANCE_ID);
70         System.setProperty("InstanceUUID", TEST_INSTANCE_UUID);
71     }
72
73     protected static final String TEST_REQUEST_ID = "403cdad8-4de7-450d-b441-561001decdd6";
74     protected static final String TEST_SERVICE_NAME = "testServiceName";
75     protected static final String TEST_PARTNER_NAME = "testPartnerName";
76     protected static final String TEST_CLIENT_IP_ADDRESS = "";
77
78     protected static final Date START_DATE = new Date();
79     protected static final Date END_DATE = new Date(new Date().getTime() + 30_000);
80     protected static final Long ELAPSED_TIME = END_DATE.getTime() - START_DATE.getTime();
81
82     protected static final Integer RESPONSE_CODE = 200;
83     protected static final String RESPONSE_DESCRIPTION = "TEST RESPONSE DESCRIPTION";
84
85     protected static final String TEST_TARGET_ENTITY = "testTargetEntity";
86     protected static final String TEST_TARGET_SERVICE_NAME = "testTargetServiceName";
87     protected static final String TEST_TARGET_VIRTUAL_ENTITY = "testTargetVirtualEntity";
88
89
90     protected static final String TEST_THREAD_ID = "testThreadId";
91     protected static final String TEST_CLASS_NAME = "testClassName";
92
93     protected static final String TEST_CUSTOM_FIELD1 = "testCustomField1";
94     protected static final String TEST_CUSTOM_FIELD2 = "testCustomField2";
95     protected static final String TEST_CUSTOM_FIELD3 = "testCustomField3";
96     protected static final String TEST_CUSTOM_FIELD4 = "testCustomField4";
97
98     protected static final String TEST_PROCESS_KEY = "testProcessId";
99
100     protected static final Integer TEST_ERROR_CODE = 500;
101     protected static final String TEST_ERROR_CODE_DESCRIPTION = "TEST ERROR CODE DESCRIPTION";
102
103
104     protected static RequestIdLogInfo getTestRequestIdLogInfo() {
105         return new RequestIdLogInfoImpl(TEST_REQUEST_ID);
106     }
107
108     protected static ServiceLogInfo getTestServiceLogInfo() {
109         return new ServiceLogInfoImpl(TEST_SERVICE_NAME, TEST_PARTNER_NAME, TEST_CLIENT_IP_ADDRESS);
110     }
111
112     protected static RequestTimingLogInfo getTestRequestTimingInfo() {
113         return new RequestTimingLogInfoImpl(START_DATE, END_DATE, ELAPSED_TIME);
114     }
115
116     protected static ResponseLogInfo getTestResponseLogInfo() {
117         return new ResponseLogInfoImpl(RESPONSE_CODE, RESPONSE_DESCRIPTION);
118     }
119
120     protected static AuditLogSpec getTestAuditLogSpec() {
121         return new AuditLogSpecImpl(getTestRequestIdLogInfo(), getTestServiceLogInfo(),
122                 getTestRequestTimingInfo(), getTestResponseLogInfo());
123     }
124
125     protected static DebugLogSpec getTestDebugLogSpec() {
126         return new DebugLogSpecImpl(getTestRequestIdLogInfo());
127     }
128
129     protected static TargetServiceLogInfo getTestTargetServiceLogInfo() {
130         return new TargetServiceLogInfoImpl(TEST_TARGET_ENTITY, TEST_TARGET_SERVICE_NAME, TEST_TARGET_VIRTUAL_ENTITY);
131     }
132
133     protected static MetricLogSpec getTestMetricLogSpec() {
134         return new MetricLogSpecImpl(getTestRequestIdLogInfo(), getTestServiceLogInfo(),
135                 getTestRequestTimingInfo(), getTestResponseLogInfo(), getTestTargetServiceLogInfo());
136     }
137
138     protected static ErrorLogInfo getTestErrorLogInfo() {
139         return new ErrorLogInfoImpl(TEST_ERROR_CODE, TEST_ERROR_CODE_DESCRIPTION);
140     }
141
142     protected static ErrorLogSpec getTestErrorLogSpec() {
143         return new ErrorLogSpecImpl(getTestRequestIdLogInfo(), getTestServiceLogInfo(), getTestTargetServiceLogInfo()
144                 , getTestErrorLogInfo());
145     }
146
147     protected static OptionalLogSpec getTestOptionalLogSpec() {
148         final MessageLogInfo messageLogInfo = new MessageLogInfoImpl(new Date(), RequestStatusCode.COMPLETE,
149                 NagiosAlertLevel.OK);
150         final CodeLogInfo codeLogInfo = new CodeLogInfoImpl(TEST_THREAD_ID, TEST_CLASS_NAME);
151         final CustomFieldsLogInfo customFieldsLogInfo = new CustomFieldsLogInfoImpl(TEST_CUSTOM_FIELD1,
152                 TEST_CUSTOM_FIELD2, TEST_CUSTOM_FIELD3, TEST_CUSTOM_FIELD4);
153         final MiscLogInfo miscLogInfo = new MiscLogInfoImpl(TEST_PROCESS_KEY, "");
154         return new OptionalLogSpecImpl(messageLogInfo, codeLogInfo, customFieldsLogInfo, miscLogInfo);
155     }
156
157 }