1 /*******************************************************************************
2 * Copyright 2016-2017 ZTE, Inc. and others.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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;
18 import java.math.BigInteger;
19 import java.util.ArrayList;
20 import java.util.List;
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;
35 import com.orbitz.consul.model.ConsulResponse;
36 import com.orbitz.consul.model.health.ImmutableNode;
38 public class CheckServiceDataEmptyAndAutoStopWatchFilterTest {
40 public void testfilter()
44 CheckServiceDataEmptyAndAutoStopWatchFilter filter = new CheckServiceDataEmptyAndAutoStopWatchFilter("huangleibo");
47 List<ServiceHealth> list = new ArrayList<ServiceHealth>();
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()
54 .node(ImmutableNode.builder().node("").address("").build())
57 list.add(serviceHealth0);
58 ConsulResponse<List<ServiceHealth>> object = new ConsulResponse<List<ServiceHealth>>(list,1,true, BigInteger.valueOf(1));
60 //have service,return true
61 Assert.assertTrue(filter.filter(object));
63 //empty [],return false
65 Assert.assertFalse(filter.filter(object));