Remove Class: HttpsUtils & MicroserviceBusRest
[holmes/common.git] / holmes-actions / src / test / java / org / onap / holmes / common / utils / CommonUtilsTest.java
1 /**
2  * Copyright 2021 ZTE Corporation.
3  * <p>
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  * <p>
7  * http://www.apache.org/licenses/LICENSE-2.0
8  * <p>
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14
15 package org.onap.holmes.common.utils;
16
17 import org.junit.Test;
18
19 import static org.hamcrest.CoreMatchers.equalTo;
20 import static org.hamcrest.core.Is.is;
21 import static org.junit.Assert.assertThat;
22
23 public class CommonUtilsTest {
24     @Test
25     public void isHttpsEnabled_normal_true() throws Exception {
26         System.setProperty("ENABLE_ENCRYPT", "true");
27         assertThat(CommonUtils.isHttpsEnabled(), is(true));
28     }
29
30     @Test
31     public void isHttpsEnabled_normal_false() throws Exception {
32         System.setProperty("ENABLE_ENCRYPT", "false");
33         assertThat(CommonUtils.isHttpsEnabled(), is(false));
34     }
35
36     @Test
37     public void isHttpsEnabled_invalid_input() throws Exception {
38         System.setProperty("ENABLE_ENCRYPT", "whatever");
39         assertThat(CommonUtils.isHttpsEnabled(), is(false));
40     }
41
42     @Test
43     public void getEnv() throws Exception {
44         System.setProperty("TEST", "COMMON_UTILS");
45         assertThat(CommonUtils.getEnv("TEST"), equalTo("COMMON_UTILS"));
46     }
47
48     @Test
49     public void isValidIpAddress_with_port() throws Exception {
50         boolean res = CommonUtils.isIpAddress("10.75.13.21:90");
51         assertThat(res, is(true));
52     }
53
54     @Test
55     public void isValidIpAddress_without_port() throws Exception {
56         boolean res = CommonUtils.isIpAddress("10.75.13.21");
57         assertThat(res, is(true));
58     }
59
60     @Test
61     public void isValidIpAddress_with_port_with_http_prefix() throws Exception {
62         boolean res = CommonUtils.isIpAddress("http://10.75.13.21:90");
63         assertThat(res, is(true));
64     }
65
66     @Test
67     public void isValidIpAddress_without_port_with_https_prefix() throws Exception {
68         boolean res = CommonUtils.isIpAddress("https://10.75.13.21");
69         assertThat(res, is(true));
70     }
71
72     @Test
73     public void isValidIpAddress_invalid_ip_without_port() throws Exception {
74         boolean res = CommonUtils.isIpAddress("holmes-rule-mgmt");
75         assertThat(res, is(false));
76     }
77
78     @Test
79     public void isValidIpAddress_invalid_ip_with_port() throws Exception {
80         boolean res = CommonUtils.isIpAddress("holmes-rule-mgmt:443");
81         assertThat(res, is(false));
82     }
83
84     @Test
85     public void isValidIpAddress_invalid_ip_without_port_with_http_prefix() throws Exception {
86         boolean res = CommonUtils.isIpAddress("http://holmes-rule-mgmt");
87         assertThat(res, is(false));
88     }
89
90     @Test
91     public void isValidIpAddress_invalid_ip_with_port_with_https_prefix() throws Exception {
92         boolean res = CommonUtils.isIpAddress("https://holmes-rule-mgmt:443");
93         assertThat(res, is(false));
94     }
95 }