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.OpenRestyHealthCheck;
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,OpenRestyHealthCheck.class })
18 public class OpenRestyHealthCheckTest {
19 private static final Logger LOGGER = LoggerFactory
20 .getLogger(OpenRestyHealthCheckTest.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("HTTP_OVERWRITE_PORT")).thenReturn("10080");
37 OpenRestyHealthCheck check = new OpenRestyHealthCheck();
39 Result rst = check.execute();
41 if (!rst.isHealthy()) {
42 LOGGER.warn("testchecksuccess health check failed:"+rst.getMessage());
46 LOGGER.debug(" testchecksuccess health");
51 public void testcheckfailed()
53 PowerMockito.mockStatic(HttpClientUtil.class);
56 PowerMockito.when(HttpClientUtil.httpGetStatus(Mockito.anyString())).thenReturn(400);
57 } catch (Exception e) {
58 // TODO Auto-generated catch block
62 PowerMockito.mockStatic(System.class);
63 PowerMockito.when(System.getenv("HTTP_OVERWRITE_PORT")).thenReturn("");
65 OpenRestyHealthCheck check = new OpenRestyHealthCheck();
67 Result rst = check.execute();
69 if (!rst.isHealthy()) {
70 LOGGER.warn("testchecksuccess health check failed:"+rst.getMessage());
74 LOGGER.debug(" testchecksuccess health");