msb discovery java client
[msb/java-sdk.git] / src / main / java / org / onap / msb / sdk / discovery / util / RegExpTestUtil.java
1 /*******************************************************************************
2  * Copyright 2017 ZTE, Inc. and others.
3  * 
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  * 
7  * http://www.apache.org/licenses/LICENSE-2.0
8  * 
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 package org.onap.msb.sdk.discovery.util;
15
16 import java.util.regex.Pattern;
17
18 public class RegExpTestUtil {
19
20   public static boolean serviceNameRegExpTest(String serviceName) {
21
22     String serviceNameReg = "^([0-9a-zA-Z]|-|_)*$";
23     return Pattern.matches(serviceNameReg, serviceName);
24
25   }
26
27
28   public static boolean hostRegExpTest(String host) {
29
30     String hostReg = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
31         + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
32         + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
33         + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)" + ":(\\d{1,5})$";
34     return Pattern.matches(hostReg, host);
35
36   }
37
38   public static boolean ipRegExpTest(String ip) {
39
40     String hostReg = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
41         + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
42         + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
43         + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
44     return Pattern.matches(hostReg, ip);
45
46   }
47
48   public static boolean portRegExpTest(String port) {
49
50     String hostReg = "^\\d{1,5}$";
51     return Pattern.matches(hostReg, port);
52
53   }
54
55   public static boolean versionRegExpTest(String version) {
56
57     String versionReg = "^v\\d+(\\.\\d+)?$";
58     return Pattern.matches(versionReg, version);
59
60   }
61
62   public static boolean urlRegExpTest(String url) {
63     if (url.equals("/"))
64       return true;
65     String urlReg = "^\\/.*((?!\\/).)$";
66     return Pattern.matches(urlReg, url);
67
68   }
69
70
71
72   public static void main(String[] args) {
73     System.out.println(urlRegExpTest("/"));
74   }
75 }