Add license header for java files
[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");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at 
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 package org.onap.msb.apiroute.wrapper.consulextend.expose;
17
18 import java.math.BigInteger;
19 import java.util.ArrayList;
20 import java.util.List;
21
22
23
24
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.onap.msb.apiroute.wrapper.consulextend.Consul;
28 import org.onap.msb.apiroute.wrapper.consulextend.expose.CheckServiceDataEmptyAndAutoStopWatchFilter;
29 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ImmutableService;
30 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ImmutableServiceHealth;
31 import org.onap.msb.apiroute.wrapper.consulextend.model.health.Service;
32 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ServiceHealth;
33 import org.onap.msb.apiroute.wrapper.util.RouteUtil;
34
35 import com.orbitz.consul.model.ConsulResponse;
36 import com.orbitz.consul.model.health.ImmutableNode;
37
38 public class CheckServiceDataEmptyAndAutoStopWatchFilterTest {
39         @Test
40         public void testfilter()
41         {
42                 
43                 
44                 CheckServiceDataEmptyAndAutoStopWatchFilter filter = new CheckServiceDataEmptyAndAutoStopWatchFilter("huangleibo");
45                 
46                 
47                 List<ServiceHealth> list = new ArrayList<ServiceHealth>();
48                 
49                 //id:huangleibo1,name:huangleibo,modifyIndex:1,createindex:1
50                 Service service0 = ImmutableService.builder().id("huangleibo1").port(0).address("")
51                                 .service("huangleibo").addTags("").createIndex(1).modifyIndex(1).build();
52                 ServiceHealth serviceHealth0 = ImmutableServiceHealth.builder()
53                                 .service(service0)
54                                 .node(ImmutableNode.builder().node("").address("").build())
55                                 .build();
56                 
57                 list.add(serviceHealth0);
58                 ConsulResponse<List<ServiceHealth>> object = new ConsulResponse<List<ServiceHealth>>(list,1,true, BigInteger.valueOf(1));
59                 
60                 //have service,return true
61                 Assert.assertTrue(filter.filter(object));
62                 
63                 //empty [],return false
64                 list.clear();
65                 Assert.assertFalse(filter.filter(object));
66                 
67         }
68 }