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;
22 import org.junit.Assert;
23 import org.junit.Test;
24 import org.onap.msb.apiroute.wrapper.consulextend.Consul;
25 import org.onap.msb.apiroute.wrapper.consulextend.expose.CheckTagAndAutoStopWatchFilter;
26 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ImmutableService;
27 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ImmutableServiceHealth;
28 import org.onap.msb.apiroute.wrapper.consulextend.model.health.Service;
29 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ServiceHealth;
30 import org.onap.msb.apiroute.wrapper.util.RouteUtil;
32 import com.orbitz.consul.model.ConsulResponse;
33 import com.orbitz.consul.model.health.ImmutableNode;
35 public class CheckTagAndAutoStopWatchFilterTest {
38 public void testfilter() {
40 CheckTagAndAutoStopWatchFilter filter = new CheckTagAndAutoStopWatchFilter("huangleibo");
43 List<ServiceHealth> list = new ArrayList<ServiceHealth>();
45 //visual range:0,tags meet conditions
46 List<String> tags = new ArrayList<String>();
47 tags.add("\"base\":{\"protocol\":\"REST\",\"is_manual\":\"true\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
48 tags.add("\"ns\":{\"namespace\":\"nsName\"}");
49 tags.add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}");
51 Service service0 = ImmutableService.builder().id("huangleibo1").port(0)
52 .address("").service("huangleibo").tags(tags).createIndex(1)
53 .modifyIndex(1).build();
54 ServiceHealth serviceHealth0 = ImmutableServiceHealth.builder()
56 .node(ImmutableNode.builder().node("").address("").build())
59 list.add(serviceHealth0);
60 ConsulResponse<List<ServiceHealth>> object = new ConsulResponse<List<ServiceHealth>>(list,1,true,BigInteger.valueOf(1));
62 //visual range:0,tags meet conditions,return true
63 Assert.assertTrue(filter.filter(object));
65 //visual range:1,tags don't meet conditions
66 List<String> tags1 = new ArrayList<String>();
67 tags1.add("\"base\":{\"protocol\":\"REST\",\"is_manual\":\"true\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
68 tags1.add("\"ns\":{\"namespace\":\"nsName\"}");
69 tags1.add("\"labels\":{\"visualRange\":\"1\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}");
71 Service service1 = ImmutableService.builder().id("huangleibo1").port(0)
72 .address("").service("huangleibo").tags(tags1).createIndex(1)
73 .modifyIndex(1).build();
74 ServiceHealth serviceHealth1 = ImmutableServiceHealth.builder()
76 .node(ImmutableNode.builder().node("").address("").build())
79 list.add(serviceHealth1);
81 //visual range:1,tags don't meet conditions,return false
82 Assert.assertFalse(filter.filter(object));