1 /*******************************************************************************
2 * Copyright 2016-2017 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
13 ******************************************************************************/
14 package org.onap.msb.apiroute.wrapper.util;
16 import org.junit.Assert;
17 import org.junit.Test;
19 public class RegExpTestUtilTest {
22 public void test_HostRegExpTest() {
23 Assert.assertTrue(RegExpTestUtil.hostRegExpTest("127.0.0.1:8080"));
24 Assert.assertFalse(RegExpTestUtil.hostRegExpTest("0.0.0.1:89"));
30 public void test_IpRegExpTest() {
31 Assert.assertTrue(RegExpTestUtil.ipRegExpTest("127.0.0.1"));
32 Assert.assertFalse(RegExpTestUtil.ipRegExpTest("127.0.0.1.5"));
38 public void test_PortRegExpTest() {
39 Assert.assertTrue(RegExpTestUtil.portRegExpTest("80"));
40 Assert.assertFalse(RegExpTestUtil.portRegExpTest("898989"));
45 public void test_VersionRegExpTest() {
46 Assert.assertTrue(RegExpTestUtil.versionRegExpTest("v1"));
47 Assert.assertFalse(RegExpTestUtil.versionRegExpTest("23"));
53 public void test_urlRegExpTest() {
54 Assert.assertTrue(RegExpTestUtil.urlRegExpTest("/test"));
55 Assert.assertTrue(RegExpTestUtil.urlRegExpTest("/"));
56 Assert.assertFalse(RegExpTestUtil.urlRegExpTest("test"));
61 public void test_apiRouteUrlRegExpTest() {
62 Assert.assertTrue(RegExpTestUtil.apiRouteUrlRegExpTest("/api/test/v1"));
63 Assert.assertFalse(RegExpTestUtil.apiRouteUrlRegExpTest("/test"));
69 public void test_iuiRouteUrlRegExpTest() {
70 Assert.assertTrue(RegExpTestUtil.iuiRouteUrlRegExpTest("/iui/test"));
71 Assert.assertFalse(RegExpTestUtil.iuiRouteUrlRegExpTest("/test"));
75 public void test_apiServiceNameMatch4URL() {
76 String[] apiServiceNameArray = {"testApiName", "v1"};
77 Assert.assertArrayEquals(apiServiceNameArray, RegExpTestUtil.apiServiceNameMatch4URL("/api/testApiName/v1"));
79 String[] apiServiceNameArray_noversion = {"testApiName", ""};
80 Assert.assertArrayEquals(apiServiceNameArray_noversion,
81 RegExpTestUtil.apiServiceNameMatch4URL("/api/testApiName"));
83 Assert.assertNull(RegExpTestUtil.apiServiceNameMatch4URL("/apiw/name/v1"));
87 public void test_iuiServiceNameMatch4URL() {
88 String iuiServiceName = "testIuiName";
89 Assert.assertEquals(iuiServiceName, RegExpTestUtil.iuiServiceNameMatch4URL("/iui/testIuiName"));
91 Assert.assertNull(RegExpTestUtil.iuiServiceNameMatch4URL("/api/name/v1"));