1 /*******************************************************************************
2 * ============LICENSE_START==================================================
4 * * ===========================================================================
5 * * Copyright © 2017 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====================================================
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 ******************************************************************************/
23 package org.onap.dmaap.datarouter.node;
25 import static org.mockito.Mockito.when;
27 import jakarta.servlet.http.HttpServletRequest;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.onap.dmaap.datarouter.node.utils.NodeUtils;
33 import org.powermock.core.classloader.annotations.PowerMockIgnore;
34 import org.powermock.modules.junit4.PowerMockRunner;
37 @RunWith(PowerMockRunner.class)
38 @PowerMockIgnore({"java.net.ssl", "com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
39 public class NodeUtilsTest {
42 private HttpServletRequest request;
45 public void Given_Uri_With_Params_Then_Get_Feed_And_File_Id_Returns_Correct_Values() {
46 String uri = "prov.datarouternew.com:8443/feed/12/fileName";
47 String[] uriParams = NodeUtils.getFeedAndFileID(uri);
48 assert uriParams != null;
49 Assert.assertEquals("12", uriParams[0]);
50 Assert.assertEquals("fileName", uriParams[1]);
54 public void Given_Uri_With_Illegal_Params_Then_Get_Feed_And_File_Id_Returns_Null() {
55 String uri = "prov.datarouternew.com:8443/feed";
56 String[] uriParams = NodeUtils.getFeedAndFileID(uri);
57 Assert.assertNull(uriParams);
61 public void Given_String_With_Escape_Fields_Then_Loge_Returns_Special_Chars() {
62 String s = NodeUtils.loge("\\search|pub|12\n");
63 Assert.assertEquals("\\esearch\\ppub\\p12\\n", s);
67 public void Given_String_With_Special_Chars_Then_Loge_Returns_String_With_Escape_Fields() {
68 String s = NodeUtils.unloge("\\esearch\\ppub\\p12\\n");
69 Assert.assertEquals("\\search|pub|12\n", s);
73 public void Given_Request_Has_RequestId_And_InvocationId_Headers_Set_MDC_Values() {
74 when(request.getHeader("X-ONAP-RequestID")).thenReturn("123");
75 when(request.getHeader("X-InvocationID")).thenReturn("456");
76 NodeUtils.setRequestIdAndInvocationId(request);
77 Assert.assertEquals("123", MDC.get("RequestId"));
78 Assert.assertEquals("456", MDC.get("InvocationId"));