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.CustomRouteInfo;
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 CustomRouteServiceWrapperTest {
30 private static CustomRouteServiceWrapper customRouteServiceWrapper;
33 public static void setUpBeforeClass() throws Exception {
34 customRouteServiceWrapper=CustomRouteServiceWrapper.getInstance();
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);
45 customRouteServiceWrapper.saveCustomRouteInstance(customRouteInfo,"");
47 catch(ExtendedInternalServerErrorException e){
50 Assert.fail("Exception" + e.getMessage());
56 public void tearDown() {
58 customRouteServiceWrapper.deleteCustomRoute("/testForJunit", "*","");
60 catch(ExtendedInternalServerErrorException e){
61 }catch (Exception e) {
62 Assert.fail("Exception" + e.getMessage());
67 public void testGetAllCustomRouteInstances(){
69 CustomRouteInfo[] customRouteInfoList=customRouteServiceWrapper.getAllCustomRouteInstances();
70 Assert.assertTrue(customRouteInfoList.length >= 0);
71 }catch(ExtendedInternalServerErrorException e){
74 Assert.fail("Exception" + e.getMessage());
80 public void testGetCustomRouteInstance_not_exist(){
81 CustomRouteInfo customRouteInfo = null;
83 customRouteInfo=customRouteServiceWrapper.getCustomRouteInstance("/testForJunit2");
84 Assert.assertNotNull(customRouteInfo);
85 }catch(ExtendedInternalServerErrorException e){
87 catch(ExtendedNotFoundException e){
88 Assert.assertNull(customRouteInfo);
94 public void testGetCustomRouteInstance_exist(){
96 CustomRouteInfo customRouteInfo=customRouteServiceWrapper.getCustomRouteInstance("/testForJunit");
97 Assert.assertNotNull(customRouteInfo);
98 }catch(ExtendedInternalServerErrorException e){
101 Assert.fail("Exception" + e.getMessage());
107 public void testUpdateCustomRouteInstance(){
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);
116 CustomRouteInfo new_customRouteInfo= customRouteServiceWrapper.updateCustomRouteInstance("/testForJunit", customRouteInfo,"");
117 Assert.assertEquals("/test_update", new_customRouteInfo.getUrl());
118 }catch(ExtendedInternalServerErrorException e){
121 Assert.fail("Exception" + e.getMessage());
127 public void testUpdateCustomRouteStatus(){
129 CustomRouteInfo new_CustomRouteInfo= customRouteServiceWrapper.updateCustomRouteStatus("/testForJunit", "0");
130 Assert.assertEquals("0",new_CustomRouteInfo.getStatus());
131 }catch(ExtendedInternalServerErrorException e){
133 Assert.fail("Exception" + e.getMessage());