| 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(); |
| |
| |
| |
| ServiceDistributionCluster[] sdc = (ServiceDistributionCluster[]) |
| Whitebox.invokeMethod(scc,"readServerDistributionFromText", json); |
| |
| return sdc; |
| } |
| |
| @Test |
| public void testReadServerDistribution() throws Exception { |
| |
| ServiceDistributionCluster[] sdc = baseTestReadServerDistribution("testServiceDistributions.json"); |
| |
| assertEquals(sdc[0].clustername, "elogbook.openK"); |
| assertEquals(sdc[0].getDistributions().length, 1); |
| assertEquals(sdc[0].getDistributions()[0].host, "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); |
| } |
| } |
| |
| } |