aboutsummaryrefslogtreecommitdiffstats
path: root/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util
diff options
context:
space:
mode:
Diffstat (limited to 'apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util')
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/CommonUtilTest.java97
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/ConfigUtilTest.java394
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/HttpClientUtilTest.java51
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/JacksonJsonUtilTest.java120
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/JedisUtilTest.java35
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/MicroServiceUtilTest.java71
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/RegExpTestUtilTest.java100
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/RouteUtilTest.java634
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/ServiceFilterTest.java357
9 files changed, 910 insertions, 949 deletions
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/CommonUtilTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/CommonUtilTest.java
index 07f2b86..6a3bfb7 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/CommonUtilTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/CommonUtilTest.java
@@ -1,17 +1,15 @@
/*******************************************************************************
* Copyright 2016-2017 ZTE, Inc. and others.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
******************************************************************************/
package org.onap.msb.apiroute.wrapper.util;
@@ -20,57 +18,56 @@ import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
-import org.onap.msb.apiroute.wrapper.util.CommonUtil;
public class CommonUtilTest {
-
- @Test
- public void test_concat() {
- Object[] str1 = new String[] {"test1", "test2"};
- Object[] str2 = new String[] {"test3"};
- Object[] str3 = CommonUtil.concat(str1, str2);
- Assert.assertEquals(3, str3.length);
- }
+ @Test
+ public void test_concat() {
+ Object[] str1 = new String[] {"test1", "test2"};
+ Object[] str2 = new String[] {"test3"};
+ Object[] str3 = CommonUtil.concat(str1, str2);
- @Test
- public void test_containStr() {
- String value = "1";
- String array[] = {"1", "2"};
- Assert.assertTrue(CommonUtil.contain(array, value));
- Assert.assertFalse(CommonUtil.contain(array, "3"));
- }
+ Assert.assertEquals(3, str3.length);
+ }
- @Test
- public void test_containArray() {
- String value[] = {"0"};
- String array[] = {"1", "2"};
- String array2[] = {"2", "1"};
- Assert.assertFalse(CommonUtil.contain(array, value));
- Assert.assertTrue(CommonUtil.contain(array, array2));
- }
+ @Test
+ public void test_containStr() {
+ String value = "1";
+ String array[] = {"1", "2"};
+ Assert.assertTrue(CommonUtil.contain(array, value));
+ Assert.assertFalse(CommonUtil.contain(array, "3"));
+ }
- @Test
- public void test_containStrArray() {
- Assert.assertFalse(CommonUtil.contain("0,1,2", "3"));
- Assert.assertTrue(CommonUtil.contain("0,1,2", "1"));
- }
+ @Test
+ public void test_containArray() {
+ String value[] = {"0"};
+ String array[] = {"1", "2"};
+ String array2[] = {"2", "1"};
+ Assert.assertFalse(CommonUtil.contain(array, value));
+ Assert.assertTrue(CommonUtil.contain(array, array2));
+ }
- @Test
- public void test_getDiffrent() {
- Set<String> list1 = new HashSet<String>();
- list1.add("test1");
- list1.add("test2");
+ @Test
+ public void test_containStrArray() {
+ Assert.assertFalse(CommonUtil.contain("0,1,2", "3"));
+ Assert.assertTrue(CommonUtil.contain("0,1,2", "1"));
+ }
- Set<String> list2 = new HashSet<String>();
- list2.add("test2");
- list2.add("test3");
+ @Test
+ public void test_getDiffrent() {
+ Set<String> list1 = new HashSet<String>();
+ list1.add("test1");
+ list1.add("test2");
- Set<String> diff = CommonUtil.getDiffrent(list1, list2);
- Assert.assertEquals(1, diff.size());
- Assert.assertTrue(diff.contains("test3"));
- }
+ Set<String> list2 = new HashSet<String>();
+ list2.add("test2");
+ list2.add("test3");
+
+ Set<String> diff = CommonUtil.getDiffrent(list1, list2);
+ Assert.assertEquals(1, diff.size());
+ Assert.assertTrue(diff.contains("test3"));
+ }
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/ConfigUtilTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/ConfigUtilTest.java
index c32b6c0..51a06df 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/ConfigUtilTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/ConfigUtilTest.java
@@ -1,17 +1,15 @@
/*******************************************************************************
* Copyright 2016-2017 ZTE, Inc. and others.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
******************************************************************************/
package org.onap.msb.apiroute.wrapper.util;
@@ -24,7 +22,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.msb.apiroute.ApiRouteAppConfig;
import org.onap.msb.apiroute.api.DiscoverInfo;
-import org.onap.msb.apiroute.wrapper.util.ConfigUtil;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -33,197 +30,196 @@ import org.powermock.modules.junit4.PowerMockRunner;
@PrepareForTest({ConfigUtil.class})
public class ConfigUtilTest {
- @Test
- public void test_initRootPath() {
- try {
- ConfigUtil.getInstance().initRootPath();
- String iuiRootPath = ConfigUtil.getInstance().getIUI_ROOT_PATH();
- String apiRootPath = ConfigUtil.getInstance().getAPI_ROOT_PATH();
- Assert.assertEquals("iui", iuiRootPath);
- Assert.assertEquals("api", apiRootPath);
- } catch (Exception e) {
- Assert.fail("throw exception means error occured!" + e.getMessage());
+ @Test
+ public void test_initRootPath() {
+ try {
+ ConfigUtil.getInstance().initRootPath();
+ String iuiRootPath = ConfigUtil.getInstance().getIUI_ROOT_PATH();
+ String apiRootPath = ConfigUtil.getInstance().getAPI_ROOT_PATH();
+ Assert.assertEquals("iui", iuiRootPath);
+ Assert.assertEquals("api", apiRootPath);
+ } catch (Exception e) {
+ Assert.fail("throw exception means error occured!" + e.getMessage());
+
+ }
+
+ }
+
+ @Test
+ public void test_initApiGatewayPort() {
+
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.getenv("APIGATEWAY_EXPOSE_PORT")).thenReturn(null);
+ ConfigUtil.getInstance().initApiGatewayPort();
+ Assert.assertEquals("80", ConfigUtil.getInstance().getServerPort());
+
+
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.getenv("APIGATEWAY_EXPOSE_PORT")).thenReturn("81");
+
+ ConfigUtil.getInstance().initApiGatewayPort();
+ Assert.assertEquals("81", ConfigUtil.getInstance().getServerPort());
+ }
+
+ @Test
+ public void test_initRouteNameSpaceMatches() {
+
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.getenv("APIGATEWAY_EXPOSE_PORT")).thenReturn(null);
+ ConfigUtil.getInstance().initRouteNameSpaceMatches();
+ Assert.assertEquals("all", ConfigUtil.getInstance().getNamespaceMatches());
+
+
+ PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("net");
+
+ ConfigUtil.getInstance().initRouteNameSpaceMatches();
+ Assert.assertEquals("net", ConfigUtil.getInstance().getNamespaceMatches());
+ }
+
+ @Test
+ public void test_initRouteLabelsMatches() {
+
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn(null);
+ ConfigUtil.getInstance().initRouteLabelsMatches();
+ Assert.assertEquals("0", ConfigUtil.getInstance().getVisualRangeMatches());
+ Assert.assertEquals("net", ConfigUtil.getInstance().getNetwork_plane_typeMatches());
+ Assert.assertTrue(ConfigUtil.getInstance().getLabelMapMatches().containsKey("custom-key"));
+
+
+
+ PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn("visualRange:1,network_plane_type:net,custom:test");
+
+ ConfigUtil.getInstance().initRouteLabelsMatches();
+ Assert.assertEquals("1", ConfigUtil.getInstance().getVisualRangeMatches());
+ Assert.assertEquals("net", ConfigUtil.getInstance().getNetwork_plane_typeMatches());
+ Assert.assertTrue(ConfigUtil.getInstance().getLabelMapMatches().containsKey("custom"));
+
+ }
+
+ @Test
+ public void test_initRouteWay() {
+ PowerMockito.mockStatic(System.class);
+
+ PowerMockito.when(System.getenv("ROUTE_WAY")).thenReturn(null);
+ ConfigUtil.getInstance().initRouteWay();
+ String[] ip_routeWay = {"ip"};
+ Assert.assertArrayEquals(ip_routeWay, ConfigUtil.getInstance().getRouteWay());
+
+ PowerMockito.when(System.getenv("ROUTE_WAY")).thenReturn("ip|domain");
+
+ ConfigUtil.getInstance().initRouteWay();
+ String[] routeWay = {"ip", "domain"};
+ Assert.assertArrayEquals(routeWay, ConfigUtil.getInstance().getRouteWay());
+ }
+
+ @Test
+ public void test_initDiscoverInfo() {
+ PowerMockito.mockStatic(System.class);
+
+
+ ApiRouteAppConfig configuration = new ApiRouteAppConfig();
+
+ DiscoverInfo discoverInfo = new DiscoverInfo();
+ discoverInfo.setEnabled(true);
+ discoverInfo.setIp("127.0.0.1");
+ discoverInfo.setPort(10081);
+
+ configuration.setDiscoverInfo(discoverInfo);
+ PowerMockito.when(System.getenv("SDCLIENT_IP")).thenReturn(null);
+ ConfigUtil.getInstance().initDiscoverInfo(configuration);
+ Assert.assertEquals("127.0.0.1:10081", ConfigUtil.getInstance().getDiscoverInfo().toString());
+
+ PowerMockito.when(System.getenv("SDCLIENT_IP")).thenReturn("10.74.44.86");
+ ConfigUtil.getInstance().initDiscoverInfo(configuration);
+ Assert.assertEquals("10.74.44.86:10081", ConfigUtil.getInstance().getDiscoverInfo().toString());
+ }
+
+ @Test
+ public void test_initNodeMeta() {
+
+ // CONSUL_REGISTER_MODE not catalog
+ ConfigUtil util = ConfigUtil.getInstance();
+ util.initNodeMetaQueryParam();
+ System.out.println(util.getNodeMetaQueryParam());
+ Assert.assertEquals(util.getNodeMetaQueryParam(), "");
+
+ // CONSUL_REGISTER_MODE catalog
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.getenv("CONSUL_REGISTER_MODE")).thenReturn("agnet");
+ util.initNodeMetaQueryParam();
+ System.out.println(util.getNodeMetaQueryParam());
+ Assert.assertEquals(util.getNodeMetaQueryParam(), "");
+
+
+ // CONSUL_REGISTER_MODE catalog
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.getenv("CONSUL_REGISTER_MODE")).thenReturn("catalog");
+ try {
+ Field visualRangeField = util.getClass().getDeclaredField("visualRangeMatches");
+ visualRangeField.setAccessible(true);
+
+ Field namespaceField = util.getClass().getDeclaredField("namespaceMatches");
+ namespaceField.setAccessible(true);
+
+ // 0:default;
+ visualRangeField.set(util, "0");
+ namespaceField.set(util, "default");
+
+ util.initNodeMetaQueryParam();
+ System.out.println(util.getNodeMetaQueryParam());
+ Assert.assertEquals(util.getNodeMetaQueryParam(), "node-meta=external:true&node-meta=ns:default");
+
+ // 1:default;
+ visualRangeField.set(util, "1");
+ util.initNodeMetaQueryParam();
+ System.out.println(util.getNodeMetaQueryParam());
+ Assert.assertEquals(util.getNodeMetaQueryParam(), "node-meta=internal:true&node-meta=ns:default");
+
+ // 0|1:default
+ visualRangeField.set(util, "0|1");
+ util.initNodeMetaQueryParam();
+ System.out.println(util.getNodeMetaQueryParam());
+ Assert.assertEquals(util.getNodeMetaQueryParam(), "node-meta=ns:default");
+
+ // 0|1:all
+ namespaceField.set(util, "all");
+ util.initNodeMetaQueryParam();
+ System.out.println(util.getNodeMetaQueryParam());
+ Assert.assertEquals(util.getNodeMetaQueryParam(), "");
+
+ ///////////////////////////////////////////////////////////////////////////
+ // 1:all
+ visualRangeField.set(util, "1");
+ namespaceField.set(util, "all");
+ util.initNodeMetaQueryParam();
+ System.out.println(util.getNodeMetaQueryParam());
+ Assert.assertEquals(util.getNodeMetaQueryParam(), "node-meta=internal:true");
+
+ // 1:!
+ namespaceField.set(util, "!default");
+ util.initNodeMetaQueryParam();
+ System.out.println(util.getNodeMetaQueryParam());
+ Assert.assertEquals(util.getNodeMetaQueryParam(), "node-meta=internal:true");
+
+ // 1:&
+ namespaceField.set(util, "tenant1&tenant2");
+ util.initNodeMetaQueryParam();
+ System.out.println(util.getNodeMetaQueryParam());
+ Assert.assertEquals(util.getNodeMetaQueryParam(), "node-meta=internal:true");
+
+ // 1:|
+ namespaceField.set(util, "tenant1|tenant2");
+ util.initNodeMetaQueryParam();
+ System.out.println(util.getNodeMetaQueryParam());
+ Assert.assertEquals(util.getNodeMetaQueryParam(), "node-meta=internal:true");
+
+ } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
- }
-
- @Test
- public void test_initApiGatewayPort() {
-
- PowerMockito.mockStatic(System.class);
- PowerMockito.when(System.getenv("APIGATEWAY_EXPOSE_PORT")).thenReturn(null);
- ConfigUtil.getInstance().initApiGatewayPort();
- Assert.assertEquals("80", ConfigUtil.getInstance().getServerPort());
-
-
- PowerMockito.mockStatic(System.class);
- PowerMockito.when(System.getenv("APIGATEWAY_EXPOSE_PORT")).thenReturn("81");
-
- ConfigUtil.getInstance().initApiGatewayPort();
- Assert.assertEquals("81", ConfigUtil.getInstance().getServerPort());
- }
-
- @Test
- public void test_initRouteNameSpaceMatches() {
-
- PowerMockito.mockStatic(System.class);
- PowerMockito.when(System.getenv("APIGATEWAY_EXPOSE_PORT")).thenReturn(null);
- ConfigUtil.getInstance().initRouteNameSpaceMatches();
- Assert.assertEquals("all", ConfigUtil.getInstance().getNamespaceMatches());
-
-
- PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("net");
-
- ConfigUtil.getInstance().initRouteNameSpaceMatches();
- Assert.assertEquals("net", ConfigUtil.getInstance().getNamespaceMatches());
- }
-
- @Test
- public void test_initRouteLabelsMatches() {
-
- PowerMockito.mockStatic(System.class);
- PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn(null);
- ConfigUtil.getInstance().initRouteLabelsMatches();
- Assert.assertEquals("0", ConfigUtil.getInstance().getVisualRangeMatches());
- Assert.assertEquals("net", ConfigUtil.getInstance().getNetwork_plane_typeMatches());
- Assert.assertTrue(ConfigUtil.getInstance().getLabelMapMatches().containsKey("custom-key"));
-
-
-
-
- PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn("visualRange:1,network_plane_type:net,custom:test");
-
- ConfigUtil.getInstance().initRouteLabelsMatches();
- Assert.assertEquals("1", ConfigUtil.getInstance().getVisualRangeMatches());
- Assert.assertEquals("net", ConfigUtil.getInstance().getNetwork_plane_typeMatches());
- Assert.assertTrue(ConfigUtil.getInstance().getLabelMapMatches().containsKey("custom"));
-
- }
-
- @Test
- public void test_initRouteWay() {
- PowerMockito.mockStatic(System.class);
-
- PowerMockito.when(System.getenv("ROUTE_WAY")).thenReturn(null);
- ConfigUtil.getInstance().initRouteWay();
- String[] ip_routeWay={"ip"};
- Assert.assertArrayEquals(ip_routeWay, ConfigUtil.getInstance().getRouteWay());
-
- PowerMockito.when(System.getenv("ROUTE_WAY")).thenReturn("ip|domain");
-
- ConfigUtil.getInstance().initRouteWay();
- String[] routeWay={"ip","domain"};
- Assert.assertArrayEquals(routeWay, ConfigUtil.getInstance().getRouteWay());
- }
-
- @Test
- public void test_initDiscoverInfo() {
- PowerMockito.mockStatic(System.class);
-
-
- ApiRouteAppConfig configuration=new ApiRouteAppConfig();
-
- DiscoverInfo discoverInfo=new DiscoverInfo();
- discoverInfo.setEnabled(true);
- discoverInfo.setIp("127.0.0.1");
- discoverInfo.setPort(10081);
-
- configuration.setDiscoverInfo(discoverInfo);
- PowerMockito.when(System.getenv("SDCLIENT_IP")).thenReturn(null);
- ConfigUtil.getInstance().initDiscoverInfo(configuration);
- Assert.assertEquals("127.0.0.1:10081", ConfigUtil.getInstance().getDiscoverInfo().toString());
-
- PowerMockito.when(System.getenv("SDCLIENT_IP")).thenReturn("10.74.44.86");
- ConfigUtil.getInstance().initDiscoverInfo(configuration);
- Assert.assertEquals("10.74.44.86:10081", ConfigUtil.getInstance().getDiscoverInfo().toString());
- }
-
- @Test
- public void test_initNodeMeta() {
-
- //CONSUL_REGISTER_MODE not catalog
- ConfigUtil util=ConfigUtil.getInstance();
- util.initNodeMetaQueryParam();
- System.out.println(util.getNodeMetaQueryParam());
- Assert.assertEquals(util.getNodeMetaQueryParam(),"");
-
- //CONSUL_REGISTER_MODE catalog
- PowerMockito.mockStatic(System.class);
- PowerMockito.when(System.getenv("CONSUL_REGISTER_MODE")).thenReturn("agnet");
- util.initNodeMetaQueryParam();
- System.out.println(util.getNodeMetaQueryParam());
- Assert.assertEquals(util.getNodeMetaQueryParam(),"");
-
-
- //CONSUL_REGISTER_MODE catalog
- PowerMockito.mockStatic(System.class);
- PowerMockito.when(System.getenv("CONSUL_REGISTER_MODE")).thenReturn("catalog");
- try {
- Field visualRangeField=util.getClass().getDeclaredField("visualRangeMatches");
- visualRangeField.setAccessible(true);
-
- Field namespaceField = util.getClass().getDeclaredField("namespaceMatches");
- namespaceField.setAccessible(true);
-
- //0:default;
- visualRangeField.set(util, "0");
- namespaceField.set(util, "default");
-
- util.initNodeMetaQueryParam();
- System.out.println(util.getNodeMetaQueryParam());
- Assert.assertEquals(util.getNodeMetaQueryParam(),"node-meta=external:true&node-meta=ns:default");
-
- //1:default;
- visualRangeField.set(util, "1");
- util.initNodeMetaQueryParam();
- System.out.println(util.getNodeMetaQueryParam());
- Assert.assertEquals(util.getNodeMetaQueryParam(),"node-meta=internal:true&node-meta=ns:default");
-
- //0|1:default
- visualRangeField.set(util, "0|1");
- util.initNodeMetaQueryParam();
- System.out.println(util.getNodeMetaQueryParam());
- Assert.assertEquals(util.getNodeMetaQueryParam(),"node-meta=ns:default");
-
- //0|1:all
- namespaceField.set(util, "all");
- util.initNodeMetaQueryParam();
- System.out.println(util.getNodeMetaQueryParam());
- Assert.assertEquals(util.getNodeMetaQueryParam(),"");
-
- ///////////////////////////////////////////////////////////////////////////
- //1:all
- visualRangeField.set(util, "1");
- namespaceField.set(util, "all");
- util.initNodeMetaQueryParam();
- System.out.println(util.getNodeMetaQueryParam());
- Assert.assertEquals(util.getNodeMetaQueryParam(),"node-meta=internal:true");
-
- //1:!
- namespaceField.set(util, "!default");
- util.initNodeMetaQueryParam();
- System.out.println(util.getNodeMetaQueryParam());
- Assert.assertEquals(util.getNodeMetaQueryParam(),"node-meta=internal:true");
-
- //1:&
- namespaceField.set(util, "tenant1&tenant2");
- util.initNodeMetaQueryParam();
- System.out.println(util.getNodeMetaQueryParam());
- Assert.assertEquals(util.getNodeMetaQueryParam(),"node-meta=internal:true");
-
- //1:|
- namespaceField.set(util, "tenant1|tenant2");
- util.initNodeMetaQueryParam();
- System.out.println(util.getNodeMetaQueryParam());
- Assert.assertEquals(util.getNodeMetaQueryParam(),"node-meta=internal:true");
-
- } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/HttpClientUtilTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/HttpClientUtilTest.java
index 61c19ad..338ab48 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/HttpClientUtilTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/HttpClientUtilTest.java
@@ -1,44 +1,33 @@
/*******************************************************************************
* Copyright 2016-2017 ZTE, Inc. and others.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
******************************************************************************/
package org.onap.msb.apiroute.wrapper.util;
-import java.io.IOException;
-
-import org.junit.Assert;
import org.junit.Test;
-import org.onap.msb.apiroute.wrapper.util.HttpClientUtil;
public class HttpClientUtilTest {
-
- private String testIp="http://10.74.151.26:8500";
-
- @Test
- public void test_httpGet() {
- /*try {
- int result = HttpClientUtil.httpGetStatus(testIp);
- if(result==200){
- Assert.assertEquals("Consul Agent", HttpClientUtil.httpGet(testIp));
- }
- else{
- Assert.assertEquals(500, result);
- }
-
- } catch (Exception e) {
- Assert.assertTrue(e instanceof IOException);
- }*/
- }
+ private String testIp = "http://10.74.151.26:8500";
+
+ @Test
+ public void test_httpGet() {
+ /*
+ * try { int result = HttpClientUtil.httpGetStatus(testIp); if(result==200){
+ * Assert.assertEquals("Consul Agent", HttpClientUtil.httpGet(testIp)); } else{
+ * Assert.assertEquals(500, result); }
+ *
+ *
+ * } catch (Exception e) { Assert.assertTrue(e instanceof IOException); }
+ */
+ }
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/JacksonJsonUtilTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/JacksonJsonUtilTest.java
index cff0b42..baf8b2a 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/JacksonJsonUtilTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/JacksonJsonUtilTest.java
@@ -1,17 +1,15 @@
/*******************************************************************************
* Copyright 2016-2017 ZTE, Inc. and others.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
******************************************************************************/
package org.onap.msb.apiroute.wrapper.util;
@@ -21,74 +19,72 @@ import org.junit.Assert;
import org.junit.Test;
import org.onap.msb.apiroute.api.PublishFullAddress;
import org.onap.msb.apiroute.api.RouteServer;
-import org.onap.msb.apiroute.wrapper.util.JacksonJsonUtil;
import com.fasterxml.jackson.core.type.TypeReference;
public class JacksonJsonUtilTest {
@Test
- public void testBeanToJson(){
- try{
- RouteServer server=new RouteServer("127.0.0.1","80");
- String json=JacksonJsonUtil.beanToJson(server);
- Assert.assertEquals("{\"ip\":\"127.0.0.1\",\"port\":\"80\",\"weight\":0}",json);
- }
- catch(Exception e){
+ public void testBeanToJson() {
+ try {
+ RouteServer server = new RouteServer("127.0.0.1", "80");
+ String json = JacksonJsonUtil.beanToJson(server);
+ Assert.assertEquals("{\"ip\":\"127.0.0.1\",\"port\":\"80\",\"weight\":0}", json);
+ } catch (Exception e) {
Assert.fail("Exception" + e.getMessage());
}
}
-
+
@Test
- public void testJsonToBean(){
- try{
- String json="{\"ip\":\"127.0.0.1\",\"port\":\"80\",\"weight\":0}";
- RouteServer server=(RouteServer) JacksonJsonUtil.jsonToBean(json, RouteServer.class);
- Assert.assertEquals("127.0.0.1",server.getIp());
- Assert.assertEquals("80",server.getPort());
- }
- catch(Exception e){
+ public void testJsonToBean() {
+ try {
+ String json = "{\"ip\":\"127.0.0.1\",\"port\":\"80\",\"weight\":0}";
+ RouteServer server = (RouteServer) JacksonJsonUtil.jsonToBean(json, RouteServer.class);
+ Assert.assertEquals("127.0.0.1", server.getIp());
+ Assert.assertEquals("80", server.getPort());
+ } catch (Exception e) {
Assert.fail("Exception" + e.getMessage());
}
}
-
-
-// @Test
-// public void testJsonToBean_Fail(){
-// try{
-// String json="{\"ip\":\"127.0.0.1\",\"port\":\"80\",\"weight\":0";
-// RouteServer server=(RouteServer) JacksonJsonUtil.jsonToBean(json, RouteServer.class);
-// }
-// catch(Exception e){
-// Assert.assertEquals("class org.onap.msb.apiroute.api.RouteServer JsonTobean faild",e.getMessage());
-// }
-// }
-
+
+
+ // @Test
+ // public void testJsonToBean_Fail(){
+ // try{
+ // String json="{\"ip\":\"127.0.0.1\",\"port\":\"80\",\"weight\":0";
+ // RouteServer server=(RouteServer) JacksonJsonUtil.jsonToBean(json, RouteServer.class);
+ // }
+ // catch(Exception e){
+ // Assert.assertEquals("class org.onap.msb.apiroute.api.RouteServer JsonTobean
+ // faild",e.getMessage());
+ // }
+ // }
+
@Test
- public void testJsonToListBean(){
- try{
- String resultJson="[{\"domain\": \"wudith.openpalette.zte.com.cn\",\"port\": \"80\",\"publish_url\": \"/api/wudith/v1\",\"visualRange\": \"0\",\"publish_protocol\": \"http\"},"
- + "{\"ip\": \"10.74.165.246\",\"port\": \"80\",\"publish_url\": \"/api/wudith/v1\",\"visualRange\": \"0\",\"publish_protocol\": \"http\"}]";
- List<PublishFullAddress> publishFullAddressList =
- JacksonJsonUtil.jsonToListBean(resultJson, new TypeReference<List<PublishFullAddress>>() {});
- Assert.assertEquals(2,publishFullAddressList.size());
- Assert.assertEquals("80",publishFullAddressList.get(0).getPort());
- }
- catch(Exception e){
- Assert.fail("Exception" + e.getMessage());
- }
+ public void testJsonToListBean() {
+ try {
+ String resultJson =
+ "[{\"domain\": \"wudith.openpalette.zte.com.cn\",\"port\": \"80\",\"publish_url\": \"/api/wudith/v1\",\"visualRange\": \"0\",\"publish_protocol\": \"http\"},"
+ + "{\"ip\": \"10.74.165.246\",\"port\": \"80\",\"publish_url\": \"/api/wudith/v1\",\"visualRange\": \"0\",\"publish_protocol\": \"http\"}]";
+ List<PublishFullAddress> publishFullAddressList = JacksonJsonUtil.jsonToListBean(resultJson,
+ new TypeReference<List<PublishFullAddress>>() {});
+ Assert.assertEquals(2, publishFullAddressList.size());
+ Assert.assertEquals("80", publishFullAddressList.get(0).getPort());
+ } catch (Exception e) {
+ Assert.fail("Exception" + e.getMessage());
+ }
}
-
+
@Test
- public void testJsonToListBean_Fail(){
- try{
- String resultJson="[\"domain\": \"wudith.openpalette.zte.com.cn\",\"port\": \"80\",\"publish_url\": \"/api/wudith/v1\",\"visualRange\": \"0\",\"publish_protocol\": \"http\"},"
- + "{\"ip\": \"10.74.165.246\",\"port\": \"80\",\"publish_url\": \"/api/wudith/v1\",\"visualRange\": \"0\",\"publish_protocol\": \"http\"}]";
- List<PublishFullAddress> publishFullAddressList =
- JacksonJsonUtil.jsonToListBean(resultJson, new TypeReference<List<PublishFullAddress>>() {});
- }
- catch(Exception e){
- Assert.assertTrue(e instanceof Exception);
- }
+ public void testJsonToListBean_Fail() {
+ try {
+ String resultJson =
+ "[\"domain\": \"wudith.openpalette.zte.com.cn\",\"port\": \"80\",\"publish_url\": \"/api/wudith/v1\",\"visualRange\": \"0\",\"publish_protocol\": \"http\"},"
+ + "{\"ip\": \"10.74.165.246\",\"port\": \"80\",\"publish_url\": \"/api/wudith/v1\",\"visualRange\": \"0\",\"publish_protocol\": \"http\"}]";
+ List<PublishFullAddress> publishFullAddressList = JacksonJsonUtil.jsonToListBean(resultJson,
+ new TypeReference<List<PublishFullAddress>>() {});
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof Exception);
+ }
}
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/JedisUtilTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/JedisUtilTest.java
index 91fbe32..0004aad 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/JedisUtilTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/JedisUtilTest.java
@@ -1,35 +1,32 @@
/*******************************************************************************
* Copyright 2016-2017 ZTE, Inc. and others.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
******************************************************************************/
package org.onap.msb.apiroute.wrapper.util;
import org.junit.Assert;
import org.junit.Test;
-import org.onap.msb.apiroute.wrapper.util.JedisUtil;
import redis.clients.jedis.exceptions.JedisConnectionException;
public class JedisUtilTest {
- @Test
- public void test_initialPool() {
- try {
- JedisUtil.borrowJedisInstance();
-
- } catch (Exception e) {
- Assert.assertTrue(e instanceof JedisConnectionException);
-
+ @Test
+ public void test_initialPool() {
+ try {
+ JedisUtil.borrowJedisInstance();
+
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof JedisConnectionException);
+
+ }
}
- }
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/MicroServiceUtilTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/MicroServiceUtilTest.java
index bede4ff..2b622a4 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/MicroServiceUtilTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/MicroServiceUtilTest.java
@@ -1,17 +1,15 @@
/*******************************************************************************
* Copyright 2016-2017 ZTE, Inc. and others.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
******************************************************************************/
package org.onap.msb.apiroute.wrapper.util;
@@ -20,41 +18,38 @@ import javax.servlet.http.HttpServletRequest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.onap.msb.apiroute.wrapper.util.MicroServiceUtil;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import redis.clients.jedis.Jedis;
-
@RunWith(PowerMockRunner.class)
@PrepareForTest({HttpServletRequest.class})
public class MicroServiceUtilTest {
- @Test
- public void test_getPrefixedKey(){
- Assert.assertEquals("discover:microservices:test:v1",MicroServiceUtil.getPrefixedKey("test","v1"));
- }
-
- @Test
- public void test_getServiceKey(){
- Assert.assertEquals("discover:microservices:test:v1",MicroServiceUtil.getServiceKey("test","v1"));
- }
-
- @Test
- public void test_getRealIp(){
- HttpServletRequest request=PowerMockito.mock(HttpServletRequest.class);
- PowerMockito.when(request.getHeader("X-Forwarded-For")).thenReturn("127.0.0.1");
- Assert.assertEquals("127.0.0.1",MicroServiceUtil.getRealIp(request));
-
- PowerMockito.when(request.getHeader("X-Forwarded-For")).thenReturn("");
- PowerMockito.when(request.getHeader("X-Real-IP")).thenReturn("127.0.0.2");
- Assert.assertEquals("127.0.0.2",MicroServiceUtil.getRealIp(request));
-
- PowerMockito.when(request.getHeader("X-Forwarded-For")).thenReturn("");
- PowerMockito.when(request.getHeader("X-Real-IP")).thenReturn("");
- PowerMockito.when(request.getRemoteAddr()).thenReturn("127.0.0.3");
- Assert.assertEquals("127.0.0.3",MicroServiceUtil.getRealIp(request));
-
- }
+ @Test
+ public void test_getPrefixedKey() {
+ Assert.assertEquals("discover:microservices:test:v1", MicroServiceUtil.getPrefixedKey("test", "v1"));
+ }
+
+ @Test
+ public void test_getServiceKey() {
+ Assert.assertEquals("discover:microservices:test:v1", MicroServiceUtil.getServiceKey("test", "v1"));
+ }
+
+ @Test
+ public void test_getRealIp() {
+ HttpServletRequest request = PowerMockito.mock(HttpServletRequest.class);
+ PowerMockito.when(request.getHeader("X-Forwarded-For")).thenReturn("127.0.0.1");
+ Assert.assertEquals("127.0.0.1", MicroServiceUtil.getRealIp(request));
+
+ PowerMockito.when(request.getHeader("X-Forwarded-For")).thenReturn("");
+ PowerMockito.when(request.getHeader("X-Real-IP")).thenReturn("127.0.0.2");
+ Assert.assertEquals("127.0.0.2", MicroServiceUtil.getRealIp(request));
+
+ PowerMockito.when(request.getHeader("X-Forwarded-For")).thenReturn("");
+ PowerMockito.when(request.getHeader("X-Real-IP")).thenReturn("");
+ PowerMockito.when(request.getRemoteAddr()).thenReturn("127.0.0.3");
+ Assert.assertEquals("127.0.0.3", MicroServiceUtil.getRealIp(request));
+
+ }
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/RegExpTestUtilTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/RegExpTestUtilTest.java
index 2d5c5c5..76a0c7d 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/RegExpTestUtilTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/RegExpTestUtilTest.java
@@ -1,96 +1,94 @@
/*******************************************************************************
* Copyright 2016-2017 ZTE, Inc. and others.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
******************************************************************************/
package org.onap.msb.apiroute.wrapper.util;
import org.junit.Assert;
import org.junit.Test;
-import org.onap.msb.apiroute.wrapper.util.RegExpTestUtil;
public class RegExpTestUtilTest {
@Test
- public void test_HostRegExpTest(){
+ public void test_HostRegExpTest() {
Assert.assertTrue(RegExpTestUtil.hostRegExpTest("127.0.0.1:8080"));
Assert.assertFalse(RegExpTestUtil.hostRegExpTest("0.0.0.1:89"));
}
-
-
-
+
+
+
@Test
- public void test_IpRegExpTest(){
+ public void test_IpRegExpTest() {
Assert.assertTrue(RegExpTestUtil.ipRegExpTest("127.0.0.1"));
Assert.assertFalse(RegExpTestUtil.ipRegExpTest("127.0.0.1.5"));
}
-
-
-
+
+
+
@Test
- public void test_PortRegExpTest(){
- Assert.assertTrue(RegExpTestUtil.portRegExpTest("80"));
+ public void test_PortRegExpTest() {
+ Assert.assertTrue(RegExpTestUtil.portRegExpTest("80"));
Assert.assertFalse(RegExpTestUtil.portRegExpTest("898989"));
}
-
-
+
+
@Test
- public void test_VersionRegExpTest(){
+ public void test_VersionRegExpTest() {
Assert.assertTrue(RegExpTestUtil.versionRegExpTest("v1"));
Assert.assertFalse(RegExpTestUtil.versionRegExpTest("23"));
}
-
-
-
+
+
+
@Test
- public void test_urlRegExpTest(){
+ public void test_urlRegExpTest() {
Assert.assertTrue(RegExpTestUtil.urlRegExpTest("/test"));
Assert.assertTrue(RegExpTestUtil.urlRegExpTest("/"));
Assert.assertFalse(RegExpTestUtil.urlRegExpTest("test"));
}
-
-
+
+
@Test
- public void test_apiRouteUrlRegExpTest(){
+ public void test_apiRouteUrlRegExpTest() {
Assert.assertTrue(RegExpTestUtil.apiRouteUrlRegExpTest("/api/test/v1"));
Assert.assertFalse(RegExpTestUtil.apiRouteUrlRegExpTest("/test"));
}
-
-
-
+
+
+
@Test
- public void test_iuiRouteUrlRegExpTest(){
+ public void test_iuiRouteUrlRegExpTest() {
Assert.assertTrue(RegExpTestUtil.iuiRouteUrlRegExpTest("/iui/test"));
Assert.assertFalse(RegExpTestUtil.iuiRouteUrlRegExpTest("/test"));
- }
-
+ }
+
@Test
- public void test_apiServiceNameMatch4URL(){
- String[] apiServiceNameArray={"testApiName","v1"};
- Assert.assertArrayEquals(apiServiceNameArray, RegExpTestUtil.apiServiceNameMatch4URL("/api/testApiName/v1"));
-
- String[] apiServiceNameArray_noversion={"testApiName",""};
- Assert.assertArrayEquals(apiServiceNameArray_noversion, RegExpTestUtil.apiServiceNameMatch4URL("/api/testApiName"));
-
- Assert.assertNull(RegExpTestUtil.apiServiceNameMatch4URL("/apiw/name/v1"));
+ public void test_apiServiceNameMatch4URL() {
+ String[] apiServiceNameArray = {"testApiName", "v1"};
+ Assert.assertArrayEquals(apiServiceNameArray, RegExpTestUtil.apiServiceNameMatch4URL("/api/testApiName/v1"));
+
+ String[] apiServiceNameArray_noversion = {"testApiName", ""};
+ Assert.assertArrayEquals(apiServiceNameArray_noversion,
+ RegExpTestUtil.apiServiceNameMatch4URL("/api/testApiName"));
+
+ Assert.assertNull(RegExpTestUtil.apiServiceNameMatch4URL("/apiw/name/v1"));
}
-
+
@Test
- public void test_iuiServiceNameMatch4URL(){
- String iuiServiceName="testIuiName";
- Assert.assertEquals(iuiServiceName, RegExpTestUtil.iuiServiceNameMatch4URL("/iui/testIuiName"));
-
- Assert.assertNull(RegExpTestUtil.iuiServiceNameMatch4URL("/api/name/v1"));
+ public void test_iuiServiceNameMatch4URL() {
+ String iuiServiceName = "testIuiName";
+ Assert.assertEquals(iuiServiceName, RegExpTestUtil.iuiServiceNameMatch4URL("/iui/testIuiName"));
+
+ Assert.assertNull(RegExpTestUtil.iuiServiceNameMatch4URL("/api/name/v1"));
}
-
+
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/RouteUtilTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/RouteUtilTest.java
index 08fcf6c..02fa9f3 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/RouteUtilTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/RouteUtilTest.java
@@ -1,17 +1,15 @@
/*******************************************************************************
* Copyright 2016-2017 ZTE, Inc. and others.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
******************************************************************************/
package org.onap.msb.apiroute.wrapper.util;
@@ -34,340 +32,344 @@ import org.powermock.modules.junit4.PowerMockRunner;
@PrepareForTest({ConfigUtil.class})
public class RouteUtilTest {
- @Test
- public void test_getPrefixedKey() {
- Assert.assertEquals("msb:routing:test:v1", RouteUtil.getPrefixedKey("", "test", "v1"));
- Assert.assertEquals("msb:5656:test:v1", RouteUtil.getPrefixedKey("5656", "test", "v1"));
+ @Test
+ public void test_getPrefixedKey() {
+ Assert.assertEquals("msb:routing:test:v1", RouteUtil.getPrefixedKey("", "test", "v1"));
+ Assert.assertEquals("msb:5656:test:v1", RouteUtil.getPrefixedKey("5656", "test", "v1"));
- }
+ }
+
+ @Test
+ public void test_getPrefixedKey4Host() {
+ Assert.assertEquals("msb:host:test:v1", RouteUtil.getPrefixedKey4Host("test", "v1"));
- @Test
- public void test_getPrefixedKey4Host() {
- Assert.assertEquals("msb:host:test:v1", RouteUtil.getPrefixedKey4Host("test", "v1"));
+ }
- }
+ @Test
+ public void test_checkRouteWay() {
+ try {
+ RouteUtil.checkRouteWay("ipp");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
- @Test
- public void test_checkRouteWay() {
- try {
- RouteUtil.checkRouteWay("ipp");
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
}
- }
+ @Test
+ public void test_checkServiceNameAndVersion() {
+ try {
+ RouteUtil.checkServiceNameAndVersion("", "v1");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
- @Test
- public void test_checkServiceNameAndVersion() {
- try {
- RouteUtil.checkServiceNameAndVersion("","v1");
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+ try {
+ RouteUtil.checkServiceNameAndVersion("test", "ve1");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
}
-
- try {
- RouteUtil.checkServiceNameAndVersion("test","ve1");
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_checkServiceStatus() {
+ try {
+ RouteUtil.checkServiceStatus("2");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
}
- }
-
- @Test
- public void test_checkServiceStatus() {
- try {
- RouteUtil.checkServiceStatus("2");
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_checkRouterInfoFormat() {
+ RouteInfo routeInfo = new RouteInfo();
+
+ try {
+ RouteUtil.checkRouterInfoFormat(routeInfo);
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
}
- }
-
- @Test
- public void test_checkRouterInfoFormat() {
- RouteInfo routeInfo=new RouteInfo();
-
- try {
- RouteUtil.checkRouterInfoFormat(routeInfo);
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_checkMicroServiceInfoFormat() {
+ MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
+
+ try {
+ RouteUtil.checkMicroServiceInfoFormat(microServiceInfo, "");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
+ }
+
+ @Test
+ public void test_checkMicroServiceInfoFormat_ip() {
+ MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
+ microServiceInfo.setServiceName("name");
+ microServiceInfo.setProtocol("REST");
+ Set<Node> nodeSet = new HashSet<>();
+ nodeSet.add(new Node("10.74.148.88.22", "8080"));
+ microServiceInfo.setNodes(nodeSet);
+
+ try {
+ RouteUtil.checkMicroServiceInfoFormat(microServiceInfo, "");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
}
- }
-
- @Test
- public void test_checkMicroServiceInfoFormat() {
- MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
-
- try {
- RouteUtil.checkMicroServiceInfoFormat(microServiceInfo,"");
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_checkMicroServiceInfoFormat_port() {
+ MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
+ microServiceInfo.setServiceName("name");
+ microServiceInfo.setProtocol("REST");
+ Set<Node> nodeSet = new HashSet<>();
+ nodeSet.add(new Node("10.74.148.88.22", "808770"));
+ microServiceInfo.setNodes(nodeSet);
+
+ try {
+ RouteUtil.checkMicroServiceInfoFormat(microServiceInfo, "");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
}
- }
-
- @Test
- public void test_checkMicroServiceInfoFormat_ip() {
- MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
- microServiceInfo.setServiceName("name");
- microServiceInfo.setProtocol("REST");
- Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("10.74.148.88.22","8080"));
- microServiceInfo.setNodes(nodeSet);
-
- try {
- RouteUtil.checkMicroServiceInfoFormat(microServiceInfo,"");
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_checkMicroServiceInfoFormat_version() {
+ MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
+ microServiceInfo.setServiceName("name");
+ microServiceInfo.setProtocol("REST");
+ Set<Node> nodeSet = new HashSet<>();
+ nodeSet.add(new Node("", "8089"));
+ microServiceInfo.setNodes(nodeSet);
+ microServiceInfo.setVersion("cv2");
+
+ try {
+ RouteUtil.checkMicroServiceInfoFormat(microServiceInfo, "10.74.55.36");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
+ }
+
+ @Test
+ public void test_checkMicroServiceInfoFormat_url() {
+ MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
+ microServiceInfo.setServiceName("name");
+ microServiceInfo.setProtocol("REST");
+ Set<Node> nodeSet = new HashSet<>();
+ nodeSet.add(new Node("", "8089"));
+ microServiceInfo.setNodes(nodeSet);
+ microServiceInfo.setVersion("v2");
+ microServiceInfo.setUrl("url");
+
+ try {
+ RouteUtil.checkMicroServiceInfoFormat(microServiceInfo, "10.74.55.36");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
+ }
+
+ @Test
+ public void test_checkMicroServiceInfoFormat_protocol() {
+ MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
+ microServiceInfo.setServiceName("name");
+ microServiceInfo.setProtocol("REST2");
+ Set<Node> nodeSet = new HashSet<>();
+ nodeSet.add(new Node("", "8089"));
+ microServiceInfo.setNodes(nodeSet);
+ microServiceInfo.setVersion("v2");
+ microServiceInfo.setUrl("/url");
+
+ try {
+ RouteUtil.checkMicroServiceInfoFormat(microServiceInfo, "10.74.55.36");
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
+ }
+
+ @Test
+ public void test_getAPIRedisPrefixedKey() {
+ Assert.assertEquals("msb:20081:api:testApi:v1",
+ RouteUtil.getAPIRedisPrefixedKey("testApi", "v1", "testHost", "20081", "ip"));
+ Assert.assertEquals("msb:routing:api:testApi:v1",
+ RouteUtil.getAPIRedisPrefixedKey("testApi", "v1", "testHost", "", "ip"));
+ Assert.assertEquals("msb:host:testHost:api:testApi:v1",
+ RouteUtil.getAPIRedisPrefixedKey("testApi", "v1", "testHost", "20081", "domain"));
+ }
+
+ @Test
+ public void test_getRedisPrefixedKey() {
+ Assert.assertEquals("msb:20081:custom:/testName/v1", RouteUtil.getRedisPrefixedKey(RouteUtil.CUSTOMROUTE,
+ "/testName/v1", "testHost", "20081", "ip"));
+ Assert.assertEquals("msb:routing:custom:/testName/v1",
+ RouteUtil.getRedisPrefixedKey(RouteUtil.CUSTOMROUTE, "/testName/v1", "testHost", "", "ip"));
+ Assert.assertEquals("msb:host:testHost:custom:/testName/v1", RouteUtil
+ .getRedisPrefixedKey(RouteUtil.CUSTOMROUTE, "/testName/v1", "testHost", "20081", "domain"));
+
+ Assert.assertEquals("msb:20081:iui:testName",
+ RouteUtil.getRedisPrefixedKey(RouteUtil.IUIROUTE, "testName", "testHost", "20081", "ip"));
+ Assert.assertEquals("msb:routing:iui:testName",
+ RouteUtil.getRedisPrefixedKey(RouteUtil.IUIROUTE, "testName", "testHost", "", "ip"));
+ Assert.assertEquals("msb:host:testHost:iui:testName",
+ RouteUtil.getRedisPrefixedKey(RouteUtil.IUIROUTE, "testName", "testHost", "20081", "domain"));
}
- }
-
- @Test
- public void test_checkMicroServiceInfoFormat_port() {
- MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
- microServiceInfo.setServiceName("name");
- microServiceInfo.setProtocol("REST");
- Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("10.74.148.88.22","808770"));
- microServiceInfo.setNodes(nodeSet);
-
- try {
- RouteUtil.checkMicroServiceInfoFormat(microServiceInfo,"");
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_getMutiRedisKey() {
+ Assert.assertEquals("msb:[^h]*:api:*", RouteUtil.getMutiRedisKey(RouteUtil.APIROUTE, "ip"));
+ Assert.assertEquals("msb:[^h]*:iui:*", RouteUtil.getMutiRedisKey(RouteUtil.IUIROUTE, "ip"));
+ Assert.assertEquals("msb:[^h]*:custom:*", RouteUtil.getMutiRedisKey(RouteUtil.CUSTOMROUTE, "ip"));
+
+ Assert.assertEquals("msb:host:*:api:*", RouteUtil.getMutiRedisKey(RouteUtil.APIROUTE, "domain"));
+ Assert.assertEquals("msb:host:*:iui:*", RouteUtil.getMutiRedisKey(RouteUtil.IUIROUTE, "domain"));
+ Assert.assertEquals("msb:host:*:custom:*", RouteUtil.getMutiRedisKey(RouteUtil.CUSTOMROUTE, "domain"));
}
- }
-
- @Test
- public void test_checkMicroServiceInfoFormat_version() {
- MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
- microServiceInfo.setServiceName("name");
- microServiceInfo.setProtocol("REST");
- Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("","8089"));
- microServiceInfo.setNodes(nodeSet);
- microServiceInfo.setVersion("cv2");
-
- try {
- RouteUtil.checkMicroServiceInfoFormat(microServiceInfo,"10.74.55.36");
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_getRouteNameByns() {
+ Assert.assertEquals("serviceName", RouteUtil.getRouteNameByns("serviceName", ""));
+ Assert.assertEquals("serviceName", RouteUtil.getRouteNameByns("serviceName-ns", "ns"));
+ Assert.assertEquals("serviceName-ns", RouteUtil.getRouteNameByns("serviceName-ns-ns", "ns"));
+ Assert.assertEquals("serviceName", RouteUtil.getRouteNameByns("serviceName", "default"));
}
- }
-
- @Test
- public void test_checkMicroServiceInfoFormat_url() {
- MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
- microServiceInfo.setServiceName("name");
- microServiceInfo.setProtocol("REST");
- Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("","8089"));
- microServiceInfo.setNodes(nodeSet);
- microServiceInfo.setVersion("v2");
- microServiceInfo.setUrl("url");
-
- try {
- RouteUtil.checkMicroServiceInfoFormat(microServiceInfo,"10.74.55.36");
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_getVisualRangeByRouter() {
+ Assert.assertEquals("0", RouteUtil.getVisualRangeByRouter("0|1"));
+ Assert.assertEquals("1", RouteUtil.getVisualRangeByRouter("1"));
+ Assert.assertEquals("0", RouteUtil.getVisualRangeByRouter("0"));
+
+
}
- }
-
- @Test
- public void test_checkMicroServiceInfoFormat_protocol() {
- MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
- microServiceInfo.setServiceName("name");
- microServiceInfo.setProtocol("REST2");
- Set<Node> nodeSet = new HashSet<>();
- nodeSet.add(new Node("","8089"));
- microServiceInfo.setNodes(nodeSet);
- microServiceInfo.setVersion("v2");
- microServiceInfo.setUrl("/url");
-
- try {
- RouteUtil.checkMicroServiceInfoFormat(microServiceInfo,"10.74.55.36");
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_getVisualRangeByRouter_muti() {
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn("lab1:val,visualRange:0|1");
+ ConfigUtil.getInstance().initRouteLabelsMatches();
+ Assert.assertEquals("0", RouteUtil.getVisualRangeByRouter("0|1"));
}
- }
-
- @Test
- public void test_getAPIRedisPrefixedKey() {
- Assert.assertEquals("msb:20081:api:testApi:v1", RouteUtil.getAPIRedisPrefixedKey("testApi", "v1", "testHost","20081","ip"));
- Assert.assertEquals("msb:routing:api:testApi:v1", RouteUtil.getAPIRedisPrefixedKey("testApi", "v1", "testHost","","ip"));
- Assert.assertEquals("msb:host:testHost:api:testApi:v1", RouteUtil.getAPIRedisPrefixedKey("testApi", "v1", "testHost","20081","domain"));
- }
-
- @Test
- public void test_getRedisPrefixedKey() {
- Assert.assertEquals("msb:20081:custom:/testName/v1", RouteUtil.getRedisPrefixedKey(RouteUtil.CUSTOMROUTE,"/testName/v1", "testHost","20081","ip"));
- Assert.assertEquals("msb:routing:custom:/testName/v1", RouteUtil.getRedisPrefixedKey(RouteUtil.CUSTOMROUTE,"/testName/v1", "testHost","","ip"));
- Assert.assertEquals("msb:host:testHost:custom:/testName/v1", RouteUtil.getRedisPrefixedKey(RouteUtil.CUSTOMROUTE,"/testName/v1", "testHost","20081","domain"));
-
- Assert.assertEquals("msb:20081:iui:testName", RouteUtil.getRedisPrefixedKey(RouteUtil.IUIROUTE,"testName", "testHost","20081","ip"));
- Assert.assertEquals("msb:routing:iui:testName", RouteUtil.getRedisPrefixedKey(RouteUtil.IUIROUTE,"testName", "testHost","","ip"));
- Assert.assertEquals("msb:host:testHost:iui:testName", RouteUtil.getRedisPrefixedKey(RouteUtil.IUIROUTE,"testName", "testHost","20081","domain"));
- }
-
- @Test
- public void test_getMutiRedisKey() {
- Assert.assertEquals("msb:[^h]*:api:*", RouteUtil.getMutiRedisKey(RouteUtil.APIROUTE,"ip"));
- Assert.assertEquals("msb:[^h]*:iui:*", RouteUtil.getMutiRedisKey(RouteUtil.IUIROUTE,"ip"));
- Assert.assertEquals("msb:[^h]*:custom:*", RouteUtil.getMutiRedisKey(RouteUtil.CUSTOMROUTE,"ip"));
-
- Assert.assertEquals("msb:host:*:api:*", RouteUtil.getMutiRedisKey(RouteUtil.APIROUTE,"domain"));
- Assert.assertEquals("msb:host:*:iui:*", RouteUtil.getMutiRedisKey(RouteUtil.IUIROUTE,"domain"));
- Assert.assertEquals("msb:host:*:custom:*", RouteUtil.getMutiRedisKey(RouteUtil.CUSTOMROUTE,"domain"));
- }
-
- @Test
- public void test_getRouteNameByns() {
- Assert.assertEquals("serviceName", RouteUtil.getRouteNameByns("serviceName",""));
- Assert.assertEquals("serviceName", RouteUtil.getRouteNameByns("serviceName-ns","ns"));
- Assert.assertEquals("serviceName-ns", RouteUtil.getRouteNameByns("serviceName-ns-ns","ns"));
- Assert.assertEquals("serviceName", RouteUtil.getRouteNameByns("serviceName","default"));
- }
-
- @Test
- public void test_getVisualRangeByRouter(){
- Assert.assertEquals("0", RouteUtil.getVisualRangeByRouter("0|1"));
- Assert.assertEquals("1", RouteUtil.getVisualRangeByRouter("1"));
- Assert.assertEquals("0", RouteUtil.getVisualRangeByRouter("0"));
-
-
- }
-
- @Test
- public void test_getVisualRangeByRouter_muti(){
- PowerMockito.mockStatic(System.class);
- PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn("lab1:val,visualRange:0|1");
- ConfigUtil.getInstance().initRouteLabelsMatches();
- Assert.assertEquals("0", RouteUtil.getVisualRangeByRouter("0|1"));
- }
-
- @Test
- public void test_checkRouterInfoFormat_url() {
- RouteInfo routeInfo=new RouteInfo();
- routeInfo.setServiceName("name");
- routeInfo.setUrl("url");
- routeInfo.setServers( new RouteServer[]{new RouteServer("10.74.148.88","8080")});
-
- try {
- RouteUtil.checkRouterInfoFormat(routeInfo);
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_checkRouterInfoFormat_url() {
+ RouteInfo routeInfo = new RouteInfo();
+ routeInfo.setServiceName("name");
+ routeInfo.setUrl("url");
+ routeInfo.setServers(new RouteServer[] {new RouteServer("10.74.148.88", "8080")});
+
+ try {
+ RouteUtil.checkRouterInfoFormat(routeInfo);
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
}
- }
-
- @Test
- public void test_checkRouterInfoFormat_visualRangeRange() {
- RouteInfo routeInfo=new RouteInfo();
- routeInfo.setServiceName("name");
- routeInfo.setUrl("/url");
- routeInfo.setServers( new RouteServer[]{new RouteServer("10.74.148.88","8080")});
- routeInfo.setVisualRange("2");
-
- try {
- RouteUtil.checkRouterInfoFormat(routeInfo);
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_checkRouterInfoFormat_visualRangeRange() {
+ RouteInfo routeInfo = new RouteInfo();
+ routeInfo.setServiceName("name");
+ routeInfo.setUrl("/url");
+ routeInfo.setServers(new RouteServer[] {new RouteServer("10.74.148.88", "8080")});
+ routeInfo.setVisualRange("2");
+
+ try {
+ RouteUtil.checkRouterInfoFormat(routeInfo);
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
}
- }
-
-
- @Test
- public void test_checkRouterInfoFormat_controlRangeMatches() {
- RouteInfo routeInfo=new RouteInfo();
- routeInfo.setServiceName("name");
- routeInfo.setUrl("/url");
- routeInfo.setServers( new RouteServer[]{new RouteServer("10.74.148.88","8080")});
- routeInfo.setVisualRange("0");
- routeInfo.setControl("3");
-
- try {
- RouteUtil.checkRouterInfoFormat(routeInfo);
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+
+ @Test
+ public void test_checkRouterInfoFormat_controlRangeMatches() {
+ RouteInfo routeInfo = new RouteInfo();
+ routeInfo.setServiceName("name");
+ routeInfo.setUrl("/url");
+ routeInfo.setServers(new RouteServer[] {new RouteServer("10.74.148.88", "8080")});
+ routeInfo.setVisualRange("0");
+ routeInfo.setControl("3");
+
+ try {
+ RouteUtil.checkRouterInfoFormat(routeInfo);
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
}
- }
-
- @Test
- public void test_checkRouterInfoFormat_statusRangeMatches() {
- RouteInfo routeInfo=new RouteInfo();
- routeInfo.setServiceName("name");
- routeInfo.setUrl("/url");
- routeInfo.setServers( new RouteServer[]{new RouteServer("10.74.148.88","8080")});
- routeInfo.setVisualRange("0");
- routeInfo.setControl("0");
- routeInfo.setStatus("3");
-
- try {
- RouteUtil.checkRouterInfoFormat(routeInfo);
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_checkRouterInfoFormat_statusRangeMatches() {
+ RouteInfo routeInfo = new RouteInfo();
+ routeInfo.setServiceName("name");
+ routeInfo.setUrl("/url");
+ routeInfo.setServers(new RouteServer[] {new RouteServer("10.74.148.88", "8080")});
+ routeInfo.setVisualRange("0");
+ routeInfo.setControl("0");
+ routeInfo.setStatus("3");
+
+ try {
+ RouteUtil.checkRouterInfoFormat(routeInfo);
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
}
- }
-
-
- @Test
- public void test_checkRouterInfoFormat_useOwnUpstreamRangeMatches() {
- RouteInfo routeInfo=new RouteInfo();
- routeInfo.setServiceName("name");
- routeInfo.setUrl("/url");
- routeInfo.setServers( new RouteServer[]{new RouteServer("10.74.148.88","8080")});
- routeInfo.setVisualRange("0");
- routeInfo.setControl("0");
- routeInfo.setStatus("0");
- routeInfo.setUseOwnUpstream("3");
-
- try {
- RouteUtil.checkRouterInfoFormat(routeInfo);
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+
+ @Test
+ public void test_checkRouterInfoFormat_useOwnUpstreamRangeMatches() {
+ RouteInfo routeInfo = new RouteInfo();
+ routeInfo.setServiceName("name");
+ routeInfo.setUrl("/url");
+ routeInfo.setServers(new RouteServer[] {new RouteServer("10.74.148.88", "8080")});
+ routeInfo.setVisualRange("0");
+ routeInfo.setControl("0");
+ routeInfo.setStatus("0");
+ routeInfo.setUseOwnUpstream("3");
+
+ try {
+ RouteUtil.checkRouterInfoFormat(routeInfo);
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
}
- }
-
- @Test
- public void test_checkRouterInfoFormat_ip() {
- RouteInfo routeInfo=new RouteInfo();
- routeInfo.setServiceName("name");
- routeInfo.setUrl("/url");
- routeInfo.setServers( new RouteServer[]{new RouteServer("10.74.148.88.6","8080")});
- routeInfo.setVisualRange("0");
- routeInfo.setControl("0");
- routeInfo.setStatus("0");
- routeInfo.setUseOwnUpstream("1");
-
- try {
- RouteUtil.checkRouterInfoFormat(routeInfo);
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+ @Test
+ public void test_checkRouterInfoFormat_ip() {
+ RouteInfo routeInfo = new RouteInfo();
+ routeInfo.setServiceName("name");
+ routeInfo.setUrl("/url");
+ routeInfo.setServers(new RouteServer[] {new RouteServer("10.74.148.88.6", "8080")});
+ routeInfo.setVisualRange("0");
+ routeInfo.setControl("0");
+ routeInfo.setStatus("0");
+ routeInfo.setUseOwnUpstream("1");
+
+ try {
+ RouteUtil.checkRouterInfoFormat(routeInfo);
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
}
- }
-
-
- @Test
- public void test_checkRouterInfoFormat_port() {
- RouteInfo routeInfo=new RouteInfo();
- routeInfo.setServiceName("name");
- routeInfo.setUrl("/url");
- routeInfo.setServers( new RouteServer[]{new RouteServer("10.74.148.88.6","757577")});
- routeInfo.setVisualRange("0");
- routeInfo.setControl("0");
- routeInfo.setStatus("0");
- routeInfo.setUseOwnUpstream("1");
-
- try {
- RouteUtil.checkRouterInfoFormat(routeInfo);
- } catch (Exception e) {
- Assert.assertTrue(e instanceof UnprocessableEntityException);
+
+
+ @Test
+ public void test_checkRouterInfoFormat_port() {
+ RouteInfo routeInfo = new RouteInfo();
+ routeInfo.setServiceName("name");
+ routeInfo.setUrl("/url");
+ routeInfo.setServers(new RouteServer[] {new RouteServer("10.74.148.88.6", "757577")});
+ routeInfo.setVisualRange("0");
+ routeInfo.setControl("0");
+ routeInfo.setStatus("0");
+ routeInfo.setUseOwnUpstream("1");
+
+ try {
+ RouteUtil.checkRouterInfoFormat(routeInfo);
+ } catch (Exception e) {
+ Assert.assertTrue(e instanceof UnprocessableEntityException);
+ }
}
- }
-
-
-
-
-
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/ServiceFilterTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/ServiceFilterTest.java
index 9c9d4b1..5759014 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/ServiceFilterTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/util/ServiceFilterTest.java
@@ -1,17 +1,15 @@
/*******************************************************************************
* Copyright 2016-2017 ZTE, Inc. and others.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
******************************************************************************/
package org.onap.msb.apiroute.wrapper.util;
@@ -45,180 +43,173 @@ public class ServiceFilterTest {
- @Test
- public void test_isNeedNotifyByNameSpace() {
-
- PowerMockito.mockStatic(System.class);
-
- PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("all");
- ConfigUtil.getInstance().initRouteNameSpaceMatches();
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace("test")); // namespaceMatches:all
-
- PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("default");
- ConfigUtil.getInstance().initRouteNameSpaceMatches();
- Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNameSpace("test"));// namespaceMatches:default
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace(""));// namespaceMatches:default
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace("default"));// namespaceMatches:default
-
-
- PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("!default");
- ConfigUtil.getInstance().initRouteNameSpaceMatches();
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace("test"));// namespaceMatches:!default
- Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNameSpace(""));// namespaceMatches:!default
-
- PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("ns|ns2");
- ConfigUtil.getInstance().initRouteNameSpaceMatches();
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace("ns"));
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace("ns2"));
- Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNameSpace("ns3"));
- Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNameSpace(""));
-
-
- PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("!ns&!ns2");
- ConfigUtil.getInstance().initRouteNameSpaceMatches();
- Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNameSpace("ns"));
- Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNameSpace("ns2"));
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace("ns3"));
-
- }
-
- /*
- * @Test public void test_isNeedNotifyByVisualRange(){
- *
- * Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByVisualRange("0"));
- * Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByVisualRange("1"));
- * Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByVisualRange("0|1")); }
- */
-
- @Test
- public void test_isNeedNotifyByProtocol() {
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByProtocol("HTTP"));
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByProtocol("UI"));
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByProtocol("REST"));
- Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByProtocol("TCP"));
- }
-
- @Test
- public void test_isNeedNotifyByNetwork_plane_typeMatches() {
-
- PowerMockito.mockStatic(System.class);
- PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn("network_plane_type:network");
- ConfigUtil.getInstance().initRouteLabelsMatches();
- Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNetwork_plane_typeMatches("net"));
- Assert.assertTrue(ServiceFilter.getInstance()
- .isNeedNotifyByNetwork_plane_typeMatches("network"));
-
- PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn("network_plane_type:net1|net2");
- ConfigUtil.getInstance().initRouteLabelsMatches();
- Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNetwork_plane_typeMatches("net"));
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNetwork_plane_typeMatches("net1"));
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNetwork_plane_typeMatches("net2"));
-
- }
-
- @Test
- public void test_isNeedNotifyByRouteLabels() {
- Map<String, String> labelMap = new HashMap<String, String>();
- labelMap.put("lab1", "val1");
-
- PowerMockito.mockStatic(System.class);
- PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn("lab1:val,visualRange:1");
- ConfigUtil.getInstance().initRouteLabelsMatches();
- Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByRouteLabels(labelMap));
-
- PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn("lab1:val1");
- ConfigUtil.getInstance().initRouteLabelsMatches();
- Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByRouteLabels(labelMap));
-
- }
-
- @Test
- public void test_isFilterService() {
- PowerMockito.mockStatic(System.class);
- PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("ns1");
- ConfigUtil.getInstance().initRouteNameSpaceMatches();
-
- PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn(
- "visualRange:0,network_plane_type:net,customLabel:custom|custom2");
- ConfigUtil.getInstance().initRouteLabelsMatches();
-
- List<String> tagList = new ArrayList<String>();
- tagList.add("\"base\":{\"protocol\":\"REST\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
- tagList
- .add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}");
- tagList.add("\"ns\":{\"namespace\":\"ns1\"}");
- Assert.assertTrue(ServiceFilter.getInstance().isFilterService(tagList));
-
- tagList.clear();
- tagList.add("\"base\":{\"protocol\":\"TCP\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
- Assert.assertFalse(ServiceFilter.getInstance().isFilterService(tagList));
-
- tagList.clear();
- tagList.add("\"base\":{\"protocol\":\"UI\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
- tagList.add("\"ns\":{\"namespace\":\"ns2\"}");
- Assert.assertFalse(ServiceFilter.getInstance().isFilterService(tagList));
-
- tagList.clear();
- tagList.add("\"base\":{\"protocol\":\"UI\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
- tagList.add("\"ns\":{\"namespace\":\"ns1\"}");
- tagList
- .add("\"labels\":{\"visualRange\":\"1\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}");
- Assert.assertFalse(ServiceFilter.getInstance().isFilterService(tagList));
-
- tagList.clear();
- tagList.add("\"base\":{\"protocol\":\"UI\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
- tagList.add("\"ns\":{\"namespace\":\"ns1\"}");
- tagList
- .add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net2\",\"customLabel\":\"custom\"}");
- Assert.assertFalse(ServiceFilter.getInstance().isFilterService(tagList));
-
- tagList.clear();
- tagList.add("\"base\":{\"protocol\":\"UI\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
- tagList.add("\"ns\":{\"namespace\":\"ns1\"}");
- tagList
- .add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom3\"}");
- Assert.assertFalse(ServiceFilter.getInstance().isFilterService(tagList));
-
- }
-
- @Test
- public void test_transMicroServiceInfoFromConsul() {
- List<String> tagList = new ArrayList<String>();
- tagList.add("\"base\":{\"protocol\":\"REST\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
- tagList
- .add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}");
- tagList.add("\"ns\":{\"namespace\":\"ns1\"}");
-
- Service service =
- ImmutableService.builder().id("id").port(8686).address("10.74.165.246").service("msbtest")
- .addAllTags(tagList).createIndex(0).modifyIndex(0).build();
- ServiceHealth serviceHealth =
- ImmutableServiceHealth.builder().service(service)
- .node(ImmutableNode.builder().node("server").address("192.168.1.98").build()).build();
- List<ServiceHealth> serviceHealthList = new ArrayList<ServiceHealth>();
- serviceHealthList.add(serviceHealth);
-
- Map<String, MicroServiceFullInfo> serviceMap= ServiceFilter.getInstance().transMicroServiceInfoFromConsul(serviceHealthList);
- Assert.assertTrue(serviceMap.containsKey("v1"));
-
- MicroServiceFullInfo microService=new MicroServiceFullInfo();
- microService.setServiceName("msbtest");
- microService.setVersion("v1");
- microService.setUrl("/api/msbtest/v1");
- microService.setProtocol("REST");
- microService.setVisualRange("0");
- microService.setNamespace("ns1");
-
- Set<Node> nodes=new HashSet<Node>();
- nodes.add(new Node("10.74.165.246","8686"));
- microService.setNodes(nodes);
-
-
-
- Assert.assertEquals(microService,serviceMap.get("v1"));
-
-
- }
+ @Test
+ public void test_isNeedNotifyByNameSpace() {
+
+ PowerMockito.mockStatic(System.class);
+
+ PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("all");
+ ConfigUtil.getInstance().initRouteNameSpaceMatches();
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace("test")); // namespaceMatches:all
+
+ PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("default");
+ ConfigUtil.getInstance().initRouteNameSpaceMatches();
+ Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNameSpace("test"));// namespaceMatches:default
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace(""));// namespaceMatches:default
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace("default"));// namespaceMatches:default
+
+
+ PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("!default");
+ ConfigUtil.getInstance().initRouteNameSpaceMatches();
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace("test"));// namespaceMatches:!default
+ Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNameSpace(""));// namespaceMatches:!default
+
+ PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("ns|ns2");
+ ConfigUtil.getInstance().initRouteNameSpaceMatches();
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace("ns"));
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace("ns2"));
+ Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNameSpace("ns3"));
+ Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNameSpace(""));
+
+
+ PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("!ns&!ns2");
+ ConfigUtil.getInstance().initRouteNameSpaceMatches();
+ Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNameSpace("ns"));
+ Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNameSpace("ns2"));
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNameSpace("ns3"));
+
+ }
+
+ /*
+ * @Test public void test_isNeedNotifyByVisualRange(){
+ *
+ * Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByVisualRange("0"));
+ * Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByVisualRange("1"));
+ * Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByVisualRange("0|1")); }
+ */
+
+ @Test
+ public void test_isNeedNotifyByProtocol() {
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByProtocol("HTTP"));
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByProtocol("UI"));
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByProtocol("REST"));
+ Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByProtocol("TCP"));
+ }
+
+ @Test
+ public void test_isNeedNotifyByNetwork_plane_typeMatches() {
+
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn("network_plane_type:network");
+ ConfigUtil.getInstance().initRouteLabelsMatches();
+ Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNetwork_plane_typeMatches("net"));
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNetwork_plane_typeMatches("network"));
+
+ PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn("network_plane_type:net1|net2");
+ ConfigUtil.getInstance().initRouteLabelsMatches();
+ Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByNetwork_plane_typeMatches("net"));
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNetwork_plane_typeMatches("net1"));
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByNetwork_plane_typeMatches("net2"));
+
+ }
+
+ @Test
+ public void test_isNeedNotifyByRouteLabels() {
+ Map<String, String> labelMap = new HashMap<String, String>();
+ labelMap.put("lab1", "val1");
+
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn("lab1:val,visualRange:1");
+ ConfigUtil.getInstance().initRouteLabelsMatches();
+ Assert.assertFalse(ServiceFilter.getInstance().isNeedNotifyByRouteLabels(labelMap));
+
+ PowerMockito.when(System.getenv("ROUTE_LABELS")).thenReturn("lab1:val1");
+ ConfigUtil.getInstance().initRouteLabelsMatches();
+ Assert.assertTrue(ServiceFilter.getInstance().isNeedNotifyByRouteLabels(labelMap));
+
+ }
+
+ @Test
+ public void test_isFilterService() {
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.getenv("NAMESPACE")).thenReturn("ns1");
+ ConfigUtil.getInstance().initRouteNameSpaceMatches();
+
+ PowerMockito.when(System.getenv("ROUTE_LABELS"))
+ .thenReturn("visualRange:0,network_plane_type:net,customLabel:custom|custom2");
+ ConfigUtil.getInstance().initRouteLabelsMatches();
+
+ List<String> tagList = new ArrayList<String>();
+ tagList.add("\"base\":{\"protocol\":\"REST\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
+ tagList.add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}");
+ tagList.add("\"ns\":{\"namespace\":\"ns1\"}");
+ Assert.assertTrue(ServiceFilter.getInstance().isFilterService(tagList));
+
+ tagList.clear();
+ tagList.add("\"base\":{\"protocol\":\"TCP\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
+ Assert.assertFalse(ServiceFilter.getInstance().isFilterService(tagList));
+
+ tagList.clear();
+ tagList.add("\"base\":{\"protocol\":\"UI\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
+ tagList.add("\"ns\":{\"namespace\":\"ns2\"}");
+ Assert.assertFalse(ServiceFilter.getInstance().isFilterService(tagList));
+
+ tagList.clear();
+ tagList.add("\"base\":{\"protocol\":\"UI\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
+ tagList.add("\"ns\":{\"namespace\":\"ns1\"}");
+ tagList.add("\"labels\":{\"visualRange\":\"1\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}");
+ Assert.assertFalse(ServiceFilter.getInstance().isFilterService(tagList));
+
+ tagList.clear();
+ tagList.add("\"base\":{\"protocol\":\"UI\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
+ tagList.add("\"ns\":{\"namespace\":\"ns1\"}");
+ tagList.add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net2\",\"customLabel\":\"custom\"}");
+ Assert.assertFalse(ServiceFilter.getInstance().isFilterService(tagList));
+
+ tagList.clear();
+ tagList.add("\"base\":{\"protocol\":\"UI\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
+ tagList.add("\"ns\":{\"namespace\":\"ns1\"}");
+ tagList.add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom3\"}");
+ Assert.assertFalse(ServiceFilter.getInstance().isFilterService(tagList));
+
+ }
+
+ @Test
+ public void test_transMicroServiceInfoFromConsul() {
+ List<String> tagList = new ArrayList<String>();
+ tagList.add("\"base\":{\"protocol\":\"REST\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
+ tagList.add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}");
+ tagList.add("\"ns\":{\"namespace\":\"ns1\"}");
+
+ Service service = ImmutableService.builder().id("id").port(8686).address("10.74.165.246").service("msbtest")
+ .addAllTags(tagList).createIndex(0).modifyIndex(0).build();
+ ServiceHealth serviceHealth = ImmutableServiceHealth.builder().service(service)
+ .node(ImmutableNode.builder().node("server").address("192.168.1.98").build()).build();
+ List<ServiceHealth> serviceHealthList = new ArrayList<ServiceHealth>();
+ serviceHealthList.add(serviceHealth);
+
+ Map<String, MicroServiceFullInfo> serviceMap =
+ ServiceFilter.getInstance().transMicroServiceInfoFromConsul(serviceHealthList);
+ Assert.assertTrue(serviceMap.containsKey("v1"));
+
+ MicroServiceFullInfo microService = new MicroServiceFullInfo();
+ microService.setServiceName("msbtest");
+ microService.setVersion("v1");
+ microService.setUrl("/api/msbtest/v1");
+ microService.setProtocol("REST");
+ microService.setVisualRange("0");
+ microService.setNamespace("ns1");
+
+ Set<Node> nodes = new HashSet<Node>();
+ nodes.add(new Node("10.74.165.246", "8686"));
+ microService.setNodes(nodes);
+
+
+
+ Assert.assertEquals(microService, serviceMap.get("v1"));
+
+
+ }