blob: 0ebe951278d4c004b0d6c986abc3323d9daec2dc [file] [log] [blame]
/**
******************************************************************************
* Copyright © 2018 PTA GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*
******************************************************************************
*/
package org.eclipse.openk.health;
import com.codahale.metrics.health.HealthCheck;
import org.eclipse.openk.api.ServiceDistributionCluster;
import org.eclipse.openk.core.controller.ServicesConfigCache;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
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);
}
}
}