| package pta.de.health; |
| |
| import com.codahale.metrics.health.HealthCheck; |
| import org.junit.Test; |
| import org.powermock.reflect.Whitebox; |
| import pta.de.api.ServiceDistributionCluster; |
| import pta.de.core.controller.ServicesConfigCache; |
| |
| import static junit.framework.TestCase.assertFalse; |
| import static org.junit.Assert.assertTrue; |
| |
| public class ConfigFilePresentHealthCheckTest { |
| private boolean isHealthy(ConfigFilePresentHealthCheck hc) throws Exception { |
| HealthCheck.Result r = Whitebox.invokeMethod(hc, "check"); |
| return r.isHealthy(); |
| } |
| |
| @Test |
| public void testConfigFilePresent_False() throws Exception { |
| ServicesConfigCache scc = ServicesConfigCache.getInstance(); |
| ServiceDistributionCluster[] oldCache = scc.getCache(); |
| |
| try { |
| ConfigFilePresentHealthCheck hc = new ConfigFilePresentHealthCheck(); |
| |
| // test with invalid cluster |
| Whitebox.setInternalState(scc, "cache", (Object) null); |
| assertFalse(isHealthy(hc)); |
| |
| // test with invalid cluster |
| Whitebox.setInternalState(scc, "cache", new ServiceDistributionCluster[0]); |
| assertFalse(isHealthy(hc)); |
| |
| ServiceDistributionCluster[] arr = new ServiceDistributionCluster[1]; |
| arr[0] = new ServiceDistributionCluster(); |
| Whitebox.setInternalState(scc, "cache", arr); |
| assertTrue(isHealthy(hc)); |
| } finally { |
| Whitebox.setInternalState(scc, "cache", oldCache); |
| } |
| } |
| } |