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