fix powermock issue
[msb/apigateway.git] / apiroute / apiroute-service / src / test / java / org / onap / msb / apiroute / wrapper / consulextend / expose / CheckTagAndAutoStopWatchFilterTest.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.CheckTagAndAutoStopWatchFilter;
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 CheckTagAndAutoStopWatchFilterTest {
34
35     @Test
36     public void testfilter() {
37
38         CheckTagAndAutoStopWatchFilter filter = new CheckTagAndAutoStopWatchFilter("huangleibo");
39
40
41         List<ServiceHealth> list = new ArrayList<ServiceHealth>();
42
43         // visual range:0,tags meet conditions
44         List<String> tags = new ArrayList<String>();
45         tags.add("\"base\":{\"protocol\":\"REST\",\"is_manual\":\"true\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
46         tags.add("\"ns\":{\"namespace\":\"nsName\"}");
47         tags.add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}");
48
49         Service service0 = ImmutableService.builder().id("huangleibo1").port(0).address("").service("huangleibo")
50                         .tags(tags).createIndex(1).modifyIndex(1).build();
51         ServiceHealth serviceHealth0 = ImmutableServiceHealth.builder().service(service0)
52                         .node(ImmutableNode.builder().node("").address("").build()).build();
53
54         list.add(serviceHealth0);
55         ConsulResponse<List<ServiceHealth>> object =
56                         new ConsulResponse<List<ServiceHealth>>(list, 1, true, BigInteger.valueOf(1));
57
58         // visual range:0,tags meet conditions,return true
59         Assert.assertTrue(filter.filter(object));
60
61         // visual range:1,tags don't meet conditions
62         List<String> tags1 = new ArrayList<String>();
63         tags1.add("\"base\":{\"protocol\":\"REST\",\"is_manual\":\"true\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
64         tags1.add("\"ns\":{\"namespace\":\"nsName\"}");
65         tags1.add("\"labels\":{\"visualRange\":\"1\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}");
66
67         Service service1 = ImmutableService.builder().id("huangleibo1").port(0).address("").service("huangleibo")
68                         .tags(tags1).createIndex(1).modifyIndex(1).build();
69         ServiceHealth serviceHealth1 = ImmutableServiceHealth.builder().service(service1)
70                         .node(ImmutableNode.builder().node("").address("").build()).build();
71         list.clear();
72         list.add(serviceHealth1);
73
74         // visual range:1,tags don't meet conditions,return false
75         Assert.assertFalse(filter.filter(object));
76
77     }
78 }