msb protocol synch change
[msb/apigateway.git] / msb-core / apiroute / apiroute-service / src / test / java / org / openo / msb / wrapper / CustomRouteServiceWrapperTest.java
1 /**
2  * Copyright 2016 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.openo.msb.wrapper;
17
18 import org.junit.After;
19 import org.junit.Assert;
20 import org.junit.Before;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23 import org.openo.msb.api.CustomRouteInfo;
24 import org.openo.msb.api.RouteServer;
25 import org.openo.msb.api.exception.ExtendedInternalServerErrorException;
26 import org.openo.msb.api.exception.ExtendedNotFoundException;
27
28 public class CustomRouteServiceWrapperTest {
29
30   private static CustomRouteServiceWrapper customRouteServiceWrapper;
31     
32     @BeforeClass
33     public static void setUpBeforeClass() throws Exception {
34         customRouteServiceWrapper=CustomRouteServiceWrapper.getInstance();
35     }
36     
37     @Before
38     public void setUp() {
39         CustomRouteInfo customRouteInfo=new CustomRouteInfo();
40         customRouteInfo.setServiceName("/testForJunit");
41         customRouteInfo.setUrl("/test");
42         RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")};
43         customRouteInfo.setServers(servers);
44         try {
45             customRouteServiceWrapper.saveCustomRouteInstance(customRouteInfo,"");
46         }
47         catch(ExtendedInternalServerErrorException e){
48         }
49         catch(Exception e){
50             Assert.fail("Exception" + e.getMessage());
51         }
52         
53     }
54     
55     @After
56     public void tearDown() {        
57         try {
58             customRouteServiceWrapper.deleteCustomRoute("/testForJunit", "*","");      
59         } 
60         catch(ExtendedInternalServerErrorException e){
61         }catch (Exception e) {
62             Assert.fail("Exception" + e.getMessage());
63         }
64     }
65     
66     @Test
67     public void testGetAllCustomRouteInstances(){
68         try {
69             CustomRouteInfo[] customRouteInfoList=customRouteServiceWrapper.getAllCustomRouteInstances();
70             Assert.assertTrue(customRouteInfoList.length >= 0);
71         }catch(ExtendedInternalServerErrorException e){
72         }
73         catch(Exception e){
74             Assert.fail("Exception" + e.getMessage());
75         }
76        
77     }
78     
79     @Test
80     public void testGetCustomRouteInstance_not_exist(){
81         CustomRouteInfo customRouteInfo = null;
82         try {
83             customRouteInfo=customRouteServiceWrapper.getCustomRouteInstance("/testForJunit2");
84             Assert.assertNotNull(customRouteInfo);
85         }catch(ExtendedInternalServerErrorException e){
86         }
87         catch(ExtendedNotFoundException e){
88             Assert.assertNull(customRouteInfo);
89         }
90        
91     }
92     
93     @Test
94     public void testGetCustomRouteInstance_exist(){
95         try {
96             CustomRouteInfo customRouteInfo=customRouteServiceWrapper.getCustomRouteInstance("/testForJunit");
97             Assert.assertNotNull(customRouteInfo);
98         }catch(ExtendedInternalServerErrorException e){
99         }
100         catch(Exception e){
101             Assert.fail("Exception" + e.getMessage());
102         }
103        
104     }
105     
106     @Test
107     public void testUpdateCustomRouteInstance(){
108         try {
109             
110             CustomRouteInfo customRouteInfo=new CustomRouteInfo();
111             customRouteInfo.setServiceName("/testForJunit");
112             customRouteInfo.setUrl("/test_update");
113             RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")};
114             customRouteInfo.setServers(servers);
115             
116             CustomRouteInfo new_customRouteInfo= customRouteServiceWrapper.updateCustomRouteInstance("/testForJunit", customRouteInfo,"");
117             Assert.assertEquals("/test_update", new_customRouteInfo.getUrl());
118         }catch(ExtendedInternalServerErrorException e){
119         }
120         catch(Exception e){
121             Assert.fail("Exception" + e.getMessage());
122         
123         }
124     }
125     
126     @Test
127     public void testUpdateCustomRouteStatus(){
128         try { 
129             CustomRouteInfo new_CustomRouteInfo= customRouteServiceWrapper.updateCustomRouteStatus("/testForJunit", "0");
130             Assert.assertEquals("0",new_CustomRouteInfo.getStatus());
131         }catch(ExtendedInternalServerErrorException e){
132         }catch(Exception e){
133             Assert.fail("Exception" + e.getMessage());
134         
135         }
136     }
137 }