2 * Copyright 2016 ZTE Corporation.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.openo.msb.wrapper;
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.ApiRouteInfo;
24 import org.openo.msb.api.RouteServer;
25 import org.openo.msb.api.exception.ExtendedInternalServerErrorException;
26 import org.openo.msb.api.exception.ExtendedNotFoundException;
28 public class ApiRouteServiceWrapperTest {
29 private static ApiRouteServiceWrapper apiRouteServiceWrapper;
32 public static void setUpBeforeClass() throws Exception {
33 apiRouteServiceWrapper=ApiRouteServiceWrapper.getInstance();
38 ApiRouteInfo apiRouteInfo=new ApiRouteInfo();
39 apiRouteInfo.setServiceName("testForJunit");
40 apiRouteInfo.setVersion("v1");
41 apiRouteInfo.setUrl("/api/test/v1");
42 RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")};
43 apiRouteInfo.setServers(servers);
45 apiRouteServiceWrapper.saveApiRouteInstance(apiRouteInfo, "");
47 catch(ExtendedInternalServerErrorException e){
50 Assert.fail("Exception" + e.getMessage());
56 public void tearDown() {
58 apiRouteServiceWrapper.deleteApiRoute("testForJunit", "v1", "*", "");
60 catch(ExtendedInternalServerErrorException e){
62 }catch (Exception e) {
63 Assert.fail("Exception" + e.getMessage());
68 public void testGetAllApiRouteInstances(){
70 ApiRouteInfo[] apiRouteInfoList=apiRouteServiceWrapper.getAllApiRouteInstances();
71 Assert.assertTrue(apiRouteInfoList.length >= 0);
73 catch(ExtendedInternalServerErrorException e){
77 Assert.fail("Exception" + e.getMessage());
83 public void testGetApiRouteInstance_not_exist(){
84 ApiRouteInfo apiRouteInfo = null;
86 apiRouteInfo=apiRouteServiceWrapper.getApiRouteInstance("testForJunit", "v2");
87 Assert.assertNotNull(apiRouteInfo);
89 catch(ExtendedInternalServerErrorException e){
92 catch(ExtendedNotFoundException e){
93 Assert.assertNull(apiRouteInfo);
99 public void testGetApiRouteInstance_exist(){
101 ApiRouteInfo apiRouteInfo=apiRouteServiceWrapper.getApiRouteInstance("testForJunit", "v1");
102 Assert.assertNotNull(apiRouteInfo);
104 catch(ExtendedInternalServerErrorException e){
108 Assert.fail("Exception" + e.getMessage());
114 public void testUpdateApiRouteInstance(){
117 ApiRouteInfo apiRouteInfo=new ApiRouteInfo();
118 apiRouteInfo.setServiceName("testForJunit");
119 apiRouteInfo.setVersion("v1");
120 apiRouteInfo.setUrl("/api/test_update/v1");
121 RouteServer[] servers=new RouteServer[]{new RouteServer("127.0.0.1","80")};
122 apiRouteInfo.setServers(servers);
124 ApiRouteInfo new_apiRouteInfo= apiRouteServiceWrapper.updateApiRouteInstance("testForJunit", "v1", apiRouteInfo, "");
125 Assert.assertEquals("/api/test_update/v1", new_apiRouteInfo.getUrl());
127 catch(ExtendedInternalServerErrorException e){
131 Assert.assertEquals("Get Jedis from pool failed!",e.getMessage());
133 // Assert.fail("Exception" + e.getMessage());
139 public void testUpdateApiRouteStatus(){
141 ApiRouteInfo new_apiRouteInfo= apiRouteServiceWrapper.updateApiRouteStatus("testForJunit", "v1", "0");
142 Assert.assertEquals("0",new_apiRouteInfo.getStatus());
144 catch(ExtendedInternalServerErrorException e){
147 Assert.fail("Exception" + e.getMessage());
153 public void testGetApiGatewayPort(){
155 String port= apiRouteServiceWrapper.getApiGatewayPort();
156 Assert.assertEquals("10080",port);
158 Assert.fail("Exception" + e.getMessage());