fix powermock issue
[msb/apigateway.git] / apiroute / apiroute-service / src / test / java / org / onap / msb / apiroute / wrapper / consulextend / expose / ServiceModifyIndexFilterTest.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.expose.ServiceModifyIndexFilter;
23 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ImmutableService;
24 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ImmutableServiceHealth;
25 import org.onap.msb.apiroute.wrapper.consulextend.model.health.Service;
26 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ServiceHealth;
27
28 import com.orbitz.consul.model.ConsulResponse;
29 import com.orbitz.consul.model.health.ImmutableNode;
30
31 public class ServiceModifyIndexFilterTest {
32
33     @Test
34     public void testfilter() {
35         ServiceModifyIndexFilter filter = new ServiceModifyIndexFilter();
36
37
38         List<ServiceHealth> list0 = new ArrayList<ServiceHealth>();
39
40         // id:huangleibo1,name:huangleibo,modifyIndex:1,createIndex:1
41         Service service0 = ImmutableService.builder().id("huangleibo1").port(0).address("").service("huangleibo")
42                         .addTags("").createIndex(1).modifyIndex(1).build();
43         ServiceHealth serviceHealth0 = ImmutableServiceHealth.builder().service(service0)
44                         .node(ImmutableNode.builder().node("").address("").build()).build();
45         list0.add(serviceHealth0);
46
47         ConsulResponse<List<ServiceHealth>> object0 =
48                         new ConsulResponse<List<ServiceHealth>>(list0, 1, true, BigInteger.valueOf(1));
49
50         // list-size:1,id:huangleibo1,name:huangleibo,modifyIndex:1;the first time:return true
51         Assert.assertTrue(filter.filter(object0));
52
53         // list-size:1,id:huangleibo1,name:huangleibo,modifyIndex:1;same index:return false
54         Assert.assertFalse(filter.filter(object0));
55
56         /////////////////////////////////////////////////////////////////////////////////
57
58         List<ServiceHealth> list1 = new ArrayList<ServiceHealth>();
59
60         // id:huangleibo2,name:huangleibo,modifyIndex:1,createIndex:1
61         Service service1 = ImmutableService.builder().id("huangleibo2").port(0).address("").service("huangleibo")
62                         .addTags("").createIndex(1).modifyIndex(1).build();
63         ServiceHealth serviceHealth1 = ImmutableServiceHealth.builder().service(service1)
64                         .node(ImmutableNode.builder().node("").address("").build()).build();
65
66         list1.add(serviceHealth0);
67         list1.add(serviceHealth1);
68
69         ConsulResponse<List<ServiceHealth>> object1 =
70                         new ConsulResponse<List<ServiceHealth>>(list1, 1, true, BigInteger.valueOf(1));
71
72         // list-size:2,
73         // id:huangleibo1,name:huangleibo,modifyIndex:1,createIndex:1
74         // id:huangleibo2,name:huangleibo,modifyIndex:1,createIndex:1
75         // size different,return true
76         Assert.assertTrue(filter.filter(object1));
77
78         //////////////////////////////////////////////////////////////////////////
79         List<ServiceHealth> list2 = new ArrayList<ServiceHealth>();
80
81         // id:huangleibo3,name:huangleibo,modifyIndex:1,createIndex:1
82         ImmutableService service2 = ImmutableService.builder().id("huangleibo3").port(0).address("")
83                         .service("huangleibo").addTags("").createIndex(1).modifyIndex(1).build();
84         ServiceHealth serviceHealth2 = ImmutableServiceHealth.builder().service(service2)
85                         .node(ImmutableNode.builder().node("").address("").build()).build();
86         list2.add(serviceHealth0);
87         list2.add(serviceHealth2);
88
89         ConsulResponse<List<ServiceHealth>> object2 =
90                         new ConsulResponse<List<ServiceHealth>>(list2, 1, true, BigInteger.valueOf(1));
91
92         // list-size:2,
93         // id:huangleibo1,name:huangleibo,modifyIndex:1,createIndex:1
94         // id:huangleibo3,name:huangleibo,modifyIndex:1,createIndex:1
95         // instance id different,return true
96         Assert.assertTrue(filter.filter(object2));
97
98
99         //////////////////////////////////////////////////////////////////////////
100         List<ServiceHealth> list3 = new ArrayList<ServiceHealth>();
101
102         // edit modifyindex 1 to 2
103         Service service3 = service2.withModifyIndex(2);
104         ServiceHealth serviceHealth3 = ImmutableServiceHealth.builder().service(service3)
105                         .node(ImmutableNode.builder().node("").address("").build()).build();
106         list3.add(serviceHealth0);
107         list3.add(serviceHealth3);
108
109         ConsulResponse<List<ServiceHealth>> object3 =
110                         new ConsulResponse<List<ServiceHealth>>(list3, 1, true, BigInteger.valueOf(1));
111
112         // list-size:2,
113         // id:huangleibo1,name:huangleibo,modifyIndex:1,createIndex:1
114         // id:huangleibo3,name:huangleibo,modifyIndex:2,createIndex:1
115         // modifyIndex different,return true
116         Assert.assertTrue(filter.filter(object3));
117
118         // the same content,return false
119         Assert.assertFalse(filter.filter(object3));
120
121     }
122 }