From 4ed15bda06c8e9a407c12d527b8224737ba339d5 Mon Sep 17 00:00:00 2001 From: HuabingZhao Date: Sat, 13 Aug 2016 14:10:39 +0800 Subject: Initial code import Change-Id: I839b84e5200aedece6c33deb16bec1bf9dbb61df Signed-off-by: HuabingZhao --- .../msb/wrapper/ApiRouteServiceWrapperTest.java | 164 +++++++++++++++++++++ .../msb/wrapper/CustomRouteServiceWrapperTest.java | 137 +++++++++++++++++ .../msb/wrapper/IuiRouteServiceWrapperTest.java | 137 +++++++++++++++++ .../openo/msb/wrapper/MicroServiceWrapperTest.java | 148 +++++++++++++++++++ .../msb/wrapper/util/JacksonJsonUtilTest.java | 48 ++++++ .../openo/msb/wrapper/util/RegExpTestUtilTest.java | 86 +++++++++++ .../org/openo/msb/wrapper/util/RouteUtilTest.java | 64 ++++++++ 7 files changed, 784 insertions(+) create mode 100644 apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/ApiRouteServiceWrapperTest.java create mode 100644 apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/CustomRouteServiceWrapperTest.java create mode 100644 apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/IuiRouteServiceWrapperTest.java create mode 100644 apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/MicroServiceWrapperTest.java create mode 100644 apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/util/JacksonJsonUtilTest.java create mode 100644 apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/util/RegExpTestUtilTest.java create mode 100644 apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/util/RouteUtilTest.java (limited to 'apiroute/apiroute-service/src/test') diff --git a/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/ApiRouteServiceWrapperTest.java b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/ApiRouteServiceWrapperTest.java new file mode 100644 index 0000000..3f7a301 --- /dev/null +++ b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/ApiRouteServiceWrapperTest.java @@ -0,0 +1,164 @@ +/** +* Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE) +* +* 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 +* +* 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.openo.msb.wrapper; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openo.msb.api.ApiRouteInfo; +import org.openo.msb.api.RouteServer; +import org.openo.msb.api.exception.ExtendedInternalServerErrorException; +import org.openo.msb.api.exception.ExtendedNotFoundException; + +public class ApiRouteServiceWrapperTest { + private static ApiRouteServiceWrapper apiRouteServiceWrapper; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + apiRouteServiceWrapper=ApiRouteServiceWrapper.getInstance(); + } + + @Before + public void setUp() { + ApiRouteInfo apiRouteInfo=new ApiRouteInfo(); + apiRouteInfo.setServiceName("testForJunit"); + apiRouteInfo.setVersion("v1"); + apiRouteInfo.setUrl("/api/test/v1"); + RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")}; + apiRouteInfo.setServers(servers); + try { + apiRouteServiceWrapper.saveApiRouteInstance(apiRouteInfo, ""); + } + catch(ExtendedInternalServerErrorException e){ + } + catch (Exception e){ + Assert.fail("Exception" + e.getMessage()); + } + + } + + @After + public void tearDown() { + try { + apiRouteServiceWrapper.deleteApiRoute("testForJunit", "v1", "*", ""); + } + catch(ExtendedInternalServerErrorException e){ + + }catch (Exception e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Test + public void testGetAllApiRouteInstances(){ + try { + ApiRouteInfo[] apiRouteInfoList=apiRouteServiceWrapper.getAllApiRouteInstances(); + Assert.assertTrue(apiRouteInfoList.length >= 0); + } + catch(ExtendedInternalServerErrorException e){ + + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + } + + } + + @Test + public void testGetApiRouteInstance_not_exist(){ + ApiRouteInfo apiRouteInfo = null; + try { + apiRouteInfo=apiRouteServiceWrapper.getApiRouteInstance("testForJunit", "v2"); + Assert.assertNotNull(apiRouteInfo); + } + catch(ExtendedInternalServerErrorException e){ + + } + catch(ExtendedNotFoundException e){ + Assert.assertNull(apiRouteInfo); + } + + } + + @Test + public void testGetApiRouteInstance_exist(){ + try { + ApiRouteInfo apiRouteInfo=apiRouteServiceWrapper.getApiRouteInstance("testForJunit", "v1"); + Assert.assertNotNull(apiRouteInfo); + } + catch(ExtendedInternalServerErrorException e){ + + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + } + + } + + @Test + public void testUpdateApiRouteInstance(){ + try { + + ApiRouteInfo apiRouteInfo=new ApiRouteInfo(); + apiRouteInfo.setServiceName("testForJunit"); + apiRouteInfo.setVersion("v1"); + apiRouteInfo.setUrl("/api/test_update/v1"); + RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")}; + apiRouteInfo.setServers(servers); + + ApiRouteInfo new_apiRouteInfo= apiRouteServiceWrapper.updateApiRouteInstance("testForJunit", "v1", apiRouteInfo, ""); + Assert.assertEquals("/api/test_update/v1", new_apiRouteInfo.getUrl()); + } + catch(ExtendedInternalServerErrorException e){ + + } + catch(Exception e){ + Assert.assertEquals("Get Jedis from pool failed!",e.getMessage()); + +// Assert.fail("Exception" + e.getMessage()); + + } + } + + @Test + public void testUpdateApiRouteStatus(){ + try { + ApiRouteInfo new_apiRouteInfo= apiRouteServiceWrapper.updateApiRouteStatus("testForJunit", "v1", "0"); + Assert.assertEquals("0",new_apiRouteInfo.getStatus()); + } + catch(ExtendedInternalServerErrorException e){ + + }catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + + } + } + + @Test + public void testGetApiGatewayPort(){ + try { + String port= apiRouteServiceWrapper.getApiGatewayPort(); + Assert.assertEquals("10080",port); + }catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + + } + } + + +} diff --git a/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/CustomRouteServiceWrapperTest.java b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/CustomRouteServiceWrapperTest.java new file mode 100644 index 0000000..cd8e9fd --- /dev/null +++ b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/CustomRouteServiceWrapperTest.java @@ -0,0 +1,137 @@ +/** +* Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE) +* +* 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 +* +* 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.openo.msb.wrapper; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openo.msb.api.CustomRouteInfo; +import org.openo.msb.api.RouteServer; +import org.openo.msb.api.exception.ExtendedInternalServerErrorException; +import org.openo.msb.api.exception.ExtendedNotFoundException; + +public class CustomRouteServiceWrapperTest { + + private static CustomRouteServiceWrapper customRouteServiceWrapper; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + customRouteServiceWrapper=CustomRouteServiceWrapper.getInstance(); + } + + @Before + public void setUp() { + CustomRouteInfo customRouteInfo=new CustomRouteInfo(); + customRouteInfo.setServiceName("/testForJunit"); + customRouteInfo.setUrl("/test"); + RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")}; + customRouteInfo.setServers(servers); + try { + customRouteServiceWrapper.saveCustomRouteInstance(customRouteInfo,""); + } + catch(ExtendedInternalServerErrorException e){ + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + } + + } + + @After + public void tearDown() { + try { + customRouteServiceWrapper.deleteCustomRoute("/testForJunit", "*",""); + } + catch(ExtendedInternalServerErrorException e){ + }catch (Exception e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Test + public void testGetAllCustomRouteInstances(){ + try { + CustomRouteInfo[] customRouteInfoList=customRouteServiceWrapper.getAllCustomRouteInstances(); + Assert.assertTrue(customRouteInfoList.length >= 0); + }catch(ExtendedInternalServerErrorException e){ + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + } + + } + + @Test + public void testGetCustomRouteInstance_not_exist(){ + CustomRouteInfo customRouteInfo = null; + try { + customRouteInfo=customRouteServiceWrapper.getCustomRouteInstance("/testForJunit2"); + Assert.assertNotNull(customRouteInfo); + }catch(ExtendedInternalServerErrorException e){ + } + catch(ExtendedNotFoundException e){ + Assert.assertNull(customRouteInfo); + } + + } + + @Test + public void testGetCustomRouteInstance_exist(){ + try { + CustomRouteInfo customRouteInfo=customRouteServiceWrapper.getCustomRouteInstance("/testForJunit"); + Assert.assertNotNull(customRouteInfo); + }catch(ExtendedInternalServerErrorException e){ + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + } + + } + + @Test + public void testUpdateCustomRouteInstance(){ + try { + + CustomRouteInfo customRouteInfo=new CustomRouteInfo(); + customRouteInfo.setServiceName("/testForJunit"); + customRouteInfo.setUrl("/test_update"); + RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")}; + customRouteInfo.setServers(servers); + + CustomRouteInfo new_customRouteInfo= customRouteServiceWrapper.updateCustomRouteInstance("/testForJunit", customRouteInfo,""); + Assert.assertEquals("/test_update", new_customRouteInfo.getUrl()); + }catch(ExtendedInternalServerErrorException e){ + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + + } + } + + @Test + public void testUpdateCustomRouteStatus(){ + try { + CustomRouteInfo new_CustomRouteInfo= customRouteServiceWrapper.updateCustomRouteStatus("/testForJunit", "0"); + Assert.assertEquals("0",new_CustomRouteInfo.getStatus()); + }catch(ExtendedInternalServerErrorException e){ + }catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + + } + } +} diff --git a/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/IuiRouteServiceWrapperTest.java b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/IuiRouteServiceWrapperTest.java new file mode 100644 index 0000000..0b6b899 --- /dev/null +++ b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/IuiRouteServiceWrapperTest.java @@ -0,0 +1,137 @@ +/** +* Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE) +* +* 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 +* +* 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.openo.msb.wrapper; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openo.msb.api.IuiRouteInfo; +import org.openo.msb.api.RouteServer; +import org.openo.msb.api.exception.ExtendedInternalServerErrorException; +import org.openo.msb.api.exception.ExtendedNotFoundException; + +public class IuiRouteServiceWrapperTest { + private static IuiRouteServiceWrapper iuiRouteServiceWrapper; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + iuiRouteServiceWrapper=IuiRouteServiceWrapper.getInstance(); + } + + @Before + public void setUp() { + IuiRouteInfo iuiRouteInfo=new IuiRouteInfo(); + iuiRouteInfo.setServiceName("testForJunit"); + iuiRouteInfo.setUrl("/iui/test"); + RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")}; + iuiRouteInfo.setServers(servers); + try { + iuiRouteServiceWrapper.saveIuiRouteInstance(iuiRouteInfo); + }catch(ExtendedInternalServerErrorException e){ + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + } + + } + + @After + public void tearDown() { + try { + iuiRouteServiceWrapper.deleteIuiRoute("testForJunit", "*"); + }catch(ExtendedInternalServerErrorException e){ + } catch (Exception e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Test + public void testGetAllIuiRouteInstances(){ + try { + IuiRouteInfo[] iuiRouteInfoList=iuiRouteServiceWrapper.getAllIuiRouteInstances(); + Assert.assertTrue(iuiRouteInfoList.length >= 0); + }catch(ExtendedInternalServerErrorException e){ + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + } + + } + + @Test + public void testGetIuiRouteInstance_not_exist(){ + IuiRouteInfo iuiRouteInfo = null; + try { + iuiRouteInfo=iuiRouteServiceWrapper.getIuiRouteInstance("testForJunit2"); + Assert.assertNotNull(iuiRouteInfo); + }catch(ExtendedInternalServerErrorException e){ + } + catch(ExtendedNotFoundException e){ + Assert.assertNull(iuiRouteInfo); + } + + } + + @Test + public void testGetIuiRouteInstance_exist(){ + try { + IuiRouteInfo iuiRouteInfo=iuiRouteServiceWrapper.getIuiRouteInstance("testForJunit"); + Assert.assertNotNull(iuiRouteInfo); + }catch(ExtendedInternalServerErrorException e){ + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + } + + } + + @Test + public void testUpdateIuiRouteInstance(){ + try { + + IuiRouteInfo iuiRouteInfo=new IuiRouteInfo(); + iuiRouteInfo.setServiceName("testForJunit"); + iuiRouteInfo.setUrl("/iui/test_update"); + RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")}; + iuiRouteInfo.setServers(servers); + + IuiRouteInfo new_iuiRouteInfo= iuiRouteServiceWrapper.updateIuiRouteInstance("testForJunit", iuiRouteInfo); + Assert.assertEquals("/iui/test_update", new_iuiRouteInfo.getUrl()); + }catch(ExtendedInternalServerErrorException e){ + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + + } + } + + @Test + public void testUpdateIuiRouteStatus(){ + try { + IuiRouteInfo new_iuiRouteInfo= iuiRouteServiceWrapper.updateIuiRouteStatus("testForJunit", "0"); + Assert.assertEquals("0",new_iuiRouteInfo.getStatus()); + }catch(ExtendedInternalServerErrorException e){ + }catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + + } + } + + + +} diff --git a/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/MicroServiceWrapperTest.java b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/MicroServiceWrapperTest.java new file mode 100644 index 0000000..621b44a --- /dev/null +++ b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/MicroServiceWrapperTest.java @@ -0,0 +1,148 @@ +/** +* Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE) +* +* 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 +* +* 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.openo.msb.wrapper; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openo.msb.api.MicroServiceFullInfo; +import org.openo.msb.api.MicroServiceInfo; +import org.openo.msb.api.Node; +import org.openo.msb.api.exception.ExtendedInternalServerErrorException; +import org.openo.msb.api.exception.ExtendedNotFoundException; + +public class MicroServiceWrapperTest { + private static MicroServiceWrapper microServiceWrapper; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + microServiceWrapper=microServiceWrapper.getInstance(); + } + + @Before + public void setUp() { + MicroServiceInfo microServiceInfo=new MicroServiceInfo(); + microServiceInfo.setServiceName("testForJunit"); + microServiceInfo.setVersion("v1"); + microServiceInfo.setUrl("/api/test/v1"); + microServiceInfo.setProtocol("REST"); + microServiceInfo.setVisualRange("0"); + Set nodes=new HashSet(); + nodes.add(new Node("127.0.0.1","8080",0)); + microServiceInfo.setNodes(nodes); + try { + microServiceWrapper.saveMicroServiceInstance(microServiceInfo,true,"",""); + }catch(ExtendedInternalServerErrorException e){ + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + } + + } + + @After + public void tearDown() { + try { + microServiceWrapper.deleteMicroService("testForJunit", "v1", ""); + }catch(ExtendedInternalServerErrorException e){ + } catch (Exception e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Test + public void testGetAllMicroServiceInstances(){ + try { + MicroServiceFullInfo[] MicroServiceInfoList=microServiceWrapper.getAllMicroServiceInstances(); + Assert.assertTrue(MicroServiceInfoList.length >= 0); + }catch(ExtendedInternalServerErrorException e){ + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + } + + } + + @Test + public void testGetMicroServiceInstance_not_exist(){ + MicroServiceFullInfo microServiceInfo = null; + try { + microServiceInfo=microServiceWrapper.getMicroServiceInstance("testForJunit", "v2",""); + Assert.assertNotNull(microServiceInfo); + }catch(ExtendedInternalServerErrorException e){ + } + catch(ExtendedNotFoundException e){ + Assert.assertNull(microServiceInfo); + } + + } + + @Test + public void testGetMicroServiceInstance_exist(){ + try { + MicroServiceFullInfo microServiceInfo=microServiceWrapper.getMicroServiceInstance("testForJunit", "v1",""); + Assert.assertNotNull(microServiceInfo); + }catch(ExtendedInternalServerErrorException e){ + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + } + + } + + @Test + public void testUpdateMicroServiceInstance(){ + try { + + MicroServiceInfo microServiceInfo=new MicroServiceInfo(); + microServiceInfo.setServiceName("testForJunit"); + microServiceInfo.setVersion("v1"); + microServiceInfo.setUrl("/api/test2/v1"); + microServiceInfo.setProtocol("REST"); + microServiceInfo.setVisualRange("0"); + Set nodes=new HashSet(); + nodes.add(new Node("127.0.0.1","8080",0)); + microServiceInfo.setNodes(nodes); + + MicroServiceFullInfo new_MicroServiceInfo= microServiceWrapper.updateMicroServiceInstance("testForJunit", "v1", microServiceInfo); + Assert.assertEquals("/api/test2/v1", new_MicroServiceInfo.getUrl()); + }catch(ExtendedInternalServerErrorException e){ + } + catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + + } + } + + @Test + public void testUpdateMicroServiceStatus(){ + try { + MicroServiceFullInfo new_MicroServiceInfo= microServiceWrapper.updateMicroServiceStatus("testForJunit", "v1", "0"); + Assert.assertEquals("0",new_MicroServiceInfo.getStatus()); + }catch(ExtendedInternalServerErrorException e){ + }catch(Exception e){ + Assert.fail("Exception" + e.getMessage()); + + } + } + + +} diff --git a/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/util/JacksonJsonUtilTest.java b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/util/JacksonJsonUtilTest.java new file mode 100644 index 0000000..dd1c7bc --- /dev/null +++ b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/util/JacksonJsonUtilTest.java @@ -0,0 +1,48 @@ +/** +* Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE) +* +* 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 +* +* 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.openo.msb.wrapper.util; + +import org.junit.Assert; +import org.junit.Test; +import org.openo.msb.api.RouteServer; + + +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){ + 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){ + Assert.fail("Exception" + e.getMessage()); + } + } +} diff --git a/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/util/RegExpTestUtilTest.java b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/util/RegExpTestUtilTest.java new file mode 100644 index 0000000..fbe8378 --- /dev/null +++ b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/util/RegExpTestUtilTest.java @@ -0,0 +1,86 @@ +/** +* Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE) +* +* 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 +* +* 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.openo.msb.wrapper.util; + +import org.junit.Assert; + +import org.junit.Test; + +public class RegExpTestUtilTest { + + @Test + public void testHostRegExpTest(){ + boolean result=RegExpTestUtil.hostRegExpTest("127.0.0.1:8080"); + Assert.assertTrue(result); + + boolean err_result=RegExpTestUtil.hostRegExpTest("0.0.0.1:89"); + Assert.assertFalse(err_result); + } + + @Test + public void testIpRegExpTest(){ + boolean result=RegExpTestUtil.ipRegExpTest("127.0.0.1"); + Assert.assertTrue(result); + + boolean err_result=RegExpTestUtil.ipRegExpTest("127.0.0.1.5"); + Assert.assertFalse(err_result); + } + + @Test + public void testPortRegExpTest(){ + boolean result=RegExpTestUtil.portRegExpTest("80"); + Assert.assertTrue(result); + + boolean err_result=RegExpTestUtil.portRegExpTest("898989"); + Assert.assertFalse(err_result); + } + + @Test + public void testVersionRegExpTest(){ + boolean result=RegExpTestUtil.versionRegExpTest("v1"); + Assert.assertTrue(result); + + boolean err_result=RegExpTestUtil.versionRegExpTest("23"); + Assert.assertFalse(err_result); + } + + @Test + public void testurlRegExpTest(){ + boolean result=RegExpTestUtil.urlRegExpTest("/test"); + Assert.assertTrue(result); + + boolean err_result=RegExpTestUtil.urlRegExpTest("test"); + Assert.assertFalse(err_result); + } + + @Test + public void testapiRouteUrlRegExpTest(){ + boolean result=RegExpTestUtil.apiRouteUrlRegExpTest("/api/test/v1"); + Assert.assertTrue(result); + + boolean err_result=RegExpTestUtil.apiRouteUrlRegExpTest("/test"); + Assert.assertFalse(err_result); + } + + @Test + public void testiuiRouteUrlRegExpTest(){ + boolean result=RegExpTestUtil.iuiRouteUrlRegExpTest("/iui/test"); + Assert.assertTrue(result); + + boolean err_result=RegExpTestUtil.iuiRouteUrlRegExpTest("/test"); + Assert.assertFalse(err_result); + } +} diff --git a/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/util/RouteUtilTest.java b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/util/RouteUtilTest.java new file mode 100644 index 0000000..d2c645b --- /dev/null +++ b/apiroute/apiroute-service/src/test/java/org/openo/msb/wrapper/util/RouteUtilTest.java @@ -0,0 +1,64 @@ +/** +* Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE) +* +* 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 +* +* 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.openo.msb.wrapper.util; + +import org.apache.commons.lang3.StringUtils; +import org.junit.Assert; +import org.junit.Test; + +public class RouteUtilTest { + + @Test + public void testGetPrefixedKey(){ + String path=RouteUtil.getPrefixedKey("","test","v1"); + Assert.assertEquals("msb:routing:test:v1",path); + } + + @Test + public void testConcat(){ + Object[] str1=new String[]{"test1","test2"}; + Object[] str2=new String[]{"test3"}; + Object[] str3=RouteUtil.concat(str1, str2); + + Assert.assertEquals(3,str3.length); + } + + @Test + public void testContainStr(){ + String value="1"; + String array[]={"1","2"}; + boolean result=RouteUtil.contain(array, value); + Assert.assertTrue(result); + } + + @Test + public void testContainArray(){ + String value[]={"0"}; + String array[]={"1","2"}; + boolean result=RouteUtil.contain(array, value); + Assert.assertFalse(result); + + } + + @Test + public void testShow(){ + String array[]={"1","2"}; + String result=RouteUtil.show(array); + Assert.assertEquals("1|2",result); + + } + +} -- cgit 1.2.3-korg