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