summaryrefslogtreecommitdiffstats
path: root/eelf-logger/eelf-logger-logback-impl/src/test/java/org/onap/dcae/utils/eelf/logger/logback/BaseLogbackUnitTest.java
blob: fda4355e987bd2f2253d8d559c4a8939f7f01be8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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);
    }

}