| /** |
| ****************************************************************************** |
| * 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.core.controller; |
| |
| import org.easymock.EasyMock; |
| import org.eclipse.jetty.http.HttpStatus; |
| import org.eclipse.openK.core.exceptions.HttpStatusException; |
| import org.junit.AfterClass; |
| import org.junit.BeforeClass; |
| import org.junit.Test; |
| import org.powermock.reflect.Whitebox; |
| |
| import static org.easymock.EasyMock.*; |
| |
| public class ServicesConfigCacheTimerTaskTest { |
| private static ServicesConfigCache saveScc; |
| |
| @BeforeClass |
| public static void SaveState() { |
| saveScc = Whitebox.getInternalState(ServicesConfigCache.class, "instance"); |
| |
| } |
| |
| @AfterClass |
| public static void tearDown() { |
| Whitebox.setInternalState(ServicesConfigCache.class, "instance", saveScc); |
| } |
| |
| @Test |
| public void testRun() throws Exception { |
| // ------------------ Prepare Test ---------------------- |
| final String EXCEPTION_TEXT = "Exception"; |
| |
| // just to reach the sonar quality gate |
| Whitebox.invokeConstructor(InitServicesConfigCacheJob.class); |
| |
| 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, "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(); |
| } |
| |
| } |