diff options
author | HuabingZhao <zhao.huabing@zte.com.cn> | 2017-09-07 14:33:18 +0800 |
---|---|---|
committer | HuabingZhao <zhao.huabing@zte.com.cn> | 2017-09-07 14:40:59 +0800 |
commit | e75a8ef2372722c0b22669fb427d47bacc5b8d5e (patch) | |
tree | cee85cbc4fe818262fb8c4d733f2fac0c8024df8 /apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose | |
parent | e5fe5a022f4cc5164c1f4516c024617c49f12978 (diff) |
Fix java check style warning
Change-Id: I98a6d7237a213d007ad4d954989cb0b0fa150a10
Issue-Id: MSB-67
Signed-off-by: HuabingZhao <zhao.huabing@zte.com.cn>
Diffstat (limited to 'apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose')
7 files changed, 449 insertions, 508 deletions
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/CheckServiceDataEmptyAndAutoStopWatchFilterTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/CheckServiceDataEmptyAndAutoStopWatchFilterTest.java index 3daa261..c0cf337 100644 --- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/CheckServiceDataEmptyAndAutoStopWatchFilterTest.java +++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/CheckServiceDataEmptyAndAutoStopWatchFilterTest.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; @@ -19,9 +17,6 @@ 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.Consul; @@ -36,33 +31,32 @@ import com.orbitz.consul.model.ConsulResponse; import com.orbitz.consul.model.health.ImmutableNode; public class CheckServiceDataEmptyAndAutoStopWatchFilterTest { - @Test - public void testfilter() - { - - - CheckServiceDataEmptyAndAutoStopWatchFilter filter = new CheckServiceDataEmptyAndAutoStopWatchFilter("huangleibo"); - - - List<ServiceHealth> list = 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(); - - list.add(serviceHealth0); - ConsulResponse<List<ServiceHealth>> object = new ConsulResponse<List<ServiceHealth>>(list,1,true, BigInteger.valueOf(1)); - - //have service,return true - Assert.assertTrue(filter.filter(object)); - - //empty [],return false - list.clear(); - Assert.assertFalse(filter.filter(object)); - - } + @Test + public void testfilter() { + + + CheckServiceDataEmptyAndAutoStopWatchFilter filter = + new CheckServiceDataEmptyAndAutoStopWatchFilter("huangleibo"); + + + List<ServiceHealth> list = 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(); + + list.add(serviceHealth0); + ConsulResponse<List<ServiceHealth>> object = + new ConsulResponse<List<ServiceHealth>>(list, 1, true, BigInteger.valueOf(1)); + + // have service,return true + Assert.assertTrue(filter.filter(object)); + + // empty [],return false + list.clear(); + Assert.assertFalse(filter.filter(object)); + + } } diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/CheckTagAndAutoStopWatchFilterTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/CheckTagAndAutoStopWatchFilterTest.java index 0ee1e17..68f2fcf 100644 --- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/CheckTagAndAutoStopWatchFilterTest.java +++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/CheckTagAndAutoStopWatchFilterTest.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; @@ -34,52 +32,47 @@ import com.orbitz.consul.model.health.ImmutableNode; public class CheckTagAndAutoStopWatchFilterTest { - @Test - public void testfilter() { - - CheckTagAndAutoStopWatchFilter filter = new CheckTagAndAutoStopWatchFilter("huangleibo"); - - - List<ServiceHealth> list = new ArrayList<ServiceHealth>(); - - //visual range:0,tags meet conditions - List<String> tags = new ArrayList<String>(); - tags.add("\"base\":{\"protocol\":\"REST\",\"is_manual\":\"true\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}"); - tags.add("\"ns\":{\"namespace\":\"nsName\"}"); - tags.add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}"); - - Service service0 = ImmutableService.builder().id("huangleibo1").port(0) - .address("").service("huangleibo").tags(tags).createIndex(1) - .modifyIndex(1).build(); - ServiceHealth serviceHealth0 = ImmutableServiceHealth.builder() - .service(service0) - .node(ImmutableNode.builder().node("").address("").build()) - .build(); - - list.add(serviceHealth0); - ConsulResponse<List<ServiceHealth>> object = new ConsulResponse<List<ServiceHealth>>(list,1,true,BigInteger.valueOf(1)); - - //visual range:0,tags meet conditions,return true - Assert.assertTrue(filter.filter(object)); - - //visual range:1,tags don't meet conditions - List<String> tags1 = new ArrayList<String>(); - tags1.add("\"base\":{\"protocol\":\"REST\",\"is_manual\":\"true\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}"); - tags1.add("\"ns\":{\"namespace\":\"nsName\"}"); - tags1.add("\"labels\":{\"visualRange\":\"1\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}"); - - Service service1 = ImmutableService.builder().id("huangleibo1").port(0) - .address("").service("huangleibo").tags(tags1).createIndex(1) - .modifyIndex(1).build(); - ServiceHealth serviceHealth1 = ImmutableServiceHealth.builder() - .service(service1) - .node(ImmutableNode.builder().node("").address("").build()) - .build(); - list.clear(); - list.add(serviceHealth1); - - //visual range:1,tags don't meet conditions,return false - Assert.assertFalse(filter.filter(object)); - - } + @Test + public void testfilter() { + + CheckTagAndAutoStopWatchFilter filter = new CheckTagAndAutoStopWatchFilter("huangleibo"); + + + List<ServiceHealth> list = new ArrayList<ServiceHealth>(); + + // visual range:0,tags meet conditions + List<String> tags = new ArrayList<String>(); + tags.add("\"base\":{\"protocol\":\"REST\",\"is_manual\":\"true\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}"); + tags.add("\"ns\":{\"namespace\":\"nsName\"}"); + tags.add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}"); + + Service service0 = ImmutableService.builder().id("huangleibo1").port(0).address("").service("huangleibo") + .tags(tags).createIndex(1).modifyIndex(1).build(); + ServiceHealth serviceHealth0 = ImmutableServiceHealth.builder().service(service0) + .node(ImmutableNode.builder().node("").address("").build()).build(); + + list.add(serviceHealth0); + ConsulResponse<List<ServiceHealth>> object = + new ConsulResponse<List<ServiceHealth>>(list, 1, true, BigInteger.valueOf(1)); + + // visual range:0,tags meet conditions,return true + Assert.assertTrue(filter.filter(object)); + + // visual range:1,tags don't meet conditions + List<String> tags1 = new ArrayList<String>(); + tags1.add("\"base\":{\"protocol\":\"REST\",\"is_manual\":\"true\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}"); + tags1.add("\"ns\":{\"namespace\":\"nsName\"}"); + tags1.add("\"labels\":{\"visualRange\":\"1\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}"); + + Service service1 = ImmutableService.builder().id("huangleibo1").port(0).address("").service("huangleibo") + .tags(tags1).createIndex(1).modifyIndex(1).build(); + ServiceHealth serviceHealth1 = ImmutableServiceHealth.builder().service(service1) + .node(ImmutableNode.builder().node("").address("").build()).build(); + list.clear(); + list.add(serviceHealth1); + + // visual range:1,tags don't meet conditions,return false + Assert.assertFalse(filter.filter(object)); + + } } diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/ConsulIndexFilterTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/ConsulIndexFilterTest.java index a461fb9..2225eb2 100644 --- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/ConsulIndexFilterTest.java +++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/ConsulIndexFilterTest.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; @@ -20,38 +18,38 @@ import java.math.BigInteger; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.msb.apiroute.wrapper.consulextend.expose.ConsulIndexFilter; import com.orbitz.consul.model.ConsulResponse; public class ConsulIndexFilterTest { - @BeforeClass + @BeforeClass public static void setUpBeforeClass() throws Exception { } - - @Test - public void testfilter() - { - ConsulIndexFilter<Integer> filter = new ConsulIndexFilter<Integer>(); - - int response = 1; - long lastContact= 1; - boolean knownLeader = true; - - ConsulResponse<Integer> object = new ConsulResponse<Integer>(response,lastContact,knownLeader,BigInteger.valueOf(1)); - - //index 1;the first time,return true - Assert.assertTrue(filter.filter(object)); - - - //index 1;same index,return false - Assert.assertFalse(filter.filter(object)); - - ConsulResponse<Integer> object1 = new ConsulResponse<Integer>(response,lastContact,knownLeader,BigInteger.valueOf(2)); - - //index 2;different index,return true - Assert.assertTrue(filter.filter(object1)); - - } + + @Test + public void testfilter() { + ConsulIndexFilter<Integer> filter = new ConsulIndexFilter<Integer>(); + + int response = 1; + long lastContact = 1; + boolean knownLeader = true; + + ConsulResponse<Integer> object = + new ConsulResponse<Integer>(response, lastContact, knownLeader, BigInteger.valueOf(1)); + + // index 1;the first time,return true + Assert.assertTrue(filter.filter(object)); + + + // index 1;same index,return false + Assert.assertFalse(filter.filter(object)); + + ConsulResponse<Integer> object1 = + new ConsulResponse<Integer>(response, lastContact, knownLeader, BigInteger.valueOf(2)); + + // index 2;different index,return true + Assert.assertTrue(filter.filter(object1)); + + } } 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)); + + } } diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WatchCatalogServicesTaskTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WatchCatalogServicesTaskTest.java index 50e2023..548639e 100644 --- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WatchCatalogServicesTaskTest.java +++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WatchCatalogServicesTaskTest.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; @@ -30,8 +28,6 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.onap.msb.apiroute.wrapper.consulextend.Consul; import org.onap.msb.apiroute.wrapper.consulextend.async.ConsulResponseCallback; -import org.onap.msb.apiroute.wrapper.consulextend.expose.WatchCatalogServicesTask; -import org.onap.msb.apiroute.wrapper.consulextend.expose.WatchTask; import org.onap.msb.apiroute.wrapper.consulextend.expose.WatchTask.Filter; import org.onap.msb.apiroute.wrapper.consulextend.util.Http; import org.powermock.api.mockito.PowerMockito; @@ -47,107 +43,95 @@ import com.orbitz.consul.option.CatalogOptions; import com.orbitz.consul.option.QueryOptions; @RunWith(PowerMockRunner.class) -@PrepareForTest({ Http.class }) -@PowerMockIgnore({ "javax.net.ssl.*" }) +@PrepareForTest({Http.class}) +@PowerMockIgnore({"javax.net.ssl.*"}) public class WatchCatalogServicesTaskTest { - private static final Logger LOGGER = LoggerFactory - .getLogger(WatchCatalogServicesTaskTest.class); - - private Consul consul; - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Before - public void init() { - - Map<String, List<String>> catalogservices = new HashMap<String, List<String>>(); - String servicename = "huangleibo"; - List<String> tags = new ArrayList<String>(); - tags.add("1111"); - tags.add("2222"); - catalogservices.put(servicename, tags); - - long lastContact = 1; - boolean knownLeader = true; - BigInteger index = BigInteger.valueOf(1); - final ConsulResponse<Map<String, List<String>>> response = new ConsulResponse<Map<String, List<String>>>( - catalogservices, lastContact, knownLeader, index); - - // - Http http = PowerMockito.mock(Http.class); - - PowerMockito - .doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocation) - throws Throwable { - Object[] args = invocation.getArguments(); - ((ConsulResponseCallback) args[2]).onComplete(response); - return null; - } - }) - .when(http) - .asyncGet(Mockito.anyString(), - Mockito.any(TypeReference.class), - Mockito.any(ConsulResponseCallback.class)); - - // - PowerMockito.spy(Http.class); - PowerMockito.when(Http.getInstance()).thenReturn(http); - - consul = Consul.newClient(); - - WatchCatalogServicesTask task0 = new WatchCatalogServicesTask( - consul.catalogClient(), CatalogOptions.BLANK, - QueryOptions.BLANK, 10); - - WatchCatalogServicesTask task1 = new WatchCatalogServicesTask( - consul.catalogClient(), 10); - - WatchCatalogServicesTask task2 = new WatchCatalogServicesTask( - consul.catalogClient()); - - } - - public class StopHandler implements WatchTask.Handler<HttpEntity> - { - - private WatchCatalogServicesTask task; - - StopHandler(WatchCatalogServicesTask task) - { - this.task = task; - } - - @Override - public void handle(ConsulResponse<HttpEntity> object) { - // TODO Auto-generated method stub -// Map<String, List<String>> map = (Map<String, List<String>>)object.getResponse(); - LOGGER.debug("handler is here"); - task.stopWatch(); - } - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Test - public void teststartWatch() { - WatchCatalogServicesTask task0 = new WatchCatalogServicesTask( - consul.catalogClient(), CatalogOptions.BLANK, - QueryOptions.BLANK, 10); - - task0.addFilter(new Filter() { - @Override - public boolean filter(ConsulResponse object) { - // TODO Auto-generated method stub -// Map<String, List<String>> map = (Map<String, List<String>>)object.getResponse(); - LOGGER.debug("filter is here"); - return true; - } - - }); - - task0.addHandler(new StopHandler(task0)); - - task0.startWatch(); - } - + private static final Logger LOGGER = LoggerFactory.getLogger(WatchCatalogServicesTaskTest.class); + + private Consul consul; + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Before + public void init() { + + Map<String, List<String>> catalogservices = new HashMap<String, List<String>>(); + String servicename = "huangleibo"; + List<String> tags = new ArrayList<String>(); + tags.add("1111"); + tags.add("2222"); + catalogservices.put(servicename, tags); + + long lastContact = 1; + boolean knownLeader = true; + BigInteger index = BigInteger.valueOf(1); + final ConsulResponse<Map<String, List<String>>> response = + new ConsulResponse<Map<String, List<String>>>(catalogservices, lastContact, knownLeader, index); + + // + Http http = PowerMockito.mock(Http.class); + + PowerMockito.doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + ((ConsulResponseCallback) args[2]).onComplete(response); + return null; + } + }).when(http).asyncGet(Mockito.anyString(), Mockito.any(TypeReference.class), + Mockito.any(ConsulResponseCallback.class)); + + // + PowerMockito.spy(Http.class); + PowerMockito.when(Http.getInstance()).thenReturn(http); + + consul = Consul.newClient(); + + WatchCatalogServicesTask task0 = new WatchCatalogServicesTask(consul.catalogClient(), CatalogOptions.BLANK, + QueryOptions.BLANK, 10); + + WatchCatalogServicesTask task1 = new WatchCatalogServicesTask(consul.catalogClient(), 10); + + WatchCatalogServicesTask task2 = new WatchCatalogServicesTask(consul.catalogClient()); + + } + + public class StopHandler implements WatchTask.Handler<HttpEntity> { + + private WatchCatalogServicesTask task; + + StopHandler(WatchCatalogServicesTask task) { + this.task = task; + } + + @Override + public void handle(ConsulResponse<HttpEntity> object) { + // TODO Auto-generated method stub + // Map<String, List<String>> map = (Map<String, List<String>>)object.getResponse(); + LOGGER.debug("handler is here"); + task.stopWatch(); + } + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Test + public void teststartWatch() { + WatchCatalogServicesTask task0 = new WatchCatalogServicesTask(consul.catalogClient(), CatalogOptions.BLANK, + QueryOptions.BLANK, 10); + + task0.addFilter(new Filter() { + @Override + public boolean filter(ConsulResponse object) { + // TODO Auto-generated method stub + // Map<String, List<String>> map = (Map<String, List<String>>)object.getResponse(); + LOGGER.debug("filter is here"); + return true; + } + + }); + + task0.addHandler(new StopHandler(task0)); + + task0.startWatch(); + } + } diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WatchServiceHealthTaskTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WatchServiceHealthTaskTest.java index ae8fa3b..641c4c7 100644 --- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WatchServiceHealthTaskTest.java +++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WatchServiceHealthTaskTest.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; @@ -49,123 +47,109 @@ import com.orbitz.consul.option.CatalogOptions; import com.orbitz.consul.option.QueryOptions; @RunWith(PowerMockRunner.class) -@PrepareForTest({ Http.class }) -@PowerMockIgnore({ "javax.net.ssl.*" }) +@PrepareForTest({Http.class}) +@PowerMockIgnore({"javax.net.ssl.*"}) public class WatchServiceHealthTaskTest { - private static final Logger LOGGER = LoggerFactory - .getLogger(WatchServiceHealthTaskTest.class); - - private Consul consul; - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Before - public void init() { - - List<ServiceHealth> list = new ArrayList<ServiceHealth>(); - - Service service = ImmutableService.builder().id("").port(0).address("") - .service("huangleibo").addTags("").createIndex(1).modifyIndex(1).build(); - ServiceHealth serviceHealth = ImmutableServiceHealth.builder() - .service(service) - .node(ImmutableNode.builder().node("").address("").build()) - .build(); - list.add(serviceHealth); - - long lastContact = 1; - boolean knownLeader = true; - BigInteger index = BigInteger.valueOf(1); - final ConsulResponse<List<ServiceHealth>> response = new ConsulResponse<List<ServiceHealth>>( - list, lastContact, knownLeader, index); - - // - Http http = PowerMockito.mock(Http.class); - - PowerMockito - .doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocation) - throws Throwable { - Object[] args = invocation.getArguments(); - ((ConsulResponseCallback) args[2]).onComplete(response); - return null; - } - }) - .when(http) - .asyncGet(Mockito.anyString(), - Mockito.any(TypeReference.class), - Mockito.any(ConsulResponseCallback.class)); - - // - PowerMockito.spy(Http.class); - PowerMockito.when(Http.getInstance()).thenReturn(http); - - } - - @Test - public void testgetServiceName() { - consul = Consul.newClient(); - - WatchServiceHealthTask task0 = new WatchServiceHealthTask( - consul.healthClient(), "huangleibo_task0", true, - CatalogOptions.BLANK, 10, QueryOptions.BLANK); - - LOGGER.info("service name:" + task0.getServiceName()); - - WatchServiceHealthTask task1 = new WatchServiceHealthTask( - consul.healthClient(), "huangleibo_task1", true, 10); - - LOGGER.debug("service name:" + task1.getServiceName()); - - WatchServiceHealthTask task2 = new WatchServiceHealthTask( - consul.healthClient(), "huangleibo_task2", 10); - - LOGGER.debug("service name:" + task2.getServiceName()); - - } - - public class StopHandler implements WatchTask.Handler<List<ServiceHealth>> - { - - private WatchServiceHealthTask task; - - StopHandler(WatchServiceHealthTask task) - { - this.task = task; - } - - @Override - public void handle(ConsulResponse<List<ServiceHealth>> object) { - // TODO Auto-generated method stub - List<ServiceHealth> list = (List<ServiceHealth>)object.getResponse(); - LOGGER.debug("handler:"+list.get(0).getService().getService()); - task.stopWatch(); - } - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Test - public void teststartWatch() { - Consul consul = Consul.newClient(); - String serviceName = "huangleibo"; - - WatchServiceHealthTask task0 = new WatchServiceHealthTask( - consul.healthClient(), serviceName, true, CatalogOptions.BLANK, - 10, QueryOptions.BLANK); - - task0.addFilter(new Filter() { - - @Override - public boolean filter(ConsulResponse object) { - // TODO Auto-generated method stub - List<ServiceHealth> list = (List<ServiceHealth>)object.getResponse(); - LOGGER.debug("filter:"+list.get(0).getService().getService()); - return true; - } - - }); - - task0.addHandler(new StopHandler(task0)); - - task0.startWatch(); - } + private static final Logger LOGGER = LoggerFactory.getLogger(WatchServiceHealthTaskTest.class); + + private Consul consul; + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Before + public void init() { + + List<ServiceHealth> list = new ArrayList<ServiceHealth>(); + + Service service = ImmutableService.builder().id("").port(0).address("").service("huangleibo").addTags("") + .createIndex(1).modifyIndex(1).build(); + ServiceHealth serviceHealth = ImmutableServiceHealth.builder().service(service) + .node(ImmutableNode.builder().node("").address("").build()).build(); + list.add(serviceHealth); + + long lastContact = 1; + boolean knownLeader = true; + BigInteger index = BigInteger.valueOf(1); + final ConsulResponse<List<ServiceHealth>> response = + new ConsulResponse<List<ServiceHealth>>(list, lastContact, knownLeader, index); + + // + Http http = PowerMockito.mock(Http.class); + + PowerMockito.doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + ((ConsulResponseCallback) args[2]).onComplete(response); + return null; + } + }).when(http).asyncGet(Mockito.anyString(), Mockito.any(TypeReference.class), + Mockito.any(ConsulResponseCallback.class)); + + // + PowerMockito.spy(Http.class); + PowerMockito.when(Http.getInstance()).thenReturn(http); + + } + + @Test + public void testgetServiceName() { + consul = Consul.newClient(); + + WatchServiceHealthTask task0 = new WatchServiceHealthTask(consul.healthClient(), "huangleibo_task0", true, + CatalogOptions.BLANK, 10, QueryOptions.BLANK); + + LOGGER.info("service name:" + task0.getServiceName()); + + WatchServiceHealthTask task1 = new WatchServiceHealthTask(consul.healthClient(), "huangleibo_task1", true, 10); + + LOGGER.debug("service name:" + task1.getServiceName()); + + WatchServiceHealthTask task2 = new WatchServiceHealthTask(consul.healthClient(), "huangleibo_task2", 10); + + LOGGER.debug("service name:" + task2.getServiceName()); + + } + + public class StopHandler implements WatchTask.Handler<List<ServiceHealth>> { + + private WatchServiceHealthTask task; + + StopHandler(WatchServiceHealthTask task) { + this.task = task; + } + + @Override + public void handle(ConsulResponse<List<ServiceHealth>> object) { + // TODO Auto-generated method stub + List<ServiceHealth> list = (List<ServiceHealth>) object.getResponse(); + LOGGER.debug("handler:" + list.get(0).getService().getService()); + task.stopWatch(); + } + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + @Test + public void teststartWatch() { + Consul consul = Consul.newClient(); + String serviceName = "huangleibo"; + + WatchServiceHealthTask task0 = new WatchServiceHealthTask(consul.healthClient(), serviceName, true, + CatalogOptions.BLANK, 10, QueryOptions.BLANK); + + task0.addFilter(new Filter() { + + @Override + public boolean filter(ConsulResponse object) { + // TODO Auto-generated method stub + List<ServiceHealth> list = (List<ServiceHealth>) object.getResponse(); + LOGGER.debug("filter:" + list.get(0).getService().getService()); + return true; + } + + }); + + task0.addHandler(new StopHandler(task0)); + + task0.startWatch(); + } } diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WriteBufferHandlerTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WriteBufferHandlerTest.java index 9c37213..1c46d33 100644 --- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WriteBufferHandlerTest.java +++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WriteBufferHandlerTest.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,31 +29,28 @@ import com.orbitz.consul.model.ConsulResponse; import com.orbitz.consul.model.health.ImmutableNode; public class WriteBufferHandlerTest { - @Test - public void testhandle() { - List<ServiceHealth> list = new ArrayList<ServiceHealth>(); + @Test + public void testhandle() { + List<ServiceHealth> list = new ArrayList<ServiceHealth>(); - // modifyIndex 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(); + // modifyIndex 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(); - list.add(serviceHealth0); + list.add(serviceHealth0); - long lastContact = 1; - boolean knownLeader = true; - BigInteger index = BigInteger.valueOf(1); - ConsulResponse<List<ServiceHealth>> object = new ConsulResponse<List<ServiceHealth>>( - list, lastContact, knownLeader, index); + long lastContact = 1; + boolean knownLeader = true; + BigInteger index = BigInteger.valueOf(1); + ConsulResponse<List<ServiceHealth>> object = + new ConsulResponse<List<ServiceHealth>>(list, lastContact, knownLeader, index); - WriteBufferHandler<List<ServiceHealth>> handler = new WriteBufferHandler<List<ServiceHealth>>( - ServiceData.DataType.service); + WriteBufferHandler<List<ServiceHealth>> handler = + new WriteBufferHandler<List<ServiceHealth>>(ServiceData.DataType.service); - handler.handle(object); + handler.handle(object); - } + } } |