0ee1e1774b52ff609e7864feda812baf6276758d
[msb/apigateway.git] /
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 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;
31
32 import com.orbitz.consul.model.ConsulResponse;
33 import com.orbitz.consul.model.health.ImmutableNode;
34
35 public class CheckTagAndAutoStopWatchFilterTest {
36
37         @Test
38         public void testfilter() {
39                                 
40                 CheckTagAndAutoStopWatchFilter filter = new CheckTagAndAutoStopWatchFilter("huangleibo");
41                 
42                 
43                 List<ServiceHealth> list = new ArrayList<ServiceHealth>();
44
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\"}");
50                 
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()
55                                 .service(service0)
56                                 .node(ImmutableNode.builder().node("").address("").build())
57                                 .build();
58
59                 list.add(serviceHealth0);
60                 ConsulResponse<List<ServiceHealth>> object = new ConsulResponse<List<ServiceHealth>>(list,1,true,BigInteger.valueOf(1));
61                 
62                 //visual range:0,tags meet conditions,return true
63                 Assert.assertTrue(filter.filter(object));
64                 
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\"}");
70                 
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()
75                                 .service(service1)
76                                 .node(ImmutableNode.builder().node("").address("").build())
77                                 .build();
78                 list.clear();
79                 list.add(serviceHealth1);
80                 
81                 //visual range:1,tags don't meet conditions,return false
82                 Assert.assertFalse(filter.filter(object));
83                 
84         }
85 }