1 package org.onap.msb.apiroute.wrapper.consulextend;
5 import org.apache.http.HttpEntity;
6 import org.junit.BeforeClass;
8 import org.junit.runner.RunWith;
9 import org.mockito.Mockito;
10 import org.mockito.invocation.InvocationOnMock;
11 import org.mockito.stubbing.Answer;
12 import org.onap.msb.apiroute.wrapper.consulextend.CatalogClient;
13 import org.onap.msb.apiroute.wrapper.consulextend.Consul;
14 import org.onap.msb.apiroute.wrapper.consulextend.HealthClient;
15 import org.onap.msb.apiroute.wrapper.consulextend.async.ConsulResponseCallback;
16 import org.onap.msb.apiroute.wrapper.consulextend.async.OriginalConsulResponse;
17 import org.onap.msb.apiroute.wrapper.consulextend.model.health.ServiceHealth;
18 import org.onap.msb.apiroute.wrapper.consulextend.util.Http;
19 import org.powermock.api.mockito.PowerMockito;
20 import org.powermock.core.classloader.annotations.PowerMockIgnore;
21 import org.powermock.core.classloader.annotations.PrepareForTest;
22 import org.powermock.modules.junit4.PowerMockRunner;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.fasterxml.jackson.core.type.TypeReference;
27 import com.orbitz.consul.model.ConsulResponse;
28 import com.orbitz.consul.option.CatalogOptions;
29 import com.orbitz.consul.option.QueryOptions;
31 @RunWith(PowerMockRunner.class)
32 @PrepareForTest({ Http.class })
33 @PowerMockIgnore({ "javax.net.ssl.*" })
34 public class ConsulTest {
35 private static Consul consul10081;
36 private static Consul consul8500;
38 private static final Logger LOGGER = LoggerFactory
39 .getLogger(ConsulTest.class);
41 @SuppressWarnings({ "unchecked", "rawtypes" })
43 public static void setUpBeforeClass() throws Exception {
45 Http http = PowerMockito.mock(Http.class);
48 .doAnswer(new Answer() {
50 public Object answer(InvocationOnMock invocation)
52 Object[] args = invocation.getArguments();
53 ((ConsulResponseCallback) args[2]).onComplete(null);
58 .asyncGet(Mockito.anyString(),
59 Mockito.any(TypeReference.class),
60 Mockito.any(ConsulResponseCallback.class));
63 PowerMockito.spy(Http.class);
64 PowerMockito.when(Http.getInstance()).thenReturn(http);
67 consul10081 = Consul.builder().withHostAndPort("10.74.148.111", 10081)
69 consul8500 = Consul.builder().withHostAndPort("10.74.148.111", 8500)
74 public void testcatalogClient() {
76 ConsulResponseCallback<HttpEntity> callback = new ConsulResponseCallback<HttpEntity>() {
79 public void onComplete(
80 ConsulResponse<HttpEntity> consulResponse) {
81 LOGGER.info("service list complete!");
85 public void onFailure(Throwable throwable) {
86 LOGGER.info("service list failure!");
90 public void onDelayComplete(
91 OriginalConsulResponse<HttpEntity> originalConsulResponse) {
92 // TODO Auto-generated method stub
93 LOGGER.info("service list complete!");
99 CatalogClient catalogclient10081 = consul10081.catalogClient();
100 catalogclient10081.getServices(CatalogOptions.BLANK, QueryOptions.BLANK, callback);
103 CatalogClient catalogclient8500 = consul8500.catalogClient();
104 catalogclient8500.getServices(CatalogOptions.BLANK, QueryOptions.BLANK, callback);
108 public void testhealthClient() {
110 ConsulResponseCallback<List<ServiceHealth>> callback = new ConsulResponseCallback<List<ServiceHealth>>() {
113 public void onComplete(
114 ConsulResponse<List<ServiceHealth>> consulResponse) {
115 LOGGER.info("health service complete!");
120 public void onFailure(Throwable throwable) {
121 LOGGER.info("health service failure!");
125 public void onDelayComplete(
126 OriginalConsulResponse<List<ServiceHealth>> originalConsulResponse) {
127 // TODO Auto-generated method stub
128 LOGGER.info("health service complete!");
134 HealthClient healthClient10081 = consul10081.healthClient();
135 healthClient10081.getAllServiceInstances("apigateway-default", CatalogOptions.BLANK,
136 QueryOptions.BLANK, callback);
138 healthClient10081.getHealthyServiceInstances("apigateway-default",
139 CatalogOptions.BLANK, QueryOptions.BLANK, callback);
142 HealthClient healthClient8500 = consul8500.healthClient();
143 healthClient8500.getAllServiceInstances("apigateway-default", CatalogOptions.BLANK,
144 QueryOptions.BLANK, callback);
145 healthClient8500.getHealthyServiceInstances("apigateway-default", CatalogOptions.BLANK,
146 QueryOptions.BLANK, callback);