Divide the MSB source codes into two repos
[msb/apigateway.git] / apiroute / apiroute-service / src / test / java / org / onap / msb / apiroute / wrapper / consulextend / expose / CheckTagAndAutoStopWatchFilterTest.java
1 package org.onap.msb.apiroute.wrapper.consulextend.expose;
2
3 import java.math.BigInteger;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.junit.Assert;
8 import org.junit.Test;
9 import org.onap.msb.apiroute.wrapper.consulextend.Consul;
10 import org.onap.msb.apiroute.wrapper.consulextend.expose.CheckTagAndAutoStopWatchFilter;
11 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ImmutableService;
12 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ImmutableServiceHealth;
13 import org.onap.msb.apiroute.wrapper.consulextend.model.health.Service;
14 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ServiceHealth;
15 import org.onap.msb.apiroute.wrapper.util.RouteUtil;
16
17 import com.orbitz.consul.model.ConsulResponse;
18 import com.orbitz.consul.model.health.ImmutableNode;
19
20 public class CheckTagAndAutoStopWatchFilterTest {
21
22         @Test
23         public void testfilter() {
24                                 
25                 CheckTagAndAutoStopWatchFilter filter = new CheckTagAndAutoStopWatchFilter("huangleibo");
26                 
27                 
28                 List<ServiceHealth> list = new ArrayList<ServiceHealth>();
29
30                 //visual range:0,tags meet conditions
31                 List<String> tags = new ArrayList<String>();
32                 tags.add("\"base\":{\"protocol\":\"REST\",\"is_manual\":\"true\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
33                 tags.add("\"ns\":{\"namespace\":\"nsName\"}");
34                 tags.add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}");
35                 
36                 Service service0 = ImmutableService.builder().id("huangleibo1").port(0)
37                                 .address("").service("huangleibo").tags(tags).createIndex(1)
38                                 .modifyIndex(1).build();
39                 ServiceHealth serviceHealth0 = ImmutableServiceHealth.builder()
40                                 .service(service0)
41                                 .node(ImmutableNode.builder().node("").address("").build())
42                                 .build();
43
44                 list.add(serviceHealth0);
45                 ConsulResponse<List<ServiceHealth>> object = new ConsulResponse<List<ServiceHealth>>(list,1,true,BigInteger.valueOf(1));
46                 
47                 //visual range:0,tags meet conditions,return true
48                 Assert.assertTrue(filter.filter(object));
49                 
50                 //visual range:1,tags don't meet conditions
51                 List<String> tags1 = new ArrayList<String>();
52                 tags1.add("\"base\":{\"protocol\":\"REST\",\"is_manual\":\"true\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}");
53                 tags1.add("\"ns\":{\"namespace\":\"nsName\"}");
54                 tags1.add("\"labels\":{\"visualRange\":\"1\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}");
55                 
56                 Service service1 = ImmutableService.builder().id("huangleibo1").port(0)
57                                 .address("").service("huangleibo").tags(tags1).createIndex(1)
58                                 .modifyIndex(1).build();
59                 ServiceHealth serviceHealth1 = ImmutableServiceHealth.builder()
60                                 .service(service1)
61                                 .node(ImmutableNode.builder().node("").address("").build())
62                                 .build();
63                 list.clear();
64                 list.add(serviceHealth1);
65                 
66                 //visual range:1,tags don't meet conditions,return false
67                 Assert.assertFalse(filter.filter(object));
68                 
69         }
70 }