diff options
Diffstat (limited to 'apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/ServiceModifyIndexFilterTest.java')
-rw-r--r-- | apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/ServiceModifyIndexFilterTest.java | 201 |
1 files changed, 97 insertions, 104 deletions
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/ServiceModifyIndexFilterTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/ServiceModifyIndexFilterTest.java index 77465fb..a44f587 100644 --- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/ServiceModifyIndexFilterTest.java +++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/ServiceModifyIndexFilterTest.java @@ -1,17 +1,15 @@ /******************************************************************************* * Copyright 2016-2017 ZTE, Inc. and others. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. ******************************************************************************/ package org.onap.msb.apiroute.wrapper.consulextend.expose; @@ -31,99 +29,94 @@ import com.orbitz.consul.model.ConsulResponse; import com.orbitz.consul.model.health.ImmutableNode; public class ServiceModifyIndexFilterTest { - - @Test - public void testfilter() - { - ServiceModifyIndexFilter filter = new ServiceModifyIndexFilter(); - - - List<ServiceHealth> list0 = new ArrayList<ServiceHealth>(); - - //id:huangleibo1,name:huangleibo,modifyIndex:1,createIndex:1 - Service service0 = ImmutableService.builder().id("huangleibo1").port(0).address("") - .service("huangleibo").addTags("").createIndex(1).modifyIndex(1).build(); - ServiceHealth serviceHealth0 = ImmutableServiceHealth.builder() - .service(service0) - .node(ImmutableNode.builder().node("").address("").build()) - .build(); - list0.add(serviceHealth0); - - ConsulResponse<List<ServiceHealth>> object0 = new ConsulResponse<List<ServiceHealth>>(list0,1,true,BigInteger.valueOf(1)); - - //list-size:1,id:huangleibo1,name:huangleibo,modifyIndex:1;the first time:return true - Assert.assertTrue(filter.filter(object0)); - - //list-size:1,id:huangleibo1,name:huangleibo,modifyIndex:1;same index:return false - Assert.assertFalse(filter.filter(object0)); - - ///////////////////////////////////////////////////////////////////////////////// - - List<ServiceHealth> list1 = new ArrayList<ServiceHealth>(); - - //id:huangleibo2,name:huangleibo,modifyIndex:1,createIndex:1 - Service service1 = ImmutableService.builder().id("huangleibo2").port(0).address("") - .service("huangleibo").addTags("").createIndex(1).modifyIndex(1).build(); - ServiceHealth serviceHealth1 = ImmutableServiceHealth.builder() - .service(service1) - .node(ImmutableNode.builder().node("").address("").build()) - .build(); - - list1.add(serviceHealth0); - list1.add(serviceHealth1); - - ConsulResponse<List<ServiceHealth>> object1 = new ConsulResponse<List<ServiceHealth>>(list1,1,true,BigInteger.valueOf(1)); - - //list-size:2, - //id:huangleibo1,name:huangleibo,modifyIndex:1,createIndex:1 - //id:huangleibo2,name:huangleibo,modifyIndex:1,createIndex:1 - //size different,return true - Assert.assertTrue(filter.filter(object1)); - - ////////////////////////////////////////////////////////////////////////// - List<ServiceHealth> list2 = new ArrayList<ServiceHealth>(); - - //id:huangleibo3,name:huangleibo,modifyIndex:1,createIndex:1 - ImmutableService service2 = ImmutableService.builder().id("huangleibo3").port(0).address("") - .service("huangleibo").addTags("").createIndex(1).modifyIndex(1).build(); - ServiceHealth serviceHealth2 = ImmutableServiceHealth.builder() - .service(service2) - .node(ImmutableNode.builder().node("").address("").build()) - .build(); - list2.add(serviceHealth0); - list2.add(serviceHealth2); - - ConsulResponse<List<ServiceHealth>> object2 = new ConsulResponse<List<ServiceHealth>>(list2,1,true,BigInteger.valueOf(1)); - - //list-size:2, - //id:huangleibo1,name:huangleibo,modifyIndex:1,createIndex:1 - //id:huangleibo3,name:huangleibo,modifyIndex:1,createIndex:1 - //instance id different,return true - Assert.assertTrue(filter.filter(object2)); - - - ////////////////////////////////////////////////////////////////////////// - List<ServiceHealth> list3 = new ArrayList<ServiceHealth>(); - - //edit modifyindex 1 to 2 - Service service3 = service2.withModifyIndex(2); - ServiceHealth serviceHealth3 = ImmutableServiceHealth.builder() - .service(service3) - .node(ImmutableNode.builder().node("").address("").build()) - .build(); - list3.add(serviceHealth0); - list3.add(serviceHealth3); - - ConsulResponse<List<ServiceHealth>> object3 = new ConsulResponse<List<ServiceHealth>>(list3,1,true,BigInteger.valueOf(1)); - - //list-size:2, - //id:huangleibo1,name:huangleibo,modifyIndex:1,createIndex:1 - //id:huangleibo3,name:huangleibo,modifyIndex:2,createIndex:1 - //modifyIndex different,return true - Assert.assertTrue(filter.filter(object3)); - - //the same content,return false - Assert.assertFalse(filter.filter(object3)); - - } + + @Test + public void testfilter() { + ServiceModifyIndexFilter filter = new ServiceModifyIndexFilter(); + + + List<ServiceHealth> list0 = new ArrayList<ServiceHealth>(); + + // id:huangleibo1,name:huangleibo,modifyIndex:1,createIndex:1 + Service service0 = ImmutableService.builder().id("huangleibo1").port(0).address("").service("huangleibo") + .addTags("").createIndex(1).modifyIndex(1).build(); + ServiceHealth serviceHealth0 = ImmutableServiceHealth.builder().service(service0) + .node(ImmutableNode.builder().node("").address("").build()).build(); + list0.add(serviceHealth0); + + ConsulResponse<List<ServiceHealth>> object0 = + new ConsulResponse<List<ServiceHealth>>(list0, 1, true, BigInteger.valueOf(1)); + + // list-size:1,id:huangleibo1,name:huangleibo,modifyIndex:1;the first time:return true + Assert.assertTrue(filter.filter(object0)); + + // list-size:1,id:huangleibo1,name:huangleibo,modifyIndex:1;same index:return false + Assert.assertFalse(filter.filter(object0)); + + ///////////////////////////////////////////////////////////////////////////////// + + List<ServiceHealth> list1 = new ArrayList<ServiceHealth>(); + + // id:huangleibo2,name:huangleibo,modifyIndex:1,createIndex:1 + Service service1 = ImmutableService.builder().id("huangleibo2").port(0).address("").service("huangleibo") + .addTags("").createIndex(1).modifyIndex(1).build(); + ServiceHealth serviceHealth1 = ImmutableServiceHealth.builder().service(service1) + .node(ImmutableNode.builder().node("").address("").build()).build(); + + list1.add(serviceHealth0); + list1.add(serviceHealth1); + + ConsulResponse<List<ServiceHealth>> object1 = + new ConsulResponse<List<ServiceHealth>>(list1, 1, true, BigInteger.valueOf(1)); + + // list-size:2, + // id:huangleibo1,name:huangleibo,modifyIndex:1,createIndex:1 + // id:huangleibo2,name:huangleibo,modifyIndex:1,createIndex:1 + // size different,return true + Assert.assertTrue(filter.filter(object1)); + + ////////////////////////////////////////////////////////////////////////// + List<ServiceHealth> list2 = new ArrayList<ServiceHealth>(); + + // id:huangleibo3,name:huangleibo,modifyIndex:1,createIndex:1 + ImmutableService service2 = ImmutableService.builder().id("huangleibo3").port(0).address("") + .service("huangleibo").addTags("").createIndex(1).modifyIndex(1).build(); + ServiceHealth serviceHealth2 = ImmutableServiceHealth.builder().service(service2) + .node(ImmutableNode.builder().node("").address("").build()).build(); + list2.add(serviceHealth0); + list2.add(serviceHealth2); + + ConsulResponse<List<ServiceHealth>> object2 = + new ConsulResponse<List<ServiceHealth>>(list2, 1, true, BigInteger.valueOf(1)); + + // list-size:2, + // id:huangleibo1,name:huangleibo,modifyIndex:1,createIndex:1 + // id:huangleibo3,name:huangleibo,modifyIndex:1,createIndex:1 + // instance id different,return true + Assert.assertTrue(filter.filter(object2)); + + + ////////////////////////////////////////////////////////////////////////// + List<ServiceHealth> list3 = new ArrayList<ServiceHealth>(); + + // edit modifyindex 1 to 2 + Service service3 = service2.withModifyIndex(2); + ServiceHealth serviceHealth3 = ImmutableServiceHealth.builder().service(service3) + .node(ImmutableNode.builder().node("").address("").build()).build(); + list3.add(serviceHealth0); + list3.add(serviceHealth3); + + ConsulResponse<List<ServiceHealth>> object3 = + new ConsulResponse<List<ServiceHealth>>(list3, 1, true, BigInteger.valueOf(1)); + + // list-size:2, + // id:huangleibo1,name:huangleibo,modifyIndex:1,createIndex:1 + // id:huangleibo3,name:huangleibo,modifyIndex:2,createIndex:1 + // modifyIndex different,return true + Assert.assertTrue(filter.filter(object3)); + + // the same content,return false + Assert.assertFalse(filter.filter(object3)); + + } } |