fix powermock issue
[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.*", "jdk.internal.reflect.*"})
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     /*
112      * @Test
113      *
114      * public void test_noticeRouteListener4Update_iui() { try {
115      * routeInstance.noticeRouteListener4Update("iuiTest-ns", "v1",
116      * buildMicroServiceFullInfo4IUI()); IuiRouteInfo iuiRouteInfo =
117      * iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest-ns", "host", "20081", "ip");
118      * 
119      * Assert.assertNotNull(iuiRouteInfo); Assert.assertEquals("1", iuiRouteInfo.getStatus());
120      * 
121      * routeInstance.noticeUpdateStatusListener(buildMicroServiceFullInfo4IUI(), "0"); iuiRouteInfo
122      * = iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest-ns", "host", "20081", "ip");
123      * Assert.assertEquals("0", iuiRouteInfo.getStatus());
124      * 
125      * } catch (Exception e) { 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     /*
147      * @Test public void test_noticeRouteListener4Add_del_api() { try { MicroServiceFullInfo
148      * microServiceInfo = buildMicroServiceFullInfo4API();
149      * routeInstance.noticeRouteListener4Add(microServiceInfo);
150      * Assert.assertNotNull(apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "", "20081",
151      * "ip")); Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/",
152      * "apitest-ns", "", "domain"));
153      * 
154      * routeInstance.noticeRouteListener4Delete(microServiceInfo);
155      * 
156      * } catch (Exception e) { Assert.fail("throw exception means error occured!" + e.getMessage());
157      * }
158      * 
159      * try { apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "", "20081", "ip");
160      * Assert.fail("should not process to here."); } catch (Exception e) { Assert.assertTrue(e
161      * instanceof ExtendedNotFoundException); }
162      * 
163      * try { apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "apitest-ns", "",
164      * "domain"); Assert.fail("should not process to here."); } catch (Exception e) {
165      * Assert.assertTrue(e instanceof ExtendedNotFoundException); }
166      * 
167      * 
168      * }
169      */
170
171     @Test
172     public void test_noticeRouteListener4Add_del_api_path() {
173         try {
174             MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4API_path();
175             routeInstance.noticeRouteListener4Add(microServiceInfo);
176             Assert.assertNotNull(apiRouteServiceWrapper.getApiRouteInstance("apiTest4Path", "v1", "", "10081", "ip"));
177             Assert.assertNotNull(apiRouteServiceWrapper.getApiRouteInstance("apiTest4Path", "v1", "", "10082", "ip"));
178             Assert.assertNotNull(
179                             apiRouteServiceWrapper.getApiRouteInstance("apiTest4Path", "v1", "host", "", "domain"));
180
181             routeInstance.noticeRouteListener4Delete(microServiceInfo);
182
183         } catch (Exception e) {
184             Assert.fail("throw exception means error occured!" + e.getMessage());
185         }
186
187         try {
188             apiRouteServiceWrapper.getApiRouteInstance("apiTest4Path", "v1", "", "10081", "ip");
189             Assert.fail("should not process to here.");
190         } catch (Exception e) {
191             Assert.assertTrue(e instanceof ExtendedNotFoundException);
192         }
193
194         try {
195             apiRouteServiceWrapper.getApiRouteInstance("apiTest4Path", "v1", "", "10082", "ip");
196             Assert.fail("should not process to here.");
197         } catch (Exception e) {
198             Assert.assertTrue(e instanceof ExtendedNotFoundException);
199         }
200
201         try {
202             apiRouteServiceWrapper.getApiRouteInstance("apiTest4Path", "v1", "host", "", "domain");
203             Assert.fail("should not process to here.");
204         } catch (Exception e) {
205             Assert.assertTrue(e instanceof ExtendedNotFoundException);
206         }
207
208     }
209
210     @Test
211     public void test_noticeRouteListener4Add_del_api_mutiPort() {
212         try {
213             MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4API_path();
214             microServiceInfo.setPath("");
215             microServiceInfo.setHost("");
216
217             routeInstance.noticeRouteListener4Add(microServiceInfo);
218             Assert.assertNotNull(apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "", "10081", "ip"));
219             Assert.assertNotNull(apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "", "10082", "ip"));
220             Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/", "apitest", "", "domain"));
221
222             routeInstance.noticeRouteListener4Delete(microServiceInfo);
223
224         } catch (Exception e) {
225             Assert.fail("throw exception means error occured!" + e.getMessage());
226         }
227
228         try {
229             apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "", "10081", "ip");
230             Assert.fail("should not process to here.");
231         } catch (Exception e) {
232             Assert.assertTrue(e instanceof ExtendedNotFoundException);
233         }
234
235         try {
236             apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "", "10082", "ip");
237             Assert.fail("should not process to here.");
238         } catch (Exception e) {
239             Assert.assertTrue(e instanceof ExtendedNotFoundException);
240         }
241
242         try {
243             apiRouteServiceWrapper.getApiRouteInstance("apiTest", "v1", "apitest", "", "domain");
244             Assert.fail("should not process to here.");
245         } catch (Exception e) {
246             Assert.assertTrue(e instanceof ExtendedNotFoundException);
247         }
248
249     }
250
251
252     @Test
253     public void test_noticeRouteListener4Add_del_iui() throws Exception {
254
255         MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4IUI();
256         routeInstance.noticeRouteListener4Add(microServiceInfo);
257         iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "20081", "ip");
258         // Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/", "iuitest-ns",
259         // "", "domain"));
260
261         routeInstance.noticeRouteListener4Delete(microServiceInfo);
262
263
264         try {
265             iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "20081", "ip");
266             Assert.fail("should not process to here.");
267         } catch (Exception e) {
268             Assert.assertTrue(e instanceof ExtendedNotFoundException);
269         }
270
271         try {
272             iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "iuitest-ns", "", "domain");
273             Assert.fail("should not process to here.");
274         } catch (Exception e) {
275             Assert.assertTrue(e instanceof ExtendedNotFoundException);
276         }
277
278     }
279
280
281     @Test
282     public void test_noticeRouteListener4Add_del_iui_path() {
283         try {
284             MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4IUI_path();
285             routeInstance.noticeRouteListener4Add(microServiceInfo);
286             Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "", "10081", "ip"));
287             Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "", "10082", "ip"));
288             Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "host", "", "domain"));
289
290             routeInstance.noticeRouteListener4Delete(microServiceInfo);
291         } catch (Exception e) {
292             Assert.fail("throw exception means error occured!" + e.getMessage());
293         }
294
295         try {
296             iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "", "10081", "ip");
297             Assert.fail("should not process to here.");
298         } catch (Exception e) {
299             Assert.assertTrue(e instanceof ExtendedNotFoundException);
300         }
301
302         try {
303             iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "", "10082", "ip");
304             Assert.fail("should not process to here.");
305         } catch (Exception e) {
306             Assert.assertTrue(e instanceof ExtendedNotFoundException);
307         }
308
309         try {
310             iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "host", "", "domain");
311             Assert.fail("should not process to here.");
312         } catch (Exception e) {
313             Assert.assertTrue(e instanceof ExtendedNotFoundException);
314         }
315
316     }
317
318
319     @Test
320     public void test_noticeRouteListener4Add_del_iui_mutiPort() {
321         try {
322             MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4IUI_path();
323             microServiceInfo.setPath("");
324             microServiceInfo.setHost("");
325
326             routeInstance.noticeRouteListener4Add(microServiceInfo);
327             Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "10081", "ip"));
328             Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "10082", "ip"));
329             Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/", "iuitest", "", "domain"));
330
331             routeInstance.noticeRouteListener4Delete(microServiceInfo);
332         } catch (Exception e) {
333             Assert.fail("throw exception means error occured!" + e.getMessage());
334         }
335
336         try {
337             iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "10081", "ip");
338             Assert.fail("should not process to here.");
339         } catch (Exception e) {
340             Assert.assertTrue(e instanceof ExtendedNotFoundException);
341         }
342
343         try {
344             iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "10082", "ip");
345             Assert.fail("should not process to here.");
346         } catch (Exception e) {
347             Assert.assertTrue(e instanceof ExtendedNotFoundException);
348         }
349
350         try {
351             customRouteServiceWrapper.getCustomRouteInstance("/", "iuitest", "", "domain");
352             Assert.fail("should not process to here.");
353         } catch (Exception e) {
354             Assert.assertTrue(e instanceof ExtendedNotFoundException);
355         }
356
357     }
358
359     /*
360      * @Test public void test_noticeRouteListener4Add_del_http() { try { MicroServiceFullInfo
361      * microServiceInfo = buildMicroServiceFullInfo4HTTP();
362      * routeInstance.noticeRouteListener4Add(microServiceInfo);
363      * Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "",
364      * "20081", "ip"));
365      * Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1",
366      * "httptest-ns", "", "domain"));
367      * 
368      * routeInstance.noticeRouteListener4Delete(microServiceInfo); } catch (Exception e) {
369      * Assert.fail("throw exception means error occured!" + e.getMessage()); }
370      * 
371      * try { customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "20081", "ip");
372      * Assert.fail("should not process to here."); } catch (Exception e) { Assert.assertTrue(e
373      * instanceof ExtendedNotFoundException); }
374      * 
375      * try { customRouteServiceWrapper.getCustomRouteInstance("/httpTest", "httptest-ns", "",
376      * "domain"); Assert.fail("should not process to here."); } catch (Exception e) {
377      * Assert.assertTrue(e instanceof ExtendedNotFoundException); }
378      * 
379      * }
380      */
381
382     @Test
383     public void test_noticeRouteListener4Add_del_http_path() {
384         try {
385             MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4HTTP_path();
386             routeInstance.noticeRouteListener4Add(microServiceInfo);
387             Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "", "10081", "ip"));
388             Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "", "10082", "ip"));
389             Assert.assertNotNull(
390                             customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "host", "", "domain"));
391
392             routeInstance.noticeRouteListener4Delete(microServiceInfo);
393         } catch (Exception e) {
394             Assert.fail("throw exception means error occured!" + e.getMessage());
395         }
396
397         try {
398             customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "", "10081", "ip");
399             Assert.fail("should not process to here.");
400         } catch (Exception e) {
401             Assert.assertTrue(e instanceof ExtendedNotFoundException);
402         }
403
404         try {
405             customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "", "10082", "ip");
406             Assert.fail("should not process to here.");
407         } catch (Exception e) {
408             Assert.assertTrue(e instanceof ExtendedNotFoundException);
409         }
410
411         try {
412             customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "host", "", "domain");
413             Assert.fail("should not process to here.");
414         } catch (Exception e) {
415             Assert.assertTrue(e instanceof ExtendedNotFoundException);
416         }
417
418     }
419
420
421     @Test
422     public void test_noticeRouteListener4Add_del_http_mutiPort() {
423         try {
424             MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4HTTP_path();
425             microServiceInfo.setPath("");
426             microServiceInfo.setHost("");
427
428             routeInstance.noticeRouteListener4Add(microServiceInfo);
429             Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "10081", "ip"));
430             Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "10082", "ip"));
431             Assert.assertNotNull(
432                             customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "httptest", "", "domain"));
433
434             routeInstance.noticeRouteListener4Delete(microServiceInfo);
435         } catch (Exception e) {
436             Assert.fail("throw exception means error occured!" + e.getMessage());
437         }
438
439         try {
440             customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "10081", "ip");
441             Assert.fail("should not process to here.");
442         } catch (Exception e) {
443             Assert.assertTrue(e instanceof ExtendedNotFoundException);
444         }
445
446         try {
447             customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "10082", "ip");
448             Assert.fail("should not process to here.");
449         } catch (Exception e) {
450             Assert.assertTrue(e instanceof ExtendedNotFoundException);
451         }
452
453         try {
454             customRouteServiceWrapper.getCustomRouteInstance("/httpTest", "httptest", "", "domain");
455             Assert.fail("should not process to here.");
456         } catch (Exception e) {
457             Assert.assertTrue(e instanceof ExtendedNotFoundException);
458         }
459
460     }
461
462
463     @Test
464     public void test_noticeRouteListener4Add_portal() {
465         try {
466             PowerMockito.mockStatic(System.class);
467             PowerMockito.when(System.getenv("SDCLIENT_IP")).thenReturn("127.0.0.1");
468             ApiRouteAppConfig configuration = new ApiRouteAppConfig();
469
470             DiscoverInfo discoverInfo = new DiscoverInfo();
471             discoverInfo.setEnabled(true);
472             discoverInfo.setIp("127.0.0.2");
473             discoverInfo.setPort(10081);
474             configuration.setDiscoverInfo(discoverInfo);
475             ConfigUtil.getInstance().initDiscoverInfo(configuration);
476
477
478             PowerMockito.mockStatic(HttpClientUtil.class);
479             String publishUrl =
480                             "http://127.0.0.1:10081/api/microservices/v1/services/portalTest/version/v1/allpublishaddress?namespace=&visualRange=0";
481             String resultJson =
482                             "[{\"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\"}]";
483             PowerMockito.when(HttpClientUtil.httpGet(publishUrl)).thenReturn(resultJson);
484
485             MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4PORTAL();
486
487             routeInstance.noticeRouteListener4Add(microServiceInfo);
488
489             CustomRouteInfo routeInfo_ip =
490                             customRouteServiceWrapper.getCustomRouteInstance("/portalTest/v1", "", "10088", "ip");
491             RouteServer[] servers_ip = new RouteServer[] {new RouteServer("10.74.148.99", "8080")};
492             Assert.assertArrayEquals(servers_ip, routeInfo_ip.getServers());
493
494             CustomRouteInfo routeInfo_domain =
495                             customRouteServiceWrapper.getCustomRouteInstance("/portalTest/v1", "host", "", "domain");
496             RouteServer[] servers_domain = new RouteServer[] {new RouteServer("10.74.165.246", "443")};
497
498             Assert.assertArrayEquals(servers_domain, routeInfo_domain.getServers());
499
500         } catch (Exception e) {
501             Assert.fail("throw exception means error occured!" + e.getMessage());
502         }
503
504     }
505
506
507     private MicroServiceFullInfo buildMicroServiceFullInfo4API() {
508         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
509         microServiceInfo.setServiceName("apiTest-ns");
510         microServiceInfo.setVersion("v1");
511         microServiceInfo.setEnable_ssl(false);
512         microServiceInfo.setPublish_port("20081");
513         microServiceInfo.setProtocol("REST");
514         microServiceInfo.setUrl("/api/apiTest/v1");
515         microServiceInfo.setVisualRange("1");
516         microServiceInfo.setStatus("1");
517         microServiceInfo.setNamespace("ns");
518         Set<Node> nodes = new HashSet<Node>();
519         nodes.add(new Node("10.74.148.88", "8080"));
520         nodes.add(new Node("10.74.148.89", "8080"));
521         microServiceInfo.setNodes(nodes);
522
523         return microServiceInfo;
524     }
525
526     private MicroServiceFullInfo buildMicroServiceFullInfo4API_path() {
527         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
528         microServiceInfo.setServiceName("apiTest");
529         microServiceInfo.setVersion("v1");
530         microServiceInfo.setEnable_ssl(true);
531         microServiceInfo.setHost("host");
532         microServiceInfo.setPath("/api/apiTest4Path/v1");
533         microServiceInfo.setPublish_port("10081|10082");
534         microServiceInfo.setProtocol("REST");
535         microServiceInfo.setUrl("/api/apiTest/v1");
536         microServiceInfo.setVisualRange("0");
537         microServiceInfo.setLb_policy("ip_hash");
538         microServiceInfo.setStatus("1");
539         Set<Node> nodes = new HashSet<Node>();
540         nodes.add(new Node("10.74.148.88", "8080"));
541         nodes.add(new Node("10.74.148.89", "8080"));
542         microServiceInfo.setNodes(nodes);
543
544         return microServiceInfo;
545     }
546
547
548     private MicroServiceFullInfo buildMicroServiceFullInfo4PORTAL() {
549
550         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
551         microServiceInfo.setServiceName("portalTest");
552         microServiceInfo.setVersion("v1");
553         microServiceInfo.setEnable_ssl(true);
554         microServiceInfo.setHost("host");
555         microServiceInfo.setPublish_port("10088");
556         microServiceInfo.setProtocol("HTTP");
557         microServiceInfo.setUrl("/portalTestUrl/v1");
558         microServiceInfo.setVisualRange("0");
559         microServiceInfo.setLb_policy("ip_hash");
560         microServiceInfo.setStatus("1");
561         microServiceInfo.setCustom(RouteUtil.CUSTOM_PORTAL);
562         Set<Node> nodes = new HashSet<Node>();
563         nodes.add(new Node("10.74.148.99", "8080"));
564         microServiceInfo.setNodes(nodes);
565
566         return microServiceInfo;
567     }
568
569     private MicroServiceFullInfo buildMicroServiceFullInfo4IUI() {
570         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
571         microServiceInfo.setServiceName("iuiTest");
572         microServiceInfo.setNamespace("ns");
573         microServiceInfo.setVersion("v1");
574         microServiceInfo.setEnable_ssl(false);
575         microServiceInfo.setPublish_port("20081");
576         microServiceInfo.setProtocol("UI");
577         microServiceInfo.setUrl("/iui/iuiTest");
578         microServiceInfo.setVisualRange("1");
579         microServiceInfo.setStatus("1");
580         Set<Node> nodes = new HashSet<Node>();
581         nodes.add(new Node("10.74.148.88", "8080"));
582         nodes.add(new Node("10.74.148.89", "8080"));
583         microServiceInfo.setNodes(nodes);
584
585         return microServiceInfo;
586     }
587
588     private MicroServiceFullInfo buildMicroServiceFullInfo4IUI_path() {
589         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
590         microServiceInfo.setServiceName("iuiTest");
591         microServiceInfo.setVersion("v1");
592         microServiceInfo.setEnable_ssl(true);
593         microServiceInfo.setHost("host");
594         microServiceInfo.setProtocol("UI");
595         microServiceInfo.setUrl("/iui/iuiTest");
596         microServiceInfo.setLb_policy("ip_hash");
597         microServiceInfo.setPublish_port("10081|10082");
598         microServiceInfo.setPath("/iui/iuiTest4Path");
599         microServiceInfo.setVisualRange("0");
600         microServiceInfo.setStatus("1");
601         Set<Node> nodes = new HashSet<Node>();
602         nodes.add(new Node("10.74.148.88", "8080"));
603         nodes.add(new Node("10.74.148.89", "8080"));
604         microServiceInfo.setNodes(nodes);
605
606         return microServiceInfo;
607     }
608
609     private MicroServiceFullInfo buildMicroServiceFullInfo4HTTP() {
610         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
611         microServiceInfo.setServiceName("httpTest-ns");
612         microServiceInfo.setNamespace("ns");
613         microServiceInfo.setVersion("v1");
614         microServiceInfo.setEnable_ssl(false);
615         microServiceInfo.setPublish_port("20081");
616         microServiceInfo.setProtocol("HTTP");
617         microServiceInfo.setUrl("/httpTest");
618         microServiceInfo.setVisualRange("1");
619         microServiceInfo.setStatus("1");
620         Set<Node> nodes = new HashSet<Node>();
621         nodes.add(new Node("10.74.148.88", "8080"));
622         nodes.add(new Node("10.74.148.89", "8080"));
623         microServiceInfo.setNodes(nodes);
624
625         return microServiceInfo;
626     }
627
628     private MicroServiceFullInfo buildMicroServiceFullInfo4HTTP_path() {
629         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
630         microServiceInfo.setServiceName("httpTest");
631         microServiceInfo.setVersion("v1");
632         microServiceInfo.setEnable_ssl(true);
633         microServiceInfo.setHost("host");
634         microServiceInfo.setPublish_port("20081");
635         microServiceInfo.setProtocol("HTTP");
636         microServiceInfo.setUrl("/httpTest");
637         microServiceInfo.setVisualRange("0");
638         microServiceInfo.setStatus("1");
639         microServiceInfo.setLb_policy("ip_hash");
640         microServiceInfo.setPublish_port("10081|10082");
641         microServiceInfo.setPath("/httpTest4Path");
642         Set<Node> nodes = new HashSet<Node>();
643         nodes.add(new Node("10.74.148.88", "8080"));
644         nodes.add(new Node("10.74.148.89", "8080"));
645         microServiceInfo.setNodes(nodes);
646
647         return microServiceInfo;
648     }
649
650
651 }