2 * ============LICENSE_START=======================================================
3 * Copyright (c) 2022 Huawei. 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
9 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.dcae.analytics.web.util;
22 import org.junit.jupiter.api.Test;
23 import org.springframework.http.HttpHeaders;
24 import org.springframework.messaging.MessageHeaders;
26 import java.util.Date;
27 import java.util.HashMap;
30 import static org.junit.jupiter.api.Assertions.assertEquals;
31 import static org.junit.jupiter.api.Assertions.assertNotNull;
33 public class AnalyticsHttpUtilsTest {
36 public void createDefaultHttpHeadersTest () throws Exception {
37 HttpHeaders httpHeaders = AnalyticsHttpUtils.createDefaultHttpHeaders();
38 httpHeaders.set("X-TransactionID", "transactionID");
39 String transactionId = AnalyticsHttpUtils.getTransactionId(httpHeaders);
40 assertEquals("transactionID", transactionId);
44 public void createDefaultHttpHeadersRequestIDTest () throws Exception {
45 HttpHeaders httpHeaders = AnalyticsHttpUtils.createDefaultHttpHeaders("requestID");
46 String requestId = AnalyticsHttpUtils.getRequestId(httpHeaders);
47 assertEquals("requestID", requestId);
51 public void createDefaultHttpHeadersTransactionIDTest () throws Exception {
52 HttpHeaders httpHeaders = AnalyticsHttpUtils.createDefaultHttpHeaders();
53 httpHeaders.set("X-TransactionID", "transactionID");
54 String requestId = AnalyticsHttpUtils.getTransactionId(httpHeaders);
55 assertEquals("transactionID", requestId);
59 public void getTransactionIdTest () throws Exception {
60 MessageHeaders httpHeaders = new MessageHeaders(null);
61 String transactionId = AnalyticsHttpUtils.getTransactionId(httpHeaders);
62 assertEquals("UNKNOWN-TRANSACTION_ID", transactionId);
66 public void getRequestIdTest () throws Exception {
67 MessageHeaders httpHeaders = new MessageHeaders(null);
68 String requestId = AnalyticsHttpUtils.getRequestId(httpHeaders);
69 assertEquals("UNKNOWN-REQUEST_ID", requestId);
73 public void getTimestampFromHeadersTest () throws Exception {
74 Map<String, Object> headers = new HashMap<String, Object>();
75 Date dt = AnalyticsHttpUtils.getTimestampFromHeaders(headers, null);