2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.logging.filter.base;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
27 import java.util.UUID;
29 import org.junit.After;
30 import org.junit.Test;
31 import org.onap.logging.filter.base.Constants;
32 import org.onap.logging.ref.slf4j.ONAPLogConstants;
36 public class ScheduledTasksMDCSetupAspectTest {
38 private ScheduledTasksMDCSetupAspect tasksMDCSetup = new ScheduledTasksMDCSetupAspect();
41 public void tearDown() {
43 System.clearProperty("partnerName");
47 public void mdcSetupTest() {
48 System.setProperty("partnerName", ONAPComponents.SO.toString());
49 tasksMDCSetup.setupMDC("mdcSetupTest");
51 assertTrue(isValidUUID(MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)));
52 assertTrue(isValidUUID(MDC.get(ONAPLogConstants.MDCs.INVOCATION_ID)));
53 assertEquals(ONAPComponents.SO.toString(), MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY));
54 assertEquals(ONAPComponents.SO.toString(), MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME));
55 assertEquals("mdcSetupTest", MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME));
56 assertEquals(Constants.DefaultValues.UNKNOWN, MDC.get(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME));
57 assertNotNull(MDC.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
58 assertNotNull(MDC.get(ONAPLogConstants.MDCs.ELAPSED_TIME));
59 assertNotNull(MDC.get(ONAPLogConstants.MDCs.LOG_TIMESTAMP));
60 assertNotNull(MDC.get(ONAPLogConstants.MDCs.SERVER_FQDN));
64 public void errorMDCSetupTest() {
65 tasksMDCSetup.errorMDCSetup(ErrorCode.UnknownError, "Error");
67 assertEquals("900", MDC.get(ONAPLogConstants.MDCs.ERROR_CODE));
68 assertEquals("Error", MDC.get(ONAPLogConstants.MDCs.ERROR_DESC));
72 public void setStatusCodeTest() {
73 tasksMDCSetup.setStatusCode();
75 assertEquals(ONAPLogConstants.ResponseStatus.COMPLETE.toString(),
76 MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
80 public void setStatusCodeErrorTest() {
81 MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.ERROR.toString());
82 tasksMDCSetup.setStatusCode();
84 assertEquals(ONAPLogConstants.ResponseStatus.ERROR.toString(),
85 MDC.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
88 public static boolean isValidUUID(String id) {
93 UUID uuid = UUID.fromString(id);
94 return uuid.toString().equalsIgnoreCase(id);
95 } catch (IllegalArgumentException iae) {