/******************************************************************************* * 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 * * 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. ******************************************************************************/ package org.onap.msb.apiroute.wrapper.consulextend.expose; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import org.junit.Assert; import org.junit.Test; import org.onap.msb.apiroute.wrapper.consulextend.expose.ServiceModifyIndexFilter; import org.onap.msb.apiroute.wrapper.consulextend.model.health.ImmutableService; import org.onap.msb.apiroute.wrapper.consulextend.model.health.ImmutableServiceHealth; import org.onap.msb.apiroute.wrapper.consulextend.model.health.Service; import org.onap.msb.apiroute.wrapper.consulextend.model.health.ServiceHealth; 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 list0 = new ArrayList(); //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> object0 = new ConsulResponse>(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 list1 = new ArrayList(); //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> object1 = new ConsulResponse>(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 list2 = new ArrayList(); //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> object2 = new ConsulResponse>(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 list3 = new ArrayList(); //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> object3 = new ConsulResponse>(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)); } }