1. Adjust the directory hierarchy
[msb/apigateway.git] / msb-core / apiroute / apiroute-service / src / test / java / org / openo / msb / wrapper / CustomRouteServiceWrapperTest.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.CustomRouteInfo;\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 CustomRouteServiceWrapperTest {\r
29 \r
30   private static CustomRouteServiceWrapper customRouteServiceWrapper;\r
31     \r
32     @BeforeClass\r
33     public static void setUpBeforeClass() throws Exception {\r
34         customRouteServiceWrapper=CustomRouteServiceWrapper.getInstance();\r
35     }\r
36     \r
37     @Before\r
38     public void setUp() {\r
39         CustomRouteInfo customRouteInfo=new CustomRouteInfo();\r
40         customRouteInfo.setServiceName("/testForJunit");\r
41         customRouteInfo.setUrl("/test");\r
42         RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")};\r
43         customRouteInfo.setServers(servers);\r
44         try {\r
45             customRouteServiceWrapper.saveCustomRouteInstance(customRouteInfo,"");\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             customRouteServiceWrapper.deleteCustomRoute("/testForJunit", "*","");      \r
59         } \r
60         catch(ExtendedInternalServerErrorException e){\r
61         }catch (Exception e) {\r
62             Assert.fail("Exception" + e.getMessage());\r
63         }\r
64     }\r
65     \r
66     @Test\r
67     public void testGetAllCustomRouteInstances(){\r
68         try {\r
69             CustomRouteInfo[] customRouteInfoList=customRouteServiceWrapper.getAllCustomRouteInstances();\r
70             Assert.assertTrue(customRouteInfoList.length >= 0);\r
71         }catch(ExtendedInternalServerErrorException e){\r
72         }\r
73         catch(Exception e){\r
74             Assert.fail("Exception" + e.getMessage());\r
75         }\r
76        \r
77     }\r
78     \r
79     @Test\r
80     public void testGetCustomRouteInstance_not_exist(){\r
81         CustomRouteInfo customRouteInfo = null;\r
82         try {\r
83             customRouteInfo=customRouteServiceWrapper.getCustomRouteInstance("/testForJunit2");\r
84             Assert.assertNotNull(customRouteInfo);\r
85         }catch(ExtendedInternalServerErrorException e){\r
86         }\r
87         catch(ExtendedNotFoundException e){\r
88             Assert.assertNull(customRouteInfo);\r
89         }\r
90        \r
91     }\r
92     \r
93     @Test\r
94     public void testGetCustomRouteInstance_exist(){\r
95         try {\r
96             CustomRouteInfo customRouteInfo=customRouteServiceWrapper.getCustomRouteInstance("/testForJunit");\r
97             Assert.assertNotNull(customRouteInfo);\r
98         }catch(ExtendedInternalServerErrorException e){\r
99         }\r
100         catch(Exception e){\r
101             Assert.fail("Exception" + e.getMessage());\r
102         }\r
103        \r
104     }\r
105     \r
106     @Test\r
107     public void testUpdateCustomRouteInstance(){\r
108         try {\r
109             \r
110             CustomRouteInfo customRouteInfo=new CustomRouteInfo();\r
111             customRouteInfo.setServiceName("/testForJunit");\r
112             customRouteInfo.setUrl("/test_update");\r
113             RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")};\r
114             customRouteInfo.setServers(servers);\r
115             \r
116             CustomRouteInfo new_customRouteInfo= customRouteServiceWrapper.updateCustomRouteInstance("/testForJunit", customRouteInfo,"");\r
117             Assert.assertEquals("/test_update", new_customRouteInfo.getUrl());\r
118         }catch(ExtendedInternalServerErrorException e){\r
119         }\r
120         catch(Exception e){\r
121             Assert.fail("Exception" + e.getMessage());\r
122         \r
123         }\r
124     }\r
125     \r
126     @Test\r
127     public void testUpdateCustomRouteStatus(){\r
128         try { \r
129             CustomRouteInfo new_CustomRouteInfo= customRouteServiceWrapper.updateCustomRouteStatus("/testForJunit", "0");\r
130             Assert.assertEquals("0",new_CustomRouteInfo.getStatus());\r
131         }catch(ExtendedInternalServerErrorException e){\r
132         }catch(Exception e){\r
133             Assert.fail("Exception" + e.getMessage());\r
134         \r
135         }\r
136     }\r
137 }\r