aboutsummaryrefslogtreecommitdiffstats
path: root/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend
diff options
context:
space:
mode:
Diffstat (limited to 'apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend')
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/ConsulTest.java239
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServiceHealthCacheTest.java37
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServicesCatalogCacheTest.java28
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/CheckServiceDataEmptyAndAutoStopWatchFilterTest.java76
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/CheckTagAndAutoStopWatchFilterTest.java107
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/ConsulIndexFilterTest.java70
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/ServiceModifyIndexFilterTest.java201
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WatchCatalogServicesTaskTest.java210
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WatchServiceHealthTaskTest.java238
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/expose/WriteBufferHandlerTest.java55
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/model/health/ServiceHealthTest.java81
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/model/health/ServiceTest.java52
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/util/HttpTest.java119
13 files changed, 704 insertions, 809 deletions
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/ConsulTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/ConsulTest.java
index fcec469..71e6a84 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/ConsulTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/ConsulTest.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;
@@ -24,9 +22,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.onap.msb.apiroute.wrapper.consulextend.CatalogClient;
-import org.onap.msb.apiroute.wrapper.consulextend.Consul;
-import org.onap.msb.apiroute.wrapper.consulextend.HealthClient;
import org.onap.msb.apiroute.wrapper.consulextend.async.ConsulResponseCallback;
import org.onap.msb.apiroute.wrapper.consulextend.async.OriginalConsulResponse;
import org.onap.msb.apiroute.wrapper.consulextend.model.health.ServiceHealth;
@@ -44,121 +39,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 ConsulTest {
- private static Consul consul10081;
- private static Consul consul8500;
-
- private static final Logger LOGGER = LoggerFactory
- .getLogger(ConsulTest.class);
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
-
- 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(null);
- 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);
-
- //
- consul10081 = Consul.builder().withHostAndPort("10.74.148.111", 10081)
- .build();
- consul8500 = Consul.builder().withHostAndPort("10.74.148.111", 8500)
- .build();
- }
-
- @Test
- public void testcatalogClient() {
-
- ConsulResponseCallback<HttpEntity> callback = new ConsulResponseCallback<HttpEntity>() {
-
- @Override
- public void onComplete(
- ConsulResponse<HttpEntity> consulResponse) {
- LOGGER.info("service list complete!");
- }
-
- @Override
- public void onFailure(Throwable throwable) {
- LOGGER.info("service list failure!");
- }
-
- @Override
- public void onDelayComplete(
- OriginalConsulResponse<HttpEntity> originalConsulResponse) {
- // TODO Auto-generated method stub
- LOGGER.info("service list complete!");
- }
-
- };
-
- // 10081
- CatalogClient catalogclient10081 = consul10081.catalogClient();
- catalogclient10081.getServices(CatalogOptions.BLANK, QueryOptions.BLANK, callback);
-
- // 8500
- CatalogClient catalogclient8500 = consul8500.catalogClient();
- catalogclient8500.getServices(CatalogOptions.BLANK, QueryOptions.BLANK, callback);
- }
-
- @Test
- public void testhealthClient() {
-
- ConsulResponseCallback<List<ServiceHealth>> callback = new ConsulResponseCallback<List<ServiceHealth>>() {
-
- @Override
- public void onComplete(
- ConsulResponse<List<ServiceHealth>> consulResponse) {
- LOGGER.info("health service complete!");
-
- }
-
- @Override
- public void onFailure(Throwable throwable) {
- LOGGER.info("health service failure!");
- }
-
- @Override
- public void onDelayComplete(
- OriginalConsulResponse<List<ServiceHealth>> originalConsulResponse) {
- // TODO Auto-generated method stub
- LOGGER.info("health service complete!");
- }
-
- };
-
- // 10081
- HealthClient healthClient10081 = consul10081.healthClient();
- healthClient10081.getAllServiceInstances("apigateway-default", CatalogOptions.BLANK,
- QueryOptions.BLANK, callback);
-
- healthClient10081.getHealthyServiceInstances("apigateway-default",
- CatalogOptions.BLANK, QueryOptions.BLANK, callback);
-
- // 8500
- HealthClient healthClient8500 = consul8500.healthClient();
- healthClient8500.getAllServiceInstances("apigateway-default", CatalogOptions.BLANK,
- QueryOptions.BLANK, callback);
- healthClient8500.getHealthyServiceInstances("apigateway-default", CatalogOptions.BLANK,
- QueryOptions.BLANK, callback);
-
- }
+ private static Consul consul10081;
+ private static Consul consul8500;
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConsulTest.class);
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+
+ 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(null);
+ 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);
+
+ //
+ consul10081 = Consul.builder().withHostAndPort("10.74.148.111", 10081).build();
+ consul8500 = Consul.builder().withHostAndPort("10.74.148.111", 8500).build();
+ }
+
+ @Test
+ public void testcatalogClient() {
+
+ ConsulResponseCallback<HttpEntity> callback = new ConsulResponseCallback<HttpEntity>() {
+
+ @Override
+ public void onComplete(ConsulResponse<HttpEntity> consulResponse) {
+ LOGGER.info("service list complete!");
+ }
+
+ @Override
+ public void onFailure(Throwable throwable) {
+ LOGGER.info("service list failure!");
+ }
+
+ @Override
+ public void onDelayComplete(OriginalConsulResponse<HttpEntity> originalConsulResponse) {
+ // TODO Auto-generated method stub
+ LOGGER.info("service list complete!");
+ }
+
+ };
+
+ // 10081
+ CatalogClient catalogclient10081 = consul10081.catalogClient();
+ catalogclient10081.getServices(CatalogOptions.BLANK, QueryOptions.BLANK, callback);
+
+ // 8500
+ CatalogClient catalogclient8500 = consul8500.catalogClient();
+ catalogclient8500.getServices(CatalogOptions.BLANK, QueryOptions.BLANK, callback);
+ }
+
+ @Test
+ public void testhealthClient() {
+
+ ConsulResponseCallback<List<ServiceHealth>> callback = new ConsulResponseCallback<List<ServiceHealth>>() {
+
+ @Override
+ public void onComplete(ConsulResponse<List<ServiceHealth>> consulResponse) {
+ LOGGER.info("health service complete!");
+
+ }
+
+ @Override
+ public void onFailure(Throwable throwable) {
+ LOGGER.info("health service failure!");
+ }
+
+ @Override
+ public void onDelayComplete(OriginalConsulResponse<List<ServiceHealth>> originalConsulResponse) {
+ // TODO Auto-generated method stub
+ LOGGER.info("health service complete!");
+ }
+
+ };
+
+ // 10081
+ HealthClient healthClient10081 = consul10081.healthClient();
+ healthClient10081.getAllServiceInstances("apigateway-default", CatalogOptions.BLANK, QueryOptions.BLANK,
+ callback);
+
+ healthClient10081.getHealthyServiceInstances("apigateway-default", CatalogOptions.BLANK, QueryOptions.BLANK,
+ callback);
+
+ // 8500
+ HealthClient healthClient8500 = consul8500.healthClient();
+ healthClient8500.getAllServiceInstances("apigateway-default", CatalogOptions.BLANK, QueryOptions.BLANK,
+ callback);
+ healthClient8500.getHealthyServiceInstances("apigateway-default", CatalogOptions.BLANK, QueryOptions.BLANK,
+ callback);
+
+ }
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServiceHealthCacheTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServiceHealthCacheTest.java
index f22af71..e62d536 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServiceHealthCacheTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServiceHealthCacheTest.java
@@ -1,39 +1,34 @@
/*******************************************************************************
* 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.cache;
import org.junit.Assert;
import org.junit.Test;
import org.onap.msb.apiroute.wrapper.consulextend.Consul;
-import org.onap.msb.apiroute.wrapper.consulextend.cache.ServiceHealthCache;
import com.orbitz.consul.option.CatalogOptions;
public class ServiceHealthCacheTest {
- @Test
- public void testnewCache() {
- Consul consul = Consul.newClient();
- ServiceHealthCache cache1 = ServiceHealthCache.newCache(
- consul.healthClient(), "huangleibo");
- Assert.assertNotNull(cache1);
+ @Test
+ public void testnewCache() {
+ Consul consul = Consul.newClient();
+ ServiceHealthCache cache1 = ServiceHealthCache.newCache(consul.healthClient(), "huangleibo");
+ Assert.assertNotNull(cache1);
- ServiceHealthCache cache2 = ServiceHealthCache.newCache(
- consul.healthClient(), "huangleibo", false,
- CatalogOptions.BLANK, 10);
- Assert.assertNotNull(cache2);
- }
+ ServiceHealthCache cache2 = ServiceHealthCache.newCache(consul.healthClient(), "huangleibo", false,
+ CatalogOptions.BLANK, 10);
+ Assert.assertNotNull(cache2);
+ }
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServicesCatalogCacheTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServicesCatalogCacheTest.java
index 32167ca..a5718a1 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServicesCatalogCacheTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/cache/ServicesCatalogCacheTest.java
@@ -1,30 +1,26 @@
/*******************************************************************************
* 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.cache;
import org.junit.Test;
import org.onap.msb.apiroute.wrapper.consulextend.Consul;
-import org.onap.msb.apiroute.wrapper.consulextend.cache.ServicesCatalogCache;
public class ServicesCatalogCacheTest {
- @Test
- public void testnewCache()
- {
- Consul consul = Consul.newClient();
- ServicesCatalogCache cache = ServicesCatalogCache.newCache(consul.catalogClient());
- }
+ @Test
+ public void testnewCache() {
+ Consul consul = Consul.newClient();
+ ServicesCatalogCache cache = ServicesCatalogCache.newCache(consul.catalogClient());
+ }
}
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);
- }
+ }
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/model/health/ServiceHealthTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/model/health/ServiceHealthTest.java
index 8c1f675..787a008 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/model/health/ServiceHealthTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/model/health/ServiceHealthTest.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.model.health;
@@ -26,44 +24,39 @@ import com.orbitz.consul.model.health.Node;
public class ServiceHealthTest {
- @Test
- public void TestImmutableServiceHealth() {
- Service service = ImmutableService.builder().id("").port(0).address("")
- .service("huangleibo").addTags("").createIndex(1)
- .modifyIndex(1).build();
- Node node = ImmutableNode.builder().node("").address("").build();
+ @Test
+ public void TestImmutableServiceHealth() {
+ Service service = ImmutableService.builder().id("").port(0).address("").service("huangleibo").addTags("")
+ .createIndex(1).modifyIndex(1).build();
+ Node node = ImmutableNode.builder().node("").address("").build();
- HealthCheck healthCheck0 = ImmutableHealthCheck.builder().checkId("")
- .name("").node("").notes("").output("").serviceId("")
- .serviceName("").status("").build();
- HealthCheck healthCheck1 = ImmutableHealthCheck.builder().checkId("")
- .name("").node("").notes("").output("").serviceId("")
- .serviceName("").status("").build();
- HealthCheck healthCheck2 = ImmutableHealthCheck.builder().checkId("")
- .name("").node("").notes("").output("").serviceId("")
- .serviceName("").status("").build();
+ HealthCheck healthCheck0 = ImmutableHealthCheck.builder().checkId("").name("").node("").notes("").output("")
+ .serviceId("").serviceName("").status("").build();
+ HealthCheck healthCheck1 = ImmutableHealthCheck.builder().checkId("").name("").node("").notes("").output("")
+ .serviceId("").serviceName("").status("").build();
+ HealthCheck healthCheck2 = ImmutableHealthCheck.builder().checkId("").name("").node("").notes("").output("")
+ .serviceId("").serviceName("").status("").build();
- ImmutableServiceHealth serviceHealth0 = ImmutableServiceHealth
- .builder().service(service).node(node).addChecks(healthCheck0)
- .addChecks(healthCheck1, healthCheck2).build();
+ ImmutableServiceHealth serviceHealth0 = ImmutableServiceHealth.builder().service(service).node(node)
+ .addChecks(healthCheck0).addChecks(healthCheck1, healthCheck2).build();
- Assert.assertNotNull(serviceHealth0.getNode());
- Assert.assertNotNull(serviceHealth0.getChecks());
- /* ############################################################### */
+ Assert.assertNotNull(serviceHealth0.getNode());
+ Assert.assertNotNull(serviceHealth0.getChecks());
+ /* ############################################################### */
- ImmutableServiceHealth serviceHealth1 = serviceHealth0.withNode(node)
- .withNode(ImmutableNode.builder().node("").address("").build())
- .withService(service).withService(ImmutableService.builder().id("").port(0).address("")
- .service("huangleibo1111").addTags("").createIndex(1)
- .modifyIndex(1).build()).withChecks(healthCheck0);
-
- Assert.assertFalse(serviceHealth1.equals(serviceHealth0));
- System.out.println(serviceHealth1.hashCode());
-
- /* ############################################################### */
-
- ImmutableServiceHealth serviceHealth2 = ImmutableServiceHealth.builder().from(serviceHealth1).build();
- Assert.assertTrue(serviceHealth1.equals(serviceHealth2));
- }
+ ImmutableServiceHealth serviceHealth1 = serviceHealth0.withNode(node)
+ .withNode(ImmutableNode.builder().node("").address("").build())
+ .withService(service).withService(ImmutableService.builder().id("").port(0).address("")
+ .service("huangleibo1111").addTags("").createIndex(1).modifyIndex(1).build())
+ .withChecks(healthCheck0);
+
+ Assert.assertFalse(serviceHealth1.equals(serviceHealth0));
+ System.out.println(serviceHealth1.hashCode());
+
+ /* ############################################################### */
+
+ ImmutableServiceHealth serviceHealth2 = ImmutableServiceHealth.builder().from(serviceHealth1).build();
+ Assert.assertTrue(serviceHealth1.equals(serviceHealth2));
+ }
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/model/health/ServiceTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/model/health/ServiceTest.java
index 42908bc..62724e5 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/model/health/ServiceTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/model/health/ServiceTest.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.model.health;
@@ -20,28 +18,24 @@ import org.junit.Test;
public class ServiceTest {
- @Test
- public void testImmutableService() {
- ImmutableService service0 = ImmutableService.builder()
- .id("huangleibo_id").port(0).address("").service("huangleibo")
- .addTags("111", "222").createIndex(1).modifyIndex(1).build();
- Assert.assertEquals("huangleibo_id", service0.getId());
- Assert.assertEquals(1, service0.getCreateIndex());
- Assert.assertEquals(1, service0.getModifyIndex());
+ @Test
+ public void testImmutableService() {
+ ImmutableService service0 = ImmutableService.builder().id("huangleibo_id").port(0).address("")
+ .service("huangleibo").addTags("111", "222").createIndex(1).modifyIndex(1).build();
+ Assert.assertEquals("huangleibo_id", service0.getId());
+ Assert.assertEquals(1, service0.getCreateIndex());
+ Assert.assertEquals(1, service0.getModifyIndex());
- ImmutableService service1 = service0.withId("huangleibo_id")
- .withId("new_id").withService("huangleibo")
- .withService("new_service").withTags("new_tags")
- .withAddress("").withAddress("new_address").withPort(0)
- .withPort(1).withCreateIndex(1).withCreateIndex(2)
- .withModifyIndex(1).withModifyIndex(2);
+ ImmutableService service1 = service0.withId("huangleibo_id").withId("new_id").withService("huangleibo")
+ .withService("new_service").withTags("new_tags").withAddress("").withAddress("new_address")
+ .withPort(0).withPort(1).withCreateIndex(1).withCreateIndex(2).withModifyIndex(1)
+ .withModifyIndex(2);
- Assert.assertFalse(service0.equals(service1));
+ Assert.assertFalse(service0.equals(service1));
- System.out.println(service1.hashCode());
+ System.out.println(service1.hashCode());
- ImmutableService service2 = ImmutableService.builder().from(service1)
- .build();
- Assert.assertEquals("new_id", service2.getId());
- }
+ ImmutableService service2 = ImmutableService.builder().from(service1).build();
+ Assert.assertEquals("new_id", service2.getId());
+ }
}
diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/util/HttpTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/util/HttpTest.java
index acf72cc..086f0f0 100644
--- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/util/HttpTest.java
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/util/HttpTest.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.util;
@@ -28,7 +26,6 @@ import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine;
import org.junit.Before;
import org.junit.Test;
-import org.onap.msb.apiroute.wrapper.consulextend.util.Http;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,57 +36,53 @@ import com.orbitz.consul.option.ImmutableQueryOptions;
import com.orbitz.consul.option.QueryOptions;
public class HttpTest {
- private static final Logger LOGGER = LoggerFactory
- .getLogger(HttpTest.class);
-
- @Before
- public void init() {
-
- }
-
- @Test
- public void testoptionsFrom() {
- ImmutableCatalogOptions catalogs = ImmutableCatalogOptions.builder()
- .build();
- catalogs = catalogs.withDatacenter("datacenter").withTag("tag");
-
- BigInteger index = new BigInteger("1");
- ImmutableQueryOptions querys = QueryOptions.blockSeconds(10, index)
- .build();
- querys = querys.withConsistencyMode(ConsistencyMode.STALE)
- .withDatacenter("datacenter").withNear("near")
- .withToken("taoken");
- String url = Http.optionsFrom(catalogs, querys);
- LOGGER.info(url);
- }
-
- @Test
- public void testconsulResponse() {
-
- TypeReference<Map<String, List<String>>> TYPE_SERVICES_MAP = new TypeReference<Map<String, List<String>>>() {};
-
- ProtocolVersion version = new ProtocolVersion("HTTP",1,1);
- StatusLine status= new BasicStatusLine(version,200,"ok");
- BasicHttpResponse response = new BasicHttpResponse(status);
-
- response.setHeader("X-Consul-Index", "1");
- response.setHeader("X-Consul-Lastcontact", "1");
- response.setHeader("X-Consul-Knownleader", "true");
-
- BasicHttpEntity entity = new BasicHttpEntity();
- InputStream content = HttpTest.class.getResourceAsStream("serviceslist.json");
- entity.setContent(content);
- response.setEntity(entity);
-
- Http.consulResponse(TYPE_SERVICES_MAP, response);
-
- TypeReference<String> TYPE_SERVICES_MAP_STRING = new TypeReference<String>() {};
- InputStream content1 = HttpTest.class.getResourceAsStream("serviceslist.json");
- entity.setContent(content1);
-
- Http.consulResponse(TYPE_SERVICES_MAP_STRING, response);
-
- TypeReference<HttpEntity> TYPE_SERVICES_MAP_ENTITY = new TypeReference<HttpEntity>() {};
- Http.consulResponse(TYPE_SERVICES_MAP_ENTITY, response);
- }
+ private static final Logger LOGGER = LoggerFactory.getLogger(HttpTest.class);
+
+ @Before
+ public void init() {
+
+ }
+
+ @Test
+ public void testoptionsFrom() {
+ ImmutableCatalogOptions catalogs = ImmutableCatalogOptions.builder().build();
+ catalogs = catalogs.withDatacenter("datacenter").withTag("tag");
+
+ BigInteger index = new BigInteger("1");
+ ImmutableQueryOptions querys = QueryOptions.blockSeconds(10, index).build();
+ querys = querys.withConsistencyMode(ConsistencyMode.STALE).withDatacenter("datacenter").withNear("near")
+ .withToken("taoken");
+ String url = Http.optionsFrom(catalogs, querys);
+ LOGGER.info(url);
+ }
+
+ @Test
+ public void testconsulResponse() {
+
+ TypeReference<Map<String, List<String>>> TYPE_SERVICES_MAP = new TypeReference<Map<String, List<String>>>() {};
+
+ ProtocolVersion version = new ProtocolVersion("HTTP", 1, 1);
+ StatusLine status = new BasicStatusLine(version, 200, "ok");
+ BasicHttpResponse response = new BasicHttpResponse(status);
+
+ response.setHeader("X-Consul-Index", "1");
+ response.setHeader("X-Consul-Lastcontact", "1");
+ response.setHeader("X-Consul-Knownleader", "true");
+
+ BasicHttpEntity entity = new BasicHttpEntity();
+ InputStream content = HttpTest.class.getResourceAsStream("serviceslist.json");
+ entity.setContent(content);
+ response.setEntity(entity);
+
+ Http.consulResponse(TYPE_SERVICES_MAP, response);
+
+ TypeReference<String> TYPE_SERVICES_MAP_STRING = new TypeReference<String>() {};
+ InputStream content1 = HttpTest.class.getResourceAsStream("serviceslist.json");
+ entity.setContent(content1);
+
+ Http.consulResponse(TYPE_SERVICES_MAP_STRING, response);
+
+ TypeReference<HttpEntity> TYPE_SERVICES_MAP_ENTITY = new TypeReference<HttpEntity>() {};
+ Http.consulResponse(TYPE_SERVICES_MAP_ENTITY, response);
+ }
}