Add license header for java files
[msb/apigateway.git] / apiroute / apiroute-service / src / test / java / org / onap / msb / apiroute / wrapper / serviceListener / MicroServiceChangeListenerTest.java
1 /*******************************************************************************
2  * Copyright 2016-2017 ZTE, Inc. and others.
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.onap.msb.apiroute.wrapper.serviceListener;
17
18 import java.lang.reflect.InvocationHandler;
19 import java.lang.reflect.Method;
20 import java.util.HashSet;
21 import java.util.Set;
22
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.BeforeClass;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.onap.msb.apiroute.ApiRouteAppConfig;
29 import org.onap.msb.apiroute.api.ApiRouteInfo;
30 import org.onap.msb.apiroute.api.CustomRouteInfo;
31 import org.onap.msb.apiroute.api.DiscoverInfo;
32 import org.onap.msb.apiroute.api.IuiRouteInfo;
33 import org.onap.msb.apiroute.api.MicroServiceFullInfo;
34 import org.onap.msb.apiroute.api.Node;
35 import org.onap.msb.apiroute.api.RouteServer;
36 import org.onap.msb.apiroute.api.exception.ExtendedNotFoundException;
37 import org.onap.msb.apiroute.wrapper.ApiRouteServiceWrapper;
38 import org.onap.msb.apiroute.wrapper.CustomRouteServiceWrapper;
39 import org.onap.msb.apiroute.wrapper.InitRouteServiceWrapper;
40 import org.onap.msb.apiroute.wrapper.IuiRouteServiceWrapper;
41 import org.onap.msb.apiroute.wrapper.dao.RedisAccessWrapper;
42 import org.onap.msb.apiroute.wrapper.serviceListener.RouteNotify;
43 import org.onap.msb.apiroute.wrapper.util.ConfigUtil;
44 import org.onap.msb.apiroute.wrapper.util.HttpClientUtil;
45 import org.onap.msb.apiroute.wrapper.util.JedisUtil;
46 import org.onap.msb.apiroute.wrapper.util.RouteUtil;
47 import org.powermock.api.mockito.PowerMockito;
48 import org.powermock.core.classloader.annotations.PowerMockIgnore;
49 import org.powermock.core.classloader.annotations.PrepareForTest;
50 import org.powermock.modules.junit4.PowerMockRunner;
51
52 import redis.clients.jedis.JedisPool;
53 import redis.clients.jedis.JedisPoolConfig;
54
55 import com.fiftyonred.mock_jedis.MockJedisPool;
56
57 @RunWith(PowerMockRunner.class)
58 @PrepareForTest({JedisUtil.class,ConfigUtil.class,HttpClientUtil.class, RedisAccessWrapper.class,})
59 @PowerMockIgnore({"javax.management.*"})
60 public class MicroServiceChangeListenerTest {
61   private static RouteNotify routeInstance;
62   private static ApiRouteServiceWrapper apiRouteServiceWrapper;
63   private static IuiRouteServiceWrapper iuiRouteServiceWrapper;
64   private static CustomRouteServiceWrapper customRouteServiceWrapper;
65
66   
67   @BeforeClass
68   public static void setUpBeforeClass() throws Exception {
69     InitRouteServiceWrapper.getInstance().registerServiceChangeListener();
70     routeInstance=RouteNotify.getInstance();
71     apiRouteServiceWrapper=ApiRouteServiceWrapper.getInstance();
72     iuiRouteServiceWrapper=IuiRouteServiceWrapper.getInstance();
73     customRouteServiceWrapper=CustomRouteServiceWrapper.getInstance();
74
75     PowerMockito.mockStatic(System.class);
76     PowerMockito.when(System.getenv("ROUTE_WAY")).thenReturn("ip|domain");
77     ConfigUtil.getInstance().initRouteWay();
78   }
79   
80   @Before
81   public  void initReidsMock() throws Exception {
82       final JedisPool mockJedisPool = new MockJedisPool(new JedisPoolConfig(), "localhost");
83       PowerMockito.mockStatic(JedisUtil.class);
84       JedisUtil jedisUtil=PowerMockito.mock(JedisUtil.class);
85       PowerMockito.when(jedisUtil.borrowJedisInstance()).thenReturn(mockJedisPool.getResource());
86
87       PowerMockito.replace(PowerMockito.method(RedisAccessWrapper.class, "filterKeys")).with(new InvocationHandler() {
88           @Override
89           public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
90               return mockJedisPool.getResource().keys((String) args[0]);
91           }
92       });
93   }
94   
95   @Test
96   public void test_noticeRouteListener4Update_api(){
97     try {
98       routeInstance.noticeRouteListener4Update("apiTest-ns", "v1", buildMicroServiceFullInfo4API());
99       ApiRouteInfo apiRouteInfo=apiRouteServiceWrapper.getApiRouteInstance("apiTest-ns", "v1", "host", "20081", "ip");
100
101       Assert.assertNotNull(apiRouteInfo);
102       Assert.assertEquals("1", apiRouteInfo.getStatus());
103       
104       routeInstance.noticeUpdateStatusListener(buildMicroServiceFullInfo4API(),"0");
105       apiRouteInfo=apiRouteServiceWrapper.getApiRouteInstance("apiTest-ns", "v1", "host", "20081", "ip");
106       Assert.assertEquals("0", apiRouteInfo.getStatus());
107       
108     } catch (Exception e) {
109       Assert.fail("throw exception means error occured!" + e.getMessage());
110     }
111   }
112   
113   @Test
114   public void test_noticeRouteListener4Update_iui(){
115     try {
116       routeInstance.noticeRouteListener4Update("iuiTest-ns", "v1", buildMicroServiceFullInfo4IUI());
117       IuiRouteInfo iuiRouteInfo=iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest-ns", "host", "20081", "ip");
118       
119       Assert.assertNotNull(iuiRouteInfo);
120       Assert.assertEquals("1", iuiRouteInfo.getStatus());
121       
122       routeInstance.noticeUpdateStatusListener(buildMicroServiceFullInfo4IUI(),"0");
123       iuiRouteInfo=iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest-ns", "host", "20081", "ip");
124       Assert.assertEquals("0", iuiRouteInfo.getStatus());
125       
126     } catch (Exception e) {
127       Assert.fail("throw exception means error occured!" + e.getMessage());
128     }
129   }
130   
131   @Test
132   public void test_noticeRouteListener4Update_http(){
133     try {
134       routeInstance.noticeRouteListener4Update("httpTest-ns", "v1", buildMicroServiceFullInfo4HTTP());
135       CustomRouteInfo customRouteInfo=customRouteServiceWrapper.getCustomRouteInstance("/httpTest-ns", "host", "20081", "ip");
136       Assert.assertNotNull(customRouteInfo);      
137       Assert.assertEquals("1", customRouteInfo.getStatus());
138       
139       routeInstance.noticeUpdateStatusListener(buildMicroServiceFullInfo4HTTP(),"0");
140       customRouteInfo=customRouteServiceWrapper.getCustomRouteInstance("/httpTest-ns", "host", "20081", "ip");
141       Assert.assertEquals("0", customRouteInfo.getStatus());
142     } catch (Exception e) {
143       Assert.fail("throw exception means error occured!" + e.getMessage());
144     }
145   }
146   
147   @Test
148   public void test_noticeRouteListener4Add_del_api(){
149     try {
150       MicroServiceFullInfo microServiceInfo =buildMicroServiceFullInfo4API();
151       routeInstance.noticeRouteListener4Add(microServiceInfo);
152       Assert.assertNotNull(apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "", "20081", "ip"));
153       Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/", "apitest-ns", "", "domain"));
154       
155       routeInstance.noticeRouteListener4Delete(microServiceInfo);
156
157     } catch (Exception e) {
158       Assert.fail("throw exception means error occured!" + e.getMessage());
159     }
160     
161     try {     
162       apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "", "20081", "ip");
163       Assert.fail("should not process to here.");    
164      } 
165      catch(Exception e){
166          Assert.assertTrue(e instanceof ExtendedNotFoundException);
167      }
168     
169     try {     
170       apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "apitest-ns", "", "domain");
171       Assert.fail("should not process to here.");    
172      } 
173      catch(Exception e){
174          Assert.assertTrue(e instanceof ExtendedNotFoundException);
175      }
176
177     
178   }
179   
180   @Test
181   public void test_noticeRouteListener4Add_del_api_path(){
182     try {
183       MicroServiceFullInfo microServiceInfo =buildMicroServiceFullInfo4API_path();
184       routeInstance.noticeRouteListener4Add(microServiceInfo);
185       Assert.assertNotNull(apiRouteServiceWrapper.getApiRouteInstance("apiTest4Path", "v1", "", "10081", "ip"));
186       Assert.assertNotNull(apiRouteServiceWrapper.getApiRouteInstance("apiTest4Path", "v1", "", "10082", "ip"));
187       Assert.assertNotNull(apiRouteServiceWrapper.getApiRouteInstance("apiTest4Path", "v1", "host", "", "domain"));
188       
189       routeInstance.noticeRouteListener4Delete(microServiceInfo);
190       
191     } catch (Exception e) {
192       Assert.fail("throw exception means error occured!" + e.getMessage());
193     }
194     
195      try {     
196        apiRouteServiceWrapper.getApiRouteInstance("apiTest4Path", "v1", "", "10081", "ip");
197        Assert.fail("should not process to here.");    
198       } 
199       catch(Exception e){
200           Assert.assertTrue(e instanceof ExtendedNotFoundException);
201       }
202      
203      try {     
204        apiRouteServiceWrapper.getApiRouteInstance("apiTest4Path", "v1", "", "10082", "ip");
205        Assert.fail("should not process to here.");    
206       } 
207       catch(Exception e){
208           Assert.assertTrue(e instanceof ExtendedNotFoundException);
209       }
210      
211      try {     
212        apiRouteServiceWrapper.getApiRouteInstance("apiTest4Path", "v1", "host", "", "domain");
213        Assert.fail("should not process to here.");    
214       } 
215       catch(Exception e){
216           Assert.assertTrue(e instanceof ExtendedNotFoundException);
217       }
218     
219   }
220   
221   @Test
222   public void test_noticeRouteListener4Add_del_api_mutiPort(){
223     try {
224       MicroServiceFullInfo microServiceInfo =buildMicroServiceFullInfo4API_path();
225       microServiceInfo.setPath("");
226       microServiceInfo.setHost("");
227       
228       routeInstance.noticeRouteListener4Add(microServiceInfo);
229       Assert.assertNotNull(apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "", "10081", "ip"));
230       Assert.assertNotNull(apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "", "10082", "ip"));
231       Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/", "apitest", "", "domain"));
232       
233       routeInstance.noticeRouteListener4Delete(microServiceInfo);
234       
235     } catch (Exception e) {
236       Assert.fail("throw exception means error occured!" + e.getMessage());
237     }
238     
239      try {     
240        apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "", "10081", "ip");
241        Assert.fail("should not process to here.");    
242       } 
243       catch(Exception e){
244           Assert.assertTrue(e instanceof ExtendedNotFoundException);
245       }
246      
247      try {     
248        apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "", "10082", "ip");
249        Assert.fail("should not process to here.");    
250       } 
251       catch(Exception e){
252           Assert.assertTrue(e instanceof ExtendedNotFoundException);
253       }
254      
255      try {     
256        apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "apitest", "", "domain");
257        Assert.fail("should not process to here.");    
258       } 
259       catch(Exception e){
260           Assert.assertTrue(e instanceof ExtendedNotFoundException);
261       }
262     
263   }
264   
265   @Test
266   public void test_noticeRouteListener4Add_del_iui(){
267     try {
268       MicroServiceFullInfo microServiceInfo =buildMicroServiceFullInfo4IUI();
269       routeInstance.noticeRouteListener4Add(microServiceInfo);
270       Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "20081", "ip"));
271       Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/", "iuitest-ns", "", "domain"));
272       
273       routeInstance.noticeRouteListener4Delete(microServiceInfo);
274             
275     } catch (Exception e) {
276       Assert.fail("throw exception means error occured!" + e.getMessage());
277     }
278     
279     try {     
280       iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "20081", "ip");
281       Assert.fail("should not process to here.");    
282      } 
283      catch(Exception e){
284          Assert.assertTrue(e instanceof ExtendedNotFoundException);
285      }
286     
287     try {     
288       iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "iuitest-ns", "", "domain");
289       Assert.fail("should not process to here.");    
290      } 
291      catch(Exception e){
292          Assert.assertTrue(e instanceof ExtendedNotFoundException);
293      }
294     
295   }
296   
297   @Test
298   public void test_noticeRouteListener4Add_del_iui_path(){
299     try {
300       MicroServiceFullInfo microServiceInfo =buildMicroServiceFullInfo4IUI_path();
301       routeInstance.noticeRouteListener4Add(microServiceInfo);
302       Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "", "10081", "ip"));
303       Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "", "10082", "ip"));
304       Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "host", "", "domain"));
305       
306       routeInstance.noticeRouteListener4Delete(microServiceInfo);
307     } catch (Exception e) {
308       Assert.fail("throw exception means error occured!" + e.getMessage());
309     }
310     
311     try {     
312       iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "", "10081", "ip");
313       Assert.fail("should not process to here.");    
314      } 
315      catch(Exception e){
316          Assert.assertTrue(e instanceof ExtendedNotFoundException);
317      }
318     
319     try {     
320       iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "", "10082", "ip");
321       Assert.fail("should not process to here.");    
322      } 
323      catch(Exception e){
324          Assert.assertTrue(e instanceof ExtendedNotFoundException);
325      }
326     
327     try {     
328       iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "host", "", "domain");
329       Assert.fail("should not process to here.");    
330      } 
331      catch(Exception e){
332          Assert.assertTrue(e instanceof ExtendedNotFoundException);
333      }
334     
335   }
336   
337   
338   @Test
339   public void test_noticeRouteListener4Add_del_iui_mutiPort(){
340     try {
341       MicroServiceFullInfo microServiceInfo =buildMicroServiceFullInfo4IUI_path();
342       microServiceInfo.setPath("");
343       microServiceInfo.setHost("");
344       
345       routeInstance.noticeRouteListener4Add(microServiceInfo);
346       Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "10081", "ip"));
347       Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "10082", "ip"));
348       Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/", "iuitest", "", "domain"));
349       
350       routeInstance.noticeRouteListener4Delete(microServiceInfo);
351     } catch (Exception e) {
352       Assert.fail("throw exception means error occured!" + e.getMessage());
353     }
354     
355     try {     
356       iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "10081", "ip");
357       Assert.fail("should not process to here.");    
358      } 
359      catch(Exception e){
360          Assert.assertTrue(e instanceof ExtendedNotFoundException);
361      }
362     
363     try {     
364       iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "10082", "ip");
365       Assert.fail("should not process to here.");    
366      } 
367      catch(Exception e){
368          Assert.assertTrue(e instanceof ExtendedNotFoundException);
369      }
370     
371     try {     
372       customRouteServiceWrapper.getCustomRouteInstance("/", "iuitest", "", "domain");
373       Assert.fail("should not process to here.");    
374      } 
375      catch(Exception e){
376          Assert.assertTrue(e instanceof ExtendedNotFoundException);
377      }
378     
379   }
380   
381   @Test
382   public void test_noticeRouteListener4Add_del_http(){
383     try {
384       MicroServiceFullInfo microServiceInfo=buildMicroServiceFullInfo4HTTP();
385       routeInstance.noticeRouteListener4Add(microServiceInfo);
386       Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "20081", "ip"));
387       Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "httptest-ns", "", "domain"));
388       
389       routeInstance.noticeRouteListener4Delete(microServiceInfo);
390     } catch (Exception e) {
391       Assert.fail("throw exception means error occured!" + e.getMessage());
392     }
393     
394     try {     
395       customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "20081", "ip");
396       Assert.fail("should not process to here.");    
397      } 
398      catch(Exception e){
399          Assert.assertTrue(e instanceof ExtendedNotFoundException);
400      }
401     
402     try {     
403       customRouteServiceWrapper.getCustomRouteInstance("/httpTest", "httptest-ns", "", "domain");
404       Assert.fail("should not process to here.");    
405      } 
406      catch(Exception e){
407          Assert.assertTrue(e instanceof ExtendedNotFoundException);
408      }
409     
410   }
411   
412   @Test
413   public void test_noticeRouteListener4Add_del_http_path(){
414     try {
415       MicroServiceFullInfo microServiceInfo=buildMicroServiceFullInfo4HTTP_path();
416       routeInstance.noticeRouteListener4Add(microServiceInfo);
417       Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "", "10081", "ip"));
418       Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "", "10082", "ip"));
419       Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "host", "", "domain"));
420       
421       routeInstance.noticeRouteListener4Delete(microServiceInfo);
422     } catch (Exception e) {
423       Assert.fail("throw exception means error occured!" + e.getMessage());
424     }
425     
426     try {     
427       customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "", "10081", "ip");
428       Assert.fail("should not process to here.");    
429      } 
430      catch(Exception e){
431          Assert.assertTrue(e instanceof ExtendedNotFoundException);
432      }
433     
434     try {     
435       customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "", "10082", "ip");
436       Assert.fail("should not process to here.");    
437      } 
438      catch(Exception e){
439          Assert.assertTrue(e instanceof ExtendedNotFoundException);
440      }
441     
442     try {     
443       customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "host", "", "domain");
444       Assert.fail("should not process to here.");    
445      } 
446      catch(Exception e){
447          Assert.assertTrue(e instanceof ExtendedNotFoundException);
448      }
449     
450   }
451   
452   
453   @Test
454   public void test_noticeRouteListener4Add_del_http_mutiPort(){
455     try {
456       MicroServiceFullInfo microServiceInfo=buildMicroServiceFullInfo4HTTP_path();
457       microServiceInfo.setPath("");
458       microServiceInfo.setHost("");
459       
460       routeInstance.noticeRouteListener4Add(microServiceInfo);
461       Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "10081", "ip"));
462       Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "10082", "ip"));
463       Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "httptest", "", "domain"));
464       
465       routeInstance.noticeRouteListener4Delete(microServiceInfo);
466     } catch (Exception e) {
467       Assert.fail("throw exception means error occured!" + e.getMessage());
468     }
469     
470     try {     
471       customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "10081", "ip");
472       Assert.fail("should not process to here.");    
473      } 
474      catch(Exception e){
475          Assert.assertTrue(e instanceof ExtendedNotFoundException);
476      }
477     
478     try {     
479       customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "10082", "ip");
480       Assert.fail("should not process to here.");    
481      } 
482      catch(Exception e){
483          Assert.assertTrue(e instanceof ExtendedNotFoundException);
484      }
485     
486     try {     
487       customRouteServiceWrapper.getCustomRouteInstance("/httpTest", "httptest", "", "domain");
488       Assert.fail("should not process to here.");    
489      } 
490      catch(Exception e){
491          Assert.assertTrue(e instanceof ExtendedNotFoundException);
492      }
493     
494   }
495
496   
497   @Test
498   public void test_noticeRouteListener4Add_portal(){
499     try {
500       PowerMockito.mockStatic(System.class);
501       PowerMockito.when(System.getenv("SDCLIENT_IP")).thenReturn("127.0.0.1");
502       ApiRouteAppConfig configuration=new ApiRouteAppConfig();
503       
504       DiscoverInfo discoverInfo=new DiscoverInfo();
505       discoverInfo.setEnabled(true);
506       discoverInfo.setIp("127.0.0.2");
507       discoverInfo.setPort(10081);    
508       configuration.setDiscoverInfo(discoverInfo);
509       ConfigUtil.getInstance().initDiscoverInfo(configuration);
510       
511       
512       PowerMockito.mockStatic(HttpClientUtil.class);
513       String publishUrl="http://127.0.0.1:10081/api/microservices/v1/services/portalTest/version/v1/allpublishaddress?namespace=&visualRange=0";
514       String resultJson ="[{\"domain\":\"opapi.openpalette.zte.com.cn\",\"port\":\"443\",\"publish_url\":\"/api\",\"visualRange\":\"0\",\"publish_protocol\":\"https\"},{\"ip\":\"10.74.165.246\",\"port\":\"443\",\"publish_url\":\"/opapi\",\"visualRange\":\"0\",\"publish_protocol\":\"https\"},{\"ip\":\"10.74.165.246\",\"port\":\"80\",\"publish_url\":\"/opapi\",\"visualRange\":\"0\",\"publish_protocol\":\"http\"}]";
515       PowerMockito.when(HttpClientUtil.httpGet(publishUrl)).thenReturn(resultJson);
516       
517       MicroServiceFullInfo microServiceInfo=buildMicroServiceFullInfo4PORTAL();
518       
519       routeInstance.noticeRouteListener4Add(microServiceInfo);
520       
521       CustomRouteInfo routeInfo_ip=customRouteServiceWrapper.getCustomRouteInstance("/portalTest/v1", "", "10088", "ip");
522        RouteServer[] servers_ip = new RouteServer[]{new RouteServer("10.74.148.99","8080")};   
523        Assert.assertArrayEquals(servers_ip, routeInfo_ip.getServers());
524       
525        CustomRouteInfo routeInfo_domain=customRouteServiceWrapper.getCustomRouteInstance("/portalTest/v1", "host", "", "domain");
526        RouteServer[] servers_domain = new RouteServer[]{new RouteServer("10.74.165.246","443")};   
527
528        Assert.assertArrayEquals(servers_domain, routeInfo_domain.getServers());
529       
530     } catch (Exception e) {
531       Assert.fail("throw exception means error occured!" + e.getMessage());
532     }
533     
534   }
535   
536   
537   private MicroServiceFullInfo buildMicroServiceFullInfo4API(){
538     MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
539     microServiceInfo.setServiceName("apiTest-ns");
540     microServiceInfo.setVersion("v1");
541     microServiceInfo.setEnable_ssl(false);
542     microServiceInfo.setPublish_port("20081");
543     microServiceInfo.setProtocol("REST");
544     microServiceInfo.setUrl("/api/apiTest/v1");
545     microServiceInfo.setVisualRange("1");
546     microServiceInfo.setStatus("1");
547     microServiceInfo.setNamespace("ns");
548     Set<Node> nodes = new HashSet<Node>();
549     nodes.add(new Node("10.74.148.88","8080"));
550     nodes.add(new Node("10.74.148.89","8080"));
551     microServiceInfo.setNodes(nodes);
552     
553     return microServiceInfo;
554   }
555   
556   private MicroServiceFullInfo buildMicroServiceFullInfo4API_path(){
557     MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
558     microServiceInfo.setServiceName("apiTest");
559     microServiceInfo.setVersion("v1");
560     microServiceInfo.setEnable_ssl(true);
561     microServiceInfo.setHost("host");
562     microServiceInfo.setPath("/api/apiTest4Path/v1");
563     microServiceInfo.setPublish_port("10081|10082");
564     microServiceInfo.setProtocol("REST");
565     microServiceInfo.setUrl("/api/apiTest/v1");
566     microServiceInfo.setVisualRange("0");
567     microServiceInfo.setLb_policy("ip_hash");
568     microServiceInfo.setStatus("1");
569     Set<Node> nodes = new HashSet<Node>();
570     nodes.add(new Node("10.74.148.88","8080"));
571     nodes.add(new Node("10.74.148.89","8080"));
572     microServiceInfo.setNodes(nodes);
573     
574     return microServiceInfo;
575   }
576   
577   
578   private MicroServiceFullInfo buildMicroServiceFullInfo4PORTAL(){
579     
580     MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
581     microServiceInfo.setServiceName("portalTest");
582     microServiceInfo.setVersion("v1");
583     microServiceInfo.setEnable_ssl(true);
584     microServiceInfo.setHost("host");
585     microServiceInfo.setPublish_port("10088");
586     microServiceInfo.setProtocol("HTTP");
587     microServiceInfo.setUrl("/portalTestUrl/v1");
588     microServiceInfo.setVisualRange("0");
589     microServiceInfo.setLb_policy("ip_hash");
590     microServiceInfo.setStatus("1");
591     microServiceInfo.setCustom(RouteUtil.CUSTOM_PORTAL);
592     Set<Node> nodes = new HashSet<Node>();
593     nodes.add(new Node("10.74.148.99","8080"));
594     microServiceInfo.setNodes(nodes);
595     
596     return microServiceInfo;
597   }
598   
599   private MicroServiceFullInfo buildMicroServiceFullInfo4IUI(){
600     MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
601     microServiceInfo.setServiceName("iuiTest-ns");
602     microServiceInfo.setNamespace("ns");
603     microServiceInfo.setVersion("v1");
604     microServiceInfo.setEnable_ssl(false);
605     microServiceInfo.setPublish_port("20081");
606     microServiceInfo.setProtocol("UI");
607     microServiceInfo.setUrl("/iui/iuiTest");
608     microServiceInfo.setVisualRange("1");
609     microServiceInfo.setStatus("1");
610     Set<Node> nodes = new HashSet<Node>();
611     nodes.add(new Node("10.74.148.88","8080"));
612     nodes.add(new Node("10.74.148.89","8080"));
613     microServiceInfo.setNodes(nodes);
614     
615     return microServiceInfo;
616   }
617   
618   private MicroServiceFullInfo buildMicroServiceFullInfo4IUI_path(){
619     MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
620     microServiceInfo.setServiceName("iuiTest");
621     microServiceInfo.setVersion("v1");
622     microServiceInfo.setEnable_ssl(true);
623     microServiceInfo.setHost("host");
624     microServiceInfo.setProtocol("UI");
625     microServiceInfo.setUrl("/iui/iuiTest");
626     microServiceInfo.setLb_policy("ip_hash");
627     microServiceInfo.setPublish_port("10081|10082");
628     microServiceInfo.setPath("/iui/iuiTest4Path");
629     microServiceInfo.setVisualRange("0");
630     microServiceInfo.setStatus("1");
631     Set<Node> nodes = new HashSet<Node>();
632     nodes.add(new Node("10.74.148.88","8080"));
633     nodes.add(new Node("10.74.148.89","8080"));
634     microServiceInfo.setNodes(nodes);
635     
636     return microServiceInfo;
637   }
638   
639   private MicroServiceFullInfo buildMicroServiceFullInfo4HTTP(){
640     MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
641     microServiceInfo.setServiceName("httpTest-ns");
642     microServiceInfo.setNamespace("ns");
643     microServiceInfo.setVersion("v1");
644     microServiceInfo.setEnable_ssl(false);
645     microServiceInfo.setPublish_port("20081");
646     microServiceInfo.setProtocol("HTTP");
647     microServiceInfo.setUrl("/httpTest");
648     microServiceInfo.setVisualRange("1");
649     microServiceInfo.setStatus("1");
650     Set<Node> nodes = new HashSet<Node>();
651     nodes.add(new Node("10.74.148.88","8080"));
652     nodes.add(new Node("10.74.148.89","8080"));
653     microServiceInfo.setNodes(nodes);
654     
655     return microServiceInfo;
656   }
657   
658   private MicroServiceFullInfo buildMicroServiceFullInfo4HTTP_path(){
659     MicroServiceFullInfo microServiceInfo=new MicroServiceFullInfo();
660     microServiceInfo.setServiceName("httpTest");
661     microServiceInfo.setVersion("v1");
662     microServiceInfo.setEnable_ssl(true);
663     microServiceInfo.setHost("host");
664     microServiceInfo.setPublish_port("20081");
665     microServiceInfo.setProtocol("HTTP");
666     microServiceInfo.setUrl("/httpTest");
667     microServiceInfo.setVisualRange("0");
668     microServiceInfo.setStatus("1");
669     microServiceInfo.setLb_policy("ip_hash");
670     microServiceInfo.setPublish_port("10081|10082");
671     microServiceInfo.setPath("/httpTest4Path");
672     Set<Node> nodes = new HashSet<Node>();
673     nodes.add(new Node("10.74.148.88","8080"));
674     nodes.add(new Node("10.74.148.89","8080"));
675     microServiceInfo.setNodes(nodes);
676     
677     return microServiceInfo;
678   }
679   
680   
681 }