1 package org.onap.msb.apiroute.health;
3 import org.junit.Before;
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;
16 import redis.clients.jedis.JedisPool;
17 import redis.clients.jedis.JedisPoolConfig;
19 import com.codahale.metrics.health.HealthCheck.Result;
20 import com.fiftyonred.mock_jedis.MockJedisPool;
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);
30 public void setUpBeforeTest() throws Exception {
34 @SuppressWarnings("static-access")
36 public void testchecksuccess()
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());
45 RedisHealthCheck check = new RedisHealthCheck();
46 Result rst = check.execute();
48 if (!rst.isHealthy()) {
49 LOGGER.warn("testchecksuccess health check failed:"+rst.getMessage());
53 LOGGER.debug(" testchecksuccess health");
56 } catch (Exception e) {
57 // TODO Auto-generated catch block
63 public void testcheckfailed()
65 RedisHealthCheck check = new RedisHealthCheck();
66 Result rst = check.execute();
68 if (!rst.isHealthy()) {
69 LOGGER.warn("testcheckfailed health check failed:"+rst.getMessage());
73 LOGGER.debug("testcheckfailed health");