Divide the MSB source codes into two repos
[msb/apigateway.git] / apiroute / apiroute-service / src / test / java / org / onap / msb / apiroute / wrapper / util / RegExpTestUtilTest.java
1 /**
2  * Copyright 2016 ZTE, Inc. and others.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.msb.apiroute.wrapper.util;
17
18 import org.junit.Assert;
19 import org.junit.Test;
20 import org.onap.msb.apiroute.wrapper.util.RegExpTestUtil;
21
22 public class RegExpTestUtilTest {
23
24     @Test
25     public void test_HostRegExpTest(){
26         Assert.assertTrue(RegExpTestUtil.hostRegExpTest("127.0.0.1:8080"));
27         Assert.assertFalse(RegExpTestUtil.hostRegExpTest("0.0.0.1:89"));
28     }
29     
30   
31     
32     @Test
33     public void test_IpRegExpTest(){
34         Assert.assertTrue(RegExpTestUtil.ipRegExpTest("127.0.0.1"));
35         Assert.assertFalse(RegExpTestUtil.ipRegExpTest("127.0.0.1.5"));
36     }
37     
38  
39     
40     @Test
41     public void test_PortRegExpTest(){
42         Assert.assertTrue(RegExpTestUtil.portRegExpTest("80"));        
43         Assert.assertFalse(RegExpTestUtil.portRegExpTest("898989"));
44     }
45     
46     
47     @Test
48     public void test_VersionRegExpTest(){
49         Assert.assertTrue(RegExpTestUtil.versionRegExpTest("v1"));
50         Assert.assertFalse(RegExpTestUtil.versionRegExpTest("23"));
51     }
52     
53  
54     
55     @Test
56     public void test_urlRegExpTest(){
57         Assert.assertTrue(RegExpTestUtil.urlRegExpTest("/test"));
58         Assert.assertTrue(RegExpTestUtil.urlRegExpTest("/"));
59         Assert.assertFalse(RegExpTestUtil.urlRegExpTest("test"));
60     }
61     
62  
63     @Test
64     public void test_apiRouteUrlRegExpTest(){
65         Assert.assertTrue(RegExpTestUtil.apiRouteUrlRegExpTest("/api/test/v1"));
66         Assert.assertFalse(RegExpTestUtil.apiRouteUrlRegExpTest("/test"));
67     }
68     
69  
70     
71     @Test
72     public void test_iuiRouteUrlRegExpTest(){
73         Assert.assertTrue(RegExpTestUtil.iuiRouteUrlRegExpTest("/iui/test"));
74         Assert.assertFalse(RegExpTestUtil.iuiRouteUrlRegExpTest("/test"));
75     }   
76     
77     @Test
78     public void test_apiServiceNameMatch4URL(){
79       String[] apiServiceNameArray={"testApiName","v1"};
80       Assert.assertArrayEquals(apiServiceNameArray, RegExpTestUtil.apiServiceNameMatch4URL("/api/testApiName/v1"));
81       
82       String[] apiServiceNameArray_noversion={"testApiName",""};
83       Assert.assertArrayEquals(apiServiceNameArray_noversion, RegExpTestUtil.apiServiceNameMatch4URL("/api/testApiName"));
84
85       Assert.assertNull(RegExpTestUtil.apiServiceNameMatch4URL("/apiw/name/v1"));
86     }
87     
88     @Test
89     public void test_iuiServiceNameMatch4URL(){
90       String iuiServiceName="testIuiName";
91       Assert.assertEquals(iuiServiceName, RegExpTestUtil.iuiServiceNameMatch4URL("/iui/testIuiName"));
92       
93       Assert.assertNull(RegExpTestUtil.iuiServiceNameMatch4URL("/api/name/v1"));
94     }
95   
96 }