1 /*******************************************************************************
2 * Copyright 2016-2017 ZTE, Inc. and others.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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
13 ******************************************************************************/
14 package org.onap.msb.apiroute.wrapper.consulextend.expose;
16 import java.math.BigInteger;
17 import java.util.ArrayList;
18 import java.util.List;
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 import org.powermock.core.classloader.annotations.PowerMockIgnore;
30 import com.orbitz.consul.model.ConsulResponse;
31 import com.orbitz.consul.model.health.ImmutableNode;
33 public class CheckServiceDataEmptyAndAutoStopWatchFilterTest {
35 public void testfilter() {
38 CheckServiceDataEmptyAndAutoStopWatchFilter filter =
39 new CheckServiceDataEmptyAndAutoStopWatchFilter("huangleibo");
42 List<ServiceHealth> list = new ArrayList<ServiceHealth>();
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();
50 list.add(serviceHealth0);
51 ConsulResponse<List<ServiceHealth>> object =
52 new ConsulResponse<List<ServiceHealth>>(list, 1, true, BigInteger.valueOf(1));
54 // have service,return true
55 Assert.assertTrue(filter.filter(object));
57 // empty [],return false
59 Assert.assertFalse(filter.filter(object));