blob: b1b7772bc2cd0a95fa6776f34f069c050d4b8a74 [file] [log] [blame]
package pta.de.core.controller;
import org.eclipse.jetty.http.HttpStatus;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
import pta.de.api.ServiceDistributionCluster;
import pta.de.core.common.util.ResourceLoaderBase;
import pta.de.core.exceptions.HttpStatusException;
import static org.junit.Assert.assertEquals;
public class ServicesConfigCacheTest {
private ServiceDistributionCluster[] baseTestReadServerDistribution(String jsonFile) throws Exception {
ResourceLoaderBase resourceLoaderBase = new ResourceLoaderBase();
String json = resourceLoaderBase.loadStringFromResource(jsonFile);
ServicesConfigCache scc = ServicesConfigCache.getInstance();
return Whitebox.invokeMethod(scc, "readServerDistributionFromText", json);
}
@Test
public void testReadServerDistribution() throws Exception {
ServiceDistributionCluster[] sdc = baseTestReadServerDistribution("testServiceDistributions.json");
assertEquals("elogbook.openK", sdc[0].getClustername());
assertEquals(1, sdc[0].getDistributions().length);
assertEquals("172.18.22.160", sdc[0].getDistributions()[0].getHost());
}
@Test
public void testFailReadServerDistribution() throws Exception {
try {
baseTestReadServerDistribution("testServiceDist_False.json");
} catch( HttpStatusException e ) {
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, e.getHttpStatus());
}
}
@Test
public void testReadServerDistribution_FileNotExist() throws Exception {
try {
baseTestReadServerDistribution("Nowhere.json");
} catch (HttpStatusException e) {
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, e.getHttpStatus());
}
}
@Test
public void testReadServerDistribution_FileNotExistEither() throws Exception {
try {
ServicesConfigCache.getInstance().readServerDistribution("Nowhere.json");
} catch (HttpStatusException e) {
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, e.getHttpStatus());
}
}
}