Divide the MSB source codes into two repos
[msb/apigateway.git] / apiroute / apiroute-service / src / test / java / org / onap / msb / apiroute / health / RedisHealthCheckTest.java
1 package org.onap.msb.apiroute.health;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.junit.runner.RunWith;
6 import org.onap.msb.apiroute.health.RedisHealthCheck;
7 import org.onap.msb.apiroute.wrapper.dao.RedisAccessWrapper;
8 import org.onap.msb.apiroute.wrapper.util.JedisUtil;
9 import org.powermock.api.mockito.PowerMockito;
10 import org.powermock.core.classloader.annotations.PowerMockIgnore;
11 import org.powermock.core.classloader.annotations.PrepareForTest;
12 import org.powermock.modules.junit4.PowerMockRunner;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 import redis.clients.jedis.JedisPool;
17 import redis.clients.jedis.JedisPoolConfig;
18
19 import com.codahale.metrics.health.HealthCheck.Result;
20 import com.fiftyonred.mock_jedis.MockJedisPool;
21
22 @RunWith(PowerMockRunner.class)
23 @PrepareForTest({JedisUtil.class,RedisAccessWrapper.class})
24 @PowerMockIgnore( {"javax.management.*"})
25 public class RedisHealthCheckTest {
26         private static final Logger LOGGER = LoggerFactory
27                         .getLogger(RedisHealthCheckTest.class);
28         
29         @Before
30     public void setUpBeforeTest() throws Exception {
31
32     }
33         
34         @SuppressWarnings("static-access")
35         @Test
36         public void testchecksuccess()
37         {
38
39         try {
40             final JedisPool mockJedisPool = new MockJedisPool(new JedisPoolConfig(), "localhost");
41             PowerMockito.mockStatic(JedisUtil.class);
42             JedisUtil jedisUtil=PowerMockito.mock(JedisUtil.class);
43                         PowerMockito.when(jedisUtil.borrowJedisInstance()).thenReturn(mockJedisPool.getResource());
44                         
45                         RedisHealthCheck check = new RedisHealthCheck();
46                         Result rst = check.execute();
47                         
48                         if (!rst.isHealthy()) {
49                                 LOGGER.warn("testchecksuccess health check failed:"+rst.getMessage());
50                         }
51                         else
52                         {
53                                 LOGGER.debug(" testchecksuccess health");
54                         }
55                         
56                 } catch (Exception e) {
57                         // TODO Auto-generated catch block
58                         e.printStackTrace();
59                 }
60         }
61         
62         @Test
63         public void testcheckfailed()
64         {
65                 RedisHealthCheck check = new RedisHealthCheck();
66                 Result rst = check.execute();
67                 
68                 if (!rst.isHealthy()) {
69                         LOGGER.warn("testcheckfailed health check failed:"+rst.getMessage());
70                 }
71                 else
72                 {
73                         LOGGER.debug("testcheckfailed health");
74                 }
75                 
76         }
77 }