From e75a8ef2372722c0b22669fb427d47bacc5b8d5e Mon Sep 17 00:00:00 2001 From: HuabingZhao Date: Thu, 7 Sep 2017 14:33:18 +0800 Subject: Fix java check style warning Change-Id: I98a6d7237a213d007ad4d954989cb0b0fa150a10 Issue-Id: MSB-67 Signed-off-by: HuabingZhao --- .../expose/WatchServiceHealthTaskTest.java | 238 ++++++++++----------- 1 file changed, 111 insertions(+), 127 deletions(-) (limited to 'apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WatchServiceHealthTaskTest.java') 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 list = new ArrayList(); - - 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> response = new ConsulResponse>( - 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> - { - - private WatchServiceHealthTask task; - - StopHandler(WatchServiceHealthTask task) - { - this.task = task; - } - - @Override - public void handle(ConsulResponse> object) { - // TODO Auto-generated method stub - List list = (List)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 list = (List)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 list = new ArrayList(); + + 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> response = + new ConsulResponse>(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> { + + private WatchServiceHealthTask task; + + StopHandler(WatchServiceHealthTask task) { + this.task = task; + } + + @Override + public void handle(ConsulResponse> object) { + // TODO Auto-generated method stub + List list = (List) 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 list = (List) object.getResponse(); + LOGGER.debug("filter:" + list.get(0).getService().getService()); + return true; + } + + }); + + task0.addHandler(new StopHandler(task0)); + + task0.startWatch(); + } } -- cgit 1.2.3-korg