1 package org.onap.msb.apiroute.health;
4 import org.junit.runner.RunWith;
5 import org.mockito.Mockito;
6 import org.onap.msb.apiroute.health.ConsulLinkHealthCheck;
7 import org.onap.msb.apiroute.wrapper.util.HttpClientUtil;
8 import org.powermock.api.mockito.PowerMockito;
9 import org.powermock.core.classloader.annotations.PrepareForTest;
10 import org.powermock.modules.junit4.PowerMockRunner;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
14 import com.codahale.metrics.health.HealthCheck.Result;
16 @RunWith(PowerMockRunner.class)
17 @PrepareForTest({ HttpClientUtil.class,ConsulLinkHealthCheck.class })
18 public class ConsulLinkHealthCheckTest {
19 private static final Logger LOGGER = LoggerFactory
20 .getLogger(ConsulLinkHealthCheckTest.class);
23 public void testchecksuccess()
25 PowerMockito.mockStatic(HttpClientUtil.class);
28 PowerMockito.when(HttpClientUtil.httpGetStatus(Mockito.anyString())).thenReturn(200);
29 } catch (Exception e) {
30 // TODO Auto-generated catch block
34 PowerMockito.mockStatic(System.class);
35 PowerMockito.when(System.getenv("CONSUL_IP")).thenReturn("192.168.0.1");
37 ConsulLinkHealthCheck check = new ConsulLinkHealthCheck();
38 Result rst = check.execute();
40 if (!rst.isHealthy()) {
41 LOGGER.warn("testchecksuccess health check failed:"+rst.getMessage());
45 LOGGER.debug(" testchecksuccess health");
50 public void testcheckfailed()
52 PowerMockito.mockStatic(HttpClientUtil.class);
55 PowerMockito.when(HttpClientUtil.httpGetStatus(Mockito.anyString())).thenReturn(400);
56 } catch (Exception e) {
57 // TODO Auto-generated catch block
61 PowerMockito.mockStatic(System.class);
62 PowerMockito.when(System.getenv("CONSUL_IP")).thenReturn("192.168.0.1");
64 ConsulLinkHealthCheck check = new ConsulLinkHealthCheck();
65 Result rst = check.execute();
67 if (!rst.isHealthy()) {
68 LOGGER.warn("testcheckfailed health check failed:"+rst.getMessage());
72 LOGGER.debug("testcheckfailed health");
78 public void testcheckNoENV()
80 PowerMockito.mockStatic(HttpClientUtil.class);
83 PowerMockito.when(HttpClientUtil.httpGetStatus(Mockito.anyString())).thenReturn(400);
84 } catch (Exception e) {
85 // TODO Auto-generated catch block
89 PowerMockito.mockStatic(System.class);
90 PowerMockito.when(System.getenv("CONSUL_IP")).thenReturn("");
92 ConsulLinkHealthCheck check = new ConsulLinkHealthCheck();
93 Result rst = check.execute();
95 if (!rst.isHealthy()) {
96 LOGGER.warn("testcheckNoENV health check failed:"+rst.getMessage());
100 LOGGER.debug("testcheckNoENV health");