1. Adjust the directory hierarchy
[msb/apigateway.git] / msb-core / apiroute / apiroute-service / src / test / java / org / openo / msb / wrapper / ApiRouteServiceWrapperTest.java
1 /**\r
2 * Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
3 *\r
4 * Licensed under the Apache License, Version 2.0 (the "License");\r
5 * you may not use this file except in compliance with the License.\r
6 * You may obtain a copy of the License at\r
7 *\r
8 * http://www.apache.org/licenses/LICENSE-2.0\r
9 *\r
10 * Unless required by applicable law or agreed to in writing, software\r
11 * distributed under the License is distributed on an "AS IS" BASIS,\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 * See the License for the specific language governing permissions and\r
14 * limitations under the License.\r
15 */\r
16 package org.openo.msb.wrapper;\r
17 \r
18 import org.junit.After;\r
19 import org.junit.Assert;\r
20 import org.junit.Before;\r
21 import org.junit.BeforeClass;\r
22 import org.junit.Test;\r
23 import org.openo.msb.api.ApiRouteInfo;\r
24 import org.openo.msb.api.RouteServer;\r
25 import org.openo.msb.api.exception.ExtendedInternalServerErrorException;\r
26 import org.openo.msb.api.exception.ExtendedNotFoundException;\r
27 \r
28 public class ApiRouteServiceWrapperTest {\r
29     private static ApiRouteServiceWrapper apiRouteServiceWrapper;\r
30     \r
31     @BeforeClass\r
32     public static void setUpBeforeClass() throws Exception {\r
33         apiRouteServiceWrapper=ApiRouteServiceWrapper.getInstance();\r
34     }\r
35     \r
36     @Before\r
37     public void setUp() {\r
38         ApiRouteInfo apiRouteInfo=new ApiRouteInfo();\r
39         apiRouteInfo.setServiceName("testForJunit");\r
40         apiRouteInfo.setVersion("v1");\r
41         apiRouteInfo.setUrl("/api/test/v1");\r
42         RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")};\r
43         apiRouteInfo.setServers(servers);\r
44         try {\r
45             apiRouteServiceWrapper.saveApiRouteInstance(apiRouteInfo, "");\r
46         }\r
47         catch(ExtendedInternalServerErrorException e){\r
48         }\r
49         catch (Exception e){\r
50             Assert.fail("Exception" + e.getMessage());\r
51         }\r
52         \r
53     }\r
54     \r
55     @After\r
56     public void tearDown() {        \r
57         try {\r
58             apiRouteServiceWrapper.deleteApiRoute("testForJunit", "v1", "*", "");      \r
59         } \r
60         catch(ExtendedInternalServerErrorException e){\r
61             \r
62         }catch (Exception e) {\r
63             Assert.fail("Exception" + e.getMessage());\r
64         }\r
65     }\r
66     \r
67     @Test\r
68     public void testGetAllApiRouteInstances(){\r
69         try {\r
70         ApiRouteInfo[] apiRouteInfoList=apiRouteServiceWrapper.getAllApiRouteInstances();\r
71         Assert.assertTrue(apiRouteInfoList.length >= 0);\r
72         }\r
73         catch(ExtendedInternalServerErrorException e){\r
74             \r
75         }\r
76         catch(Exception e){\r
77             Assert.fail("Exception" + e.getMessage());\r
78         }\r
79        \r
80     }\r
81     \r
82     @Test\r
83     public void testGetApiRouteInstance_not_exist(){\r
84         ApiRouteInfo apiRouteInfo = null;\r
85         try {\r
86            apiRouteInfo=apiRouteServiceWrapper.getApiRouteInstance("testForJunit", "v2");\r
87            Assert.assertNotNull(apiRouteInfo);\r
88         }\r
89         catch(ExtendedInternalServerErrorException e){\r
90             \r
91         }\r
92         catch(ExtendedNotFoundException e){\r
93             Assert.assertNull(apiRouteInfo);\r
94         }\r
95        \r
96     }\r
97     \r
98     @Test\r
99     public void testGetApiRouteInstance_exist(){\r
100         try {\r
101         ApiRouteInfo apiRouteInfo=apiRouteServiceWrapper.getApiRouteInstance("testForJunit", "v1");\r
102         Assert.assertNotNull(apiRouteInfo);\r
103         }\r
104         catch(ExtendedInternalServerErrorException e){\r
105             \r
106         }\r
107         catch(Exception e){\r
108             Assert.fail("Exception" + e.getMessage());\r
109         }\r
110        \r
111     }\r
112     \r
113     @Test\r
114     public void testUpdateApiRouteInstance(){\r
115         try {\r
116             \r
117             ApiRouteInfo apiRouteInfo=new ApiRouteInfo();\r
118             apiRouteInfo.setServiceName("testForJunit");\r
119             apiRouteInfo.setVersion("v1");\r
120             apiRouteInfo.setUrl("/api/test_update/v1");\r
121             RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")};\r
122             apiRouteInfo.setServers(servers);\r
123             \r
124             ApiRouteInfo new_apiRouteInfo= apiRouteServiceWrapper.updateApiRouteInstance("testForJunit", "v1", apiRouteInfo, "");\r
125             Assert.assertEquals("/api/test_update/v1", new_apiRouteInfo.getUrl());\r
126         }\r
127         catch(ExtendedInternalServerErrorException e){\r
128             \r
129         }\r
130         catch(Exception e){\r
131             Assert.assertEquals("Get Jedis from pool failed!",e.getMessage());\r
132             \r
133 //            Assert.fail("Exception" + e.getMessage());\r
134         \r
135         }\r
136     }\r
137     \r
138     @Test\r
139     public void testUpdateApiRouteStatus(){\r
140         try { \r
141             ApiRouteInfo new_apiRouteInfo= apiRouteServiceWrapper.updateApiRouteStatus("testForJunit", "v1", "0");\r
142             Assert.assertEquals("0",new_apiRouteInfo.getStatus());\r
143         }\r
144         catch(ExtendedInternalServerErrorException e){\r
145             \r
146         }catch(Exception e){\r
147             Assert.fail("Exception" + e.getMessage());\r
148         \r
149         }\r
150     }\r
151     \r
152     @Test\r
153     public void testGetApiGatewayPort(){\r
154         try { \r
155             String port= apiRouteServiceWrapper.getApiGatewayPort();\r
156             Assert.assertEquals("10080",port);\r
157         }catch(Exception e){\r
158             Assert.fail("Exception" + e.getMessage());\r
159         \r
160         }\r
161     }\r
162    \r
163     \r
164 }\r