2  * Copyright 2016 ZTE, Inc. and others.
\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 
   8  *     http://www.apache.org/licenses/LICENSE-2.0
\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 
  16 package org.openo.msb.wrapper;
\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 
  28 public class ApiRouteServiceWrapperTest {
\r 
  29     private static ApiRouteServiceWrapper apiRouteServiceWrapper;
\r 
  32     public static void setUpBeforeClass() throws Exception {
\r 
  33         apiRouteServiceWrapper=ApiRouteServiceWrapper.getInstance();
\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 
  45             apiRouteServiceWrapper.saveApiRouteInstance(apiRouteInfo, "");
\r 
  47         catch(ExtendedInternalServerErrorException e){
\r 
  49         catch (Exception e){
\r 
  50             Assert.fail("Exception" + e.getMessage());
\r 
  56     public void tearDown() {        
\r 
  58             apiRouteServiceWrapper.deleteApiRoute("testForJunit", "v1", "*", "");      
\r 
  60         catch(ExtendedInternalServerErrorException e){
\r 
  62         }catch (Exception e) {
\r 
  63             Assert.fail("Exception" + e.getMessage());
\r 
  68     public void testGetAllApiRouteInstances(){
\r 
  70         ApiRouteInfo[] apiRouteInfoList=apiRouteServiceWrapper.getAllApiRouteInstances();
\r 
  71         Assert.assertTrue(apiRouteInfoList.length >= 0);
\r 
  73         catch(ExtendedInternalServerErrorException e){
\r 
  77             Assert.fail("Exception" + e.getMessage());
\r 
  83     public void testGetApiRouteInstance_not_exist(){
\r 
  84         ApiRouteInfo apiRouteInfo = null;
\r 
  86            apiRouteInfo=apiRouteServiceWrapper.getApiRouteInstance("testForJunit", "v2");
\r 
  87            Assert.assertNotNull(apiRouteInfo);
\r 
  89         catch(ExtendedInternalServerErrorException e){
\r 
  92         catch(ExtendedNotFoundException e){
\r 
  93             Assert.assertNull(apiRouteInfo);
\r 
  99     public void testGetApiRouteInstance_exist(){
\r 
 101         ApiRouteInfo apiRouteInfo=apiRouteServiceWrapper.getApiRouteInstance("testForJunit", "v1");
\r 
 102         Assert.assertNotNull(apiRouteInfo);
\r 
 104         catch(ExtendedInternalServerErrorException e){
\r 
 107         catch(Exception e){
\r 
 108             Assert.fail("Exception" + e.getMessage());
\r 
 114     public void testUpdateApiRouteInstance(){
\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 
 124             ApiRouteInfo new_apiRouteInfo= apiRouteServiceWrapper.updateApiRouteInstance("testForJunit", "v1", apiRouteInfo, "");
\r 
 125             Assert.assertEquals("/api/test_update/v1", new_apiRouteInfo.getUrl());
\r 
 127         catch(ExtendedInternalServerErrorException e){
\r 
 130         catch(Exception e){
\r 
 131             Assert.assertEquals("Get Jedis from pool failed!",e.getMessage());
\r 
 133 //            Assert.fail("Exception" + e.getMessage());
\r 
 139     public void testUpdateApiRouteStatus(){
\r 
 141             ApiRouteInfo new_apiRouteInfo= apiRouteServiceWrapper.updateApiRouteStatus("testForJunit", "v1", "0");
\r 
 142             Assert.assertEquals("0",new_apiRouteInfo.getStatus());
\r 
 144         catch(ExtendedInternalServerErrorException e){
\r 
 146         }catch(Exception e){
\r 
 147             Assert.fail("Exception" + e.getMessage());
\r 
 153     public void testGetApiGatewayPort(){
\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