2 * Copyright 2016-2018 ZTE, Inc. and others.
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
14 package org.onap.msb.sdclient.wrapper.util;
16 import java.util.regex.Pattern;
18 import org.apache.commons.lang3.StringUtils;
20 public class RegExpTestUtil {
22 public static boolean httpUrlRegExpTest(String url) {
26 String httpUrlReg = "^(|https:\\/\\/|http:\\/\\/)(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
27 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
28 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
29 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)" + ":(\\d{1,5}).*$";
30 return Pattern.matches(httpUrlReg, url);
34 public static boolean hostRegExpTest(String host) {
36 String hostReg = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
37 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
38 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
39 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)" + ":(\\d{1,5})$";
40 return Pattern.matches(hostReg, host);
44 public static boolean ipRegExpTest(String ip) {
46 String hostReg = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
47 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
48 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
49 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
50 return Pattern.matches(hostReg, ip);
54 public static boolean portRegExpTest(String port) {
56 String hostReg = "^\\d{1,5}$";
57 if (Pattern.matches(hostReg, port)) {
58 int iport = Integer.parseInt(port);
59 if (iport >= 1 && iport <= 65535)
67 public static boolean versionRegExpTest(String version) {
69 String versionReg = "^v\\d+(\\.\\d+)?$";
70 return Pattern.matches(versionReg, version);
74 public static boolean urlRegExpTest(String url) {
78 String urlReg = "^\\/.*((?!\\/).)$";
79 return Pattern.matches(urlReg, url);
83 public static boolean serviceNameRegExpTest(String serviceName) {
85 String serviceNameReg = "^([0-9a-zA-Z]|-|_)*$";
86 return Pattern.matches(serviceNameReg, serviceName);
90 public static boolean apiRouteUrlRegExpTest(String url) {
92 String urlReg = "^\\/api\\/.*$";
93 return Pattern.matches(urlReg, url);
97 public static boolean labelRegExpTest(String label) {
99 String labelReg = "^\\S+:\\S+$";
100 String[] labelArray = StringUtils.split(label, ",");
101 for (int i = 0; i < labelArray.length; i++) {
102 if (!Pattern.matches(labelReg, labelArray[i])) {
111 public static void main(String[] args) {
113 System.out.println(httpUrlRegExpTest("/wqew"));