c0cf3371389a86f8883249fa88f10df465fe8017
[msb/apigateway.git] / apiroute / apiroute-service / src / test / java / org / onap / msb / apiroute / wrapper / consulextend / expose / CheckServiceDataEmptyAndAutoStopWatchFilterTest.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.consulextend.expose;
15
16 import java.math.BigInteger;
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import org.junit.Assert;
21 import org.junit.Test;
22 import org.onap.msb.apiroute.wrapper.consulextend.Consul;
23 import org.onap.msb.apiroute.wrapper.consulextend.expose.CheckServiceDataEmptyAndAutoStopWatchFilter;
24 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ImmutableService;
25 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ImmutableServiceHealth;
26 import org.onap.msb.apiroute.wrapper.consulextend.model.health.Service;
27 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ServiceHealth;
28 import org.onap.msb.apiroute.wrapper.util.RouteUtil;
29
30 import com.orbitz.consul.model.ConsulResponse;
31 import com.orbitz.consul.model.health.ImmutableNode;
32
33 public class CheckServiceDataEmptyAndAutoStopWatchFilterTest {
34     @Test
35     public void testfilter() {
36
37
38         CheckServiceDataEmptyAndAutoStopWatchFilter filter =
39                         new CheckServiceDataEmptyAndAutoStopWatchFilter("huangleibo");
40
41
42         List<ServiceHealth> list = new ArrayList<ServiceHealth>();
43
44         // id:huangleibo1,name:huangleibo,modifyIndex:1,createindex:1
45         Service service0 = ImmutableService.builder().id("huangleibo1").port(0).address("").service("huangleibo")
46                         .addTags("").createIndex(1).modifyIndex(1).build();
47         ServiceHealth serviceHealth0 = ImmutableServiceHealth.builder().service(service0)
48                         .node(ImmutableNode.builder().node("").address("").build()).build();
49
50         list.add(serviceHealth0);
51         ConsulResponse<List<ServiceHealth>> object =
52                         new ConsulResponse<List<ServiceHealth>>(list, 1, true, BigInteger.valueOf(1));
53
54         // have service,return true
55         Assert.assertTrue(filter.filter(object));
56
57         // empty [],return false
58         list.clear();
59         Assert.assertFalse(filter.filter(object));
60
61     }
62 }