c132cc1883710e9200a60c8243dca2e6b0584ebf
[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     /*
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 public void test_noticeRouteListener4Add_del_iui() { try { MicroServiceFullInfo
253      * microServiceInfo = buildMicroServiceFullInfo4IUI();
254      * routeInstance.noticeRouteListener4Add(microServiceInfo);
255      * Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "20081",
256      * "ip")); Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/",
257      * "iuitest-ns", "", "domain"));
258      * 
259      * routeInstance.noticeRouteListener4Delete(microServiceInfo);
260      * 
261      * } catch (Exception e) { Assert.fail("throw exception means error occured!" + e.getMessage());
262      * }
263      * 
264      * try { iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "20081", "ip");
265      * Assert.fail("should not process to here."); } catch (Exception e) { Assert.assertTrue(e
266      * instanceof ExtendedNotFoundException); }
267      * 
268      * try { iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "iuitest-ns", "", "domain");
269      * Assert.fail("should not process to here."); } catch (Exception e) { Assert.assertTrue(e
270      * instanceof ExtendedNotFoundException); }
271      * 
272      * }
273      */
274
275     @Test
276     public void test_noticeRouteListener4Add_del_iui_path() {
277         try {
278             MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4IUI_path();
279             routeInstance.noticeRouteListener4Add(microServiceInfo);
280             Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "", "10081", "ip"));
281             Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "", "10082", "ip"));
282             Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "host", "", "domain"));
283
284             routeInstance.noticeRouteListener4Delete(microServiceInfo);
285         } catch (Exception e) {
286             Assert.fail("throw exception means error occured!" + e.getMessage());
287         }
288
289         try {
290             iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "", "10081", "ip");
291             Assert.fail("should not process to here.");
292         } catch (Exception e) {
293             Assert.assertTrue(e instanceof ExtendedNotFoundException);
294         }
295
296         try {
297             iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "", "10082", "ip");
298             Assert.fail("should not process to here.");
299         } catch (Exception e) {
300             Assert.assertTrue(e instanceof ExtendedNotFoundException);
301         }
302
303         try {
304             iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest4Path", "host", "", "domain");
305             Assert.fail("should not process to here.");
306         } catch (Exception e) {
307             Assert.assertTrue(e instanceof ExtendedNotFoundException);
308         }
309
310     }
311
312
313     @Test
314     public void test_noticeRouteListener4Add_del_iui_mutiPort() {
315         try {
316             MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4IUI_path();
317             microServiceInfo.setPath("");
318             microServiceInfo.setHost("");
319
320             routeInstance.noticeRouteListener4Add(microServiceInfo);
321             Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "10081", "ip"));
322             Assert.assertNotNull(iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "10082", "ip"));
323             Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/", "iuitest", "", "domain"));
324
325             routeInstance.noticeRouteListener4Delete(microServiceInfo);
326         } catch (Exception e) {
327             Assert.fail("throw exception means error occured!" + e.getMessage());
328         }
329
330         try {
331             iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "10081", "ip");
332             Assert.fail("should not process to here.");
333         } catch (Exception e) {
334             Assert.assertTrue(e instanceof ExtendedNotFoundException);
335         }
336
337         try {
338             iuiRouteServiceWrapper.getIuiRouteInstance("iuiTest", "", "10082", "ip");
339             Assert.fail("should not process to here.");
340         } catch (Exception e) {
341             Assert.assertTrue(e instanceof ExtendedNotFoundException);
342         }
343
344         try {
345             customRouteServiceWrapper.getCustomRouteInstance("/", "iuitest", "", "domain");
346             Assert.fail("should not process to here.");
347         } catch (Exception e) {
348             Assert.assertTrue(e instanceof ExtendedNotFoundException);
349         }
350
351     }
352
353     /*
354      * @Test public void test_noticeRouteListener4Add_del_http() { try { MicroServiceFullInfo
355      * microServiceInfo = buildMicroServiceFullInfo4HTTP();
356      * routeInstance.noticeRouteListener4Add(microServiceInfo);
357      * Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "",
358      * "20081", "ip"));
359      * Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1",
360      * "httptest-ns", "", "domain"));
361      * 
362      * routeInstance.noticeRouteListener4Delete(microServiceInfo); } catch (Exception e) {
363      * Assert.fail("throw exception means error occured!" + e.getMessage()); }
364      * 
365      * try { customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "20081", "ip");
366      * Assert.fail("should not process to here."); } catch (Exception e) { Assert.assertTrue(e
367      * instanceof ExtendedNotFoundException); }
368      * 
369      * try { customRouteServiceWrapper.getCustomRouteInstance("/httpTest", "httptest-ns", "",
370      * "domain"); Assert.fail("should not process to here."); } catch (Exception e) {
371      * Assert.assertTrue(e instanceof ExtendedNotFoundException); }
372      * 
373      * }
374      */
375
376     @Test
377     public void test_noticeRouteListener4Add_del_http_path() {
378         try {
379             MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4HTTP_path();
380             routeInstance.noticeRouteListener4Add(microServiceInfo);
381             Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "", "10081", "ip"));
382             Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "", "10082", "ip"));
383             Assert.assertNotNull(
384                             customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "host", "", "domain"));
385
386             routeInstance.noticeRouteListener4Delete(microServiceInfo);
387         } catch (Exception e) {
388             Assert.fail("throw exception means error occured!" + e.getMessage());
389         }
390
391         try {
392             customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "", "10081", "ip");
393             Assert.fail("should not process to here.");
394         } catch (Exception e) {
395             Assert.assertTrue(e instanceof ExtendedNotFoundException);
396         }
397
398         try {
399             customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "", "10082", "ip");
400             Assert.fail("should not process to here.");
401         } catch (Exception e) {
402             Assert.assertTrue(e instanceof ExtendedNotFoundException);
403         }
404
405         try {
406             customRouteServiceWrapper.getCustomRouteInstance("/httpTest4Path", "host", "", "domain");
407             Assert.fail("should not process to here.");
408         } catch (Exception e) {
409             Assert.assertTrue(e instanceof ExtendedNotFoundException);
410         }
411
412     }
413
414
415     @Test
416     public void test_noticeRouteListener4Add_del_http_mutiPort() {
417         try {
418             MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4HTTP_path();
419             microServiceInfo.setPath("");
420             microServiceInfo.setHost("");
421
422             routeInstance.noticeRouteListener4Add(microServiceInfo);
423             Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "10081", "ip"));
424             Assert.assertNotNull(customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "10082", "ip"));
425             Assert.assertNotNull(
426                             customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "httptest", "", "domain"));
427
428             routeInstance.noticeRouteListener4Delete(microServiceInfo);
429         } catch (Exception e) {
430             Assert.fail("throw exception means error occured!" + e.getMessage());
431         }
432
433         try {
434             customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "10081", "ip");
435             Assert.fail("should not process to here.");
436         } catch (Exception e) {
437             Assert.assertTrue(e instanceof ExtendedNotFoundException);
438         }
439
440         try {
441             customRouteServiceWrapper.getCustomRouteInstance("/httpTest/v1", "", "10082", "ip");
442             Assert.fail("should not process to here.");
443         } catch (Exception e) {
444             Assert.assertTrue(e instanceof ExtendedNotFoundException);
445         }
446
447         try {
448             customRouteServiceWrapper.getCustomRouteInstance("/httpTest", "httptest", "", "domain");
449             Assert.fail("should not process to here.");
450         } catch (Exception e) {
451             Assert.assertTrue(e instanceof ExtendedNotFoundException);
452         }
453
454     }
455
456
457     @Test
458     public void test_noticeRouteListener4Add_portal() {
459         try {
460             PowerMockito.mockStatic(System.class);
461             PowerMockito.when(System.getenv("SDCLIENT_IP")).thenReturn("127.0.0.1");
462             ApiRouteAppConfig configuration = new ApiRouteAppConfig();
463
464             DiscoverInfo discoverInfo = new DiscoverInfo();
465             discoverInfo.setEnabled(true);
466             discoverInfo.setIp("127.0.0.2");
467             discoverInfo.setPort(10081);
468             configuration.setDiscoverInfo(discoverInfo);
469             ConfigUtil.getInstance().initDiscoverInfo(configuration);
470
471
472             PowerMockito.mockStatic(HttpClientUtil.class);
473             String publishUrl =
474                             "http://127.0.0.1:10081/api/microservices/v1/services/portalTest/version/v1/allpublishaddress?namespace=&visualRange=0";
475             String resultJson =
476                             "[{\"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\"}]";
477             PowerMockito.when(HttpClientUtil.httpGet(publishUrl)).thenReturn(resultJson);
478
479             MicroServiceFullInfo microServiceInfo = buildMicroServiceFullInfo4PORTAL();
480
481             routeInstance.noticeRouteListener4Add(microServiceInfo);
482
483             CustomRouteInfo routeInfo_ip =
484                             customRouteServiceWrapper.getCustomRouteInstance("/portalTest/v1", "", "10088", "ip");
485             RouteServer[] servers_ip = new RouteServer[] {new RouteServer("10.74.148.99", "8080")};
486             Assert.assertArrayEquals(servers_ip, routeInfo_ip.getServers());
487
488             CustomRouteInfo routeInfo_domain =
489                             customRouteServiceWrapper.getCustomRouteInstance("/portalTest/v1", "host", "", "domain");
490             RouteServer[] servers_domain = new RouteServer[] {new RouteServer("10.74.165.246", "443")};
491
492             Assert.assertArrayEquals(servers_domain, routeInfo_domain.getServers());
493
494         } catch (Exception e) {
495             Assert.fail("throw exception means error occured!" + e.getMessage());
496         }
497
498     }
499
500
501     private MicroServiceFullInfo buildMicroServiceFullInfo4API() {
502         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
503         microServiceInfo.setServiceName("apiTest-ns");
504         microServiceInfo.setVersion("v1");
505         microServiceInfo.setEnable_ssl(false);
506         microServiceInfo.setPublish_port("20081");
507         microServiceInfo.setProtocol("REST");
508         microServiceInfo.setUrl("/api/apiTest/v1");
509         microServiceInfo.setVisualRange("1");
510         microServiceInfo.setStatus("1");
511         microServiceInfo.setNamespace("ns");
512         Set<Node> nodes = new HashSet<Node>();
513         nodes.add(new Node("10.74.148.88", "8080"));
514         nodes.add(new Node("10.74.148.89", "8080"));
515         microServiceInfo.setNodes(nodes);
516
517         return microServiceInfo;
518     }
519
520     private MicroServiceFullInfo buildMicroServiceFullInfo4API_path() {
521         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
522         microServiceInfo.setServiceName("apiTest");
523         microServiceInfo.setVersion("v1");
524         microServiceInfo.setEnable_ssl(true);
525         microServiceInfo.setHost("host");
526         microServiceInfo.setPath("/api/apiTest4Path/v1");
527         microServiceInfo.setPublish_port("10081|10082");
528         microServiceInfo.setProtocol("REST");
529         microServiceInfo.setUrl("/api/apiTest/v1");
530         microServiceInfo.setVisualRange("0");
531         microServiceInfo.setLb_policy("ip_hash");
532         microServiceInfo.setStatus("1");
533         Set<Node> nodes = new HashSet<Node>();
534         nodes.add(new Node("10.74.148.88", "8080"));
535         nodes.add(new Node("10.74.148.89", "8080"));
536         microServiceInfo.setNodes(nodes);
537
538         return microServiceInfo;
539     }
540
541
542     private MicroServiceFullInfo buildMicroServiceFullInfo4PORTAL() {
543
544         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
545         microServiceInfo.setServiceName("portalTest");
546         microServiceInfo.setVersion("v1");
547         microServiceInfo.setEnable_ssl(true);
548         microServiceInfo.setHost("host");
549         microServiceInfo.setPublish_port("10088");
550         microServiceInfo.setProtocol("HTTP");
551         microServiceInfo.setUrl("/portalTestUrl/v1");
552         microServiceInfo.setVisualRange("0");
553         microServiceInfo.setLb_policy("ip_hash");
554         microServiceInfo.setStatus("1");
555         microServiceInfo.setCustom(RouteUtil.CUSTOM_PORTAL);
556         Set<Node> nodes = new HashSet<Node>();
557         nodes.add(new Node("10.74.148.99", "8080"));
558         microServiceInfo.setNodes(nodes);
559
560         return microServiceInfo;
561     }
562
563     private MicroServiceFullInfo buildMicroServiceFullInfo4IUI() {
564         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
565         microServiceInfo.setServiceName("iuiTest-ns");
566         microServiceInfo.setNamespace("ns");
567         microServiceInfo.setVersion("v1");
568         microServiceInfo.setEnable_ssl(false);
569         microServiceInfo.setPublish_port("20081");
570         microServiceInfo.setProtocol("UI");
571         microServiceInfo.setUrl("/iui/iuiTest");
572         microServiceInfo.setVisualRange("1");
573         microServiceInfo.setStatus("1");
574         Set<Node> nodes = new HashSet<Node>();
575         nodes.add(new Node("10.74.148.88", "8080"));
576         nodes.add(new Node("10.74.148.89", "8080"));
577         microServiceInfo.setNodes(nodes);
578
579         return microServiceInfo;
580     }
581
582     private MicroServiceFullInfo buildMicroServiceFullInfo4IUI_path() {
583         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
584         microServiceInfo.setServiceName("iuiTest");
585         microServiceInfo.setVersion("v1");
586         microServiceInfo.setEnable_ssl(true);
587         microServiceInfo.setHost("host");
588         microServiceInfo.setProtocol("UI");
589         microServiceInfo.setUrl("/iui/iuiTest");
590         microServiceInfo.setLb_policy("ip_hash");
591         microServiceInfo.setPublish_port("10081|10082");
592         microServiceInfo.setPath("/iui/iuiTest4Path");
593         microServiceInfo.setVisualRange("0");
594         microServiceInfo.setStatus("1");
595         Set<Node> nodes = new HashSet<Node>();
596         nodes.add(new Node("10.74.148.88", "8080"));
597         nodes.add(new Node("10.74.148.89", "8080"));
598         microServiceInfo.setNodes(nodes);
599
600         return microServiceInfo;
601     }
602
603     private MicroServiceFullInfo buildMicroServiceFullInfo4HTTP() {
604         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
605         microServiceInfo.setServiceName("httpTest-ns");
606         microServiceInfo.setNamespace("ns");
607         microServiceInfo.setVersion("v1");
608         microServiceInfo.setEnable_ssl(false);
609         microServiceInfo.setPublish_port("20081");
610         microServiceInfo.setProtocol("HTTP");
611         microServiceInfo.setUrl("/httpTest");
612         microServiceInfo.setVisualRange("1");
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_path() {
623         MicroServiceFullInfo microServiceInfo = new MicroServiceFullInfo();
624         microServiceInfo.setServiceName("httpTest");
625         microServiceInfo.setVersion("v1");
626         microServiceInfo.setEnable_ssl(true);
627         microServiceInfo.setHost("host");
628         microServiceInfo.setPublish_port("20081");
629         microServiceInfo.setProtocol("HTTP");
630         microServiceInfo.setUrl("/httpTest");
631         microServiceInfo.setVisualRange("0");
632         microServiceInfo.setStatus("1");
633         microServiceInfo.setLb_policy("ip_hash");
634         microServiceInfo.setPublish_port("10081|10082");
635         microServiceInfo.setPath("/httpTest4Path");
636         Set<Node> nodes = new HashSet<Node>();
637         nodes.add(new Node("10.74.148.88", "8080"));
638         nodes.add(new Node("10.74.148.89", "8080"));
639         microServiceInfo.setNodes(nodes);
640
641         return microServiceInfo;
642     }
643
644
645 }