aboutsummaryrefslogtreecommitdiffstats
path: root/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/ConsulTest.java
diff options
context:
space:
mode:
authorHuabingZhao <zhao.huabing@zte.com.cn>2017-07-25 15:18:33 +0800
committerHuabingZhao <zhao.huabing@zte.com.cn>2017-07-25 18:11:59 +0800
commit672f3d40be83d9e380fd7be4b674d5e8d5fa36de (patch)
tree43105e1d5e2ba8e8accea8648e57e1cf87db3f00 /apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/ConsulTest.java
parent41d3db15a8e1a0496f9c2a5e15db2998a32bb9bf (diff)
Divide the MSB source codes into two repos
Change-Id: Ie76d545b214a8ce5191f215350a623e1529983d9 Issue-id: MSB-5 Signed-off-by: HuabingZhao <zhao.huabing@zte.com.cn>
Diffstat (limited to 'apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/ConsulTest.java')
-rw-r--r--apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/ConsulTest.java149
1 files changed, 149 insertions, 0 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
new file mode 100644
index 0000000..abf5e09
--- /dev/null
+++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/consulextend/ConsulTest.java
@@ -0,0 +1,149 @@
+package org.onap.msb.apiroute.wrapper.consulextend;
+
+import java.util.List;
+
+import org.apache.http.HttpEntity;
+import org.junit.BeforeClass;
+import org.junit.Test;
+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;
+import org.onap.msb.apiroute.wrapper.consulextend.util.Http;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.orbitz.consul.model.ConsulResponse;
+import com.orbitz.consul.option.CatalogOptions;
+import com.orbitz.consul.option.QueryOptions;
+
+@RunWith(PowerMockRunner.class)
+@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);
+
+ }
+}