2 * Copyright 2021 ZTE Corporation.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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
15 package org.onap.holmes.common.utils;
17 import org.junit.Test;
19 import static org.hamcrest.CoreMatchers.equalTo;
20 import static org.hamcrest.core.Is.is;
21 import static org.junit.Assert.assertThat;
23 public class CommonUtilsTest {
25 public void isHttpsEnabled_normal_true() throws Exception {
26 System.setProperty("ENABLE_ENCRYPT", "true");
27 assertThat(CommonUtils.isHttpsEnabled(), is(true));
31 public void isHttpsEnabled_normal_false() throws Exception {
32 System.setProperty("ENABLE_ENCRYPT", "false");
33 assertThat(CommonUtils.isHttpsEnabled(), is(false));
37 public void isHttpsEnabled_invalid_input() throws Exception {
38 System.setProperty("ENABLE_ENCRYPT", "whatever");
39 assertThat(CommonUtils.isHttpsEnabled(), is(false));
43 public void getEnv() throws Exception {
44 System.setProperty("TEST", "COMMON_UTILS");
45 assertThat(CommonUtils.getEnv("TEST"), equalTo("COMMON_UTILS"));
49 public void isValidIpAddress_with_port() throws Exception {
50 boolean res = CommonUtils.isIpAddress("10.75.13.21:90");
51 assertThat(res, is(true));
55 public void isValidIpAddress_without_port() throws Exception {
56 boolean res = CommonUtils.isIpAddress("10.75.13.21");
57 assertThat(res, is(true));
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));
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));
73 public void isValidIpAddress_invalid_ip_without_port() throws Exception {
74 boolean res = CommonUtils.isIpAddress("holmes-rule-mgmt");
75 assertThat(res, is(false));
79 public void isValidIpAddress_invalid_ip_with_port() throws Exception {
80 boolean res = CommonUtils.isIpAddress("holmes-rule-mgmt:443");
81 assertThat(res, is(false));
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));
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));