blob: 95ae4664a989c6862cd6a65cd210e9e905d665a6 [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(sdc[0].getClustername(), "elogbook.openK");
assertEquals(sdc[0].getDistributions().length, 1);
assertEquals(sdc[0].getDistributions()[0].getHost(), "172.18.22.160");
}
@Test
public void testFailReadServerDistribution() throws Exception {
try {
baseTestReadServerDistribution("testServiceDist_False.json");
} catch( HttpStatusException e ) {
assertEquals(e.getHttpStatus(), HttpStatus.INTERNAL_SERVER_ERROR_500);
}
}
@Test
public void testReadServerDistribution_FileNotExist() throws Exception {
try {
baseTestReadServerDistribution("Nowhere.json");
} catch (HttpStatusException e) {
assertEquals(e.getHttpStatus(), HttpStatus.INTERNAL_SERVER_ERROR_500);
}
}
@Test
public void testReadServerDistribution_FileNotExistEither() throws Exception {
try {
ServicesConfigCache.getInstance().readServerDistribution("Nowhere.json");
} catch (HttpStatusException e) {
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, e.getHttpStatus());
}
}
}