| package pta.de.core.controller; |
| |
| import org.easymock.EasyMock; |
| import org.eclipse.jetty.http.HttpStatus; |
| import org.junit.AfterClass; |
| import org.junit.BeforeClass; |
| import org.junit.Test; |
| import org.powermock.reflect.Whitebox; |
| import pta.de.core.exceptions.HttpStatusException; |
| |
| import static org.easymock.EasyMock.*; |
| |
| public class ServicesConfigCacheTimerTaskTest { |
| private static ServicesConfigCache saveScc; |
| |
| @BeforeClass |
| public static void SaveState() { |
| saveScc = Whitebox.getInternalState(ServicesConfigCache.class, "SERIVCECONFIGCACHE_INSTANCE"); |
| |
| } |
| |
| @AfterClass |
| public static void tearDown() { |
| Whitebox.setInternalState(ServicesConfigCache.class, "SERIVCECONFIGCACHE_INSTANCE", saveScc); |
| } |
| |
| @Test |
| public void testRun() throws HttpStatusException { |
| // ------------------ Prepare Test ---------------------- |
| final String EXCEPTION_TEXT = "Exception"; |
| |
| ServicesConfigCache scc = EasyMock.createMock(ServicesConfigCache.class); |
| scc.readServerDistribution(eq(EXCEPTION_TEXT)); |
| expectLastCall().andThrow(new HttpStatusException(HttpStatus.INTERNAL_SERVER_ERROR_500)).anyTimes(); |
| |
| scc.readServerDistribution(not(eq(EXCEPTION_TEXT))); |
| expectLastCall().anyTimes(); |
| |
| replay( scc ); |
| |
| Whitebox.setInternalState(ServicesConfigCache.class, "SERIVCECONFIGCACHE_INSTANCE", scc); |
| |
| |
| // ---------------------------- Test it ------------------------------------------ |
| ServicesConfigCacheTimerTask task = new ServicesConfigCacheTimerTask(EXCEPTION_TEXT); |
| |
| task.run(); |
| |
| // should run without problems |
| ServicesConfigCacheTimerTask task2 = new ServicesConfigCacheTimerTask("No Error"); |
| task2.run(); |
| |
| tearDown(); |
| } |
| |
| } |