Divide the MSB source codes into two repos
[msb/apigateway.git] / apiroute / apiroute-service / src / test / java / org / onap / msb / apiroute / health / ApiRouteHealthCheckTest.java
1 package org.onap.msb.apiroute.health;
2
3 import org.junit.Test;
4 import org.junit.runner.RunWith;
5 import org.mockito.Mockito;
6 import org.onap.msb.apiroute.health.ApiRouteHealthCheck;
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;
13
14 import com.codahale.metrics.health.HealthCheck.Result;
15
16 @RunWith(PowerMockRunner.class)
17 @PrepareForTest({ HttpClientUtil.class })
18 public class ApiRouteHealthCheckTest {
19         private static final Logger LOGGER = LoggerFactory
20                         .getLogger(ApiRouteHealthCheckTest.class);
21         
22         @Test
23         public void testchecksuccess()
24         {
25                 PowerMockito.mockStatic(HttpClientUtil.class);
26                 try {
27                         
28                         PowerMockito.when(HttpClientUtil.httpGetStatus(Mockito.anyString())).thenReturn(200);
29                 } catch (Exception e) {
30                         // TODO Auto-generated catch block
31                         e.printStackTrace();
32                 }
33                 
34                 ApiRouteHealthCheck check = new ApiRouteHealthCheck();
35                 Result rst = check.execute();
36                 
37                 if (!rst.isHealthy()) {
38                         LOGGER.warn("testchecksuccess health check failed:"+rst.getMessage());
39                 }
40                 else
41                 {
42                         LOGGER.debug(" testchecksuccess health");
43                 }
44         }
45         
46         @Test
47         public void testcheckfailed()
48         {
49                 PowerMockito.mockStatic(HttpClientUtil.class);
50                 try {
51                         
52                         PowerMockito.when(HttpClientUtil.httpGetStatus(Mockito.anyString())).thenReturn(400);
53                 } catch (Exception e) {
54                         // TODO Auto-generated catch block
55                         e.printStackTrace();
56                 }
57                 
58                 ApiRouteHealthCheck check = new ApiRouteHealthCheck();
59                 Result rst = check.execute();
60                 
61                 if (!rst.isHealthy()) {
62                         LOGGER.warn("testcheckfailed health check failed:"+rst.getMessage());
63                 }
64                 else
65                 {
66                         LOGGER.debug(" testcheckfailed health");
67                 }
68         }
69 }