From: Sébastien Lesaint Date: Tue, 22 Mar 2016 17:15:29 +0000 (+0100) Subject: fix quality flaw and some missing UT coverage X-Git-Tag: 5.5-M11~43 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=467766171fcc8407d7d07edd573918d047ba2e55;p=sonarqube.git fix quality flaw and some missing UT coverage --- diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerWatcherImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerWatcherImplTest.java index a2b0fb7d757..32007dc60f1 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerWatcherImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerWatcherImplTest.java @@ -90,9 +90,36 @@ public class WebServerWatcherImplTest { assertThat(logTester.logs(LoggerLevel.INFO)).contains("Waiting for Web Server to be operational..."); } + @Test + public void waitForOperational_returns_false_if_thread_is_interrupted() throws InterruptedException { + WaitingThread waitingThread = new WaitingThread(new CountDownLatch(1)); + waitingThread.start(); + + assertThat(waitingThread.latch.await(50, MILLISECONDS)).isTrue(); + waitingThread.interrupt(); + + assertThat(waitingThread.result).isFalse(); + } + private void setWebServerOperational() { try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(sharedDir, WEB_SERVER_PROCESS_NUMBER)) { processCommands.setOperational(); } } + + private class WaitingThread extends Thread { + CountDownLatch latch; + boolean result = true; + + public WaitingThread(CountDownLatch latch) { + this.latch = latch; + result = false; + } + + @Override + public void run() { + latch.countDown(); + this.result = underTest.waitForOperational(); + } + } } diff --git a/server/sonar-server/src/main/java/org/sonar/ce/settings/ComputeEngineSettings.java b/server/sonar-server/src/main/java/org/sonar/ce/settings/ComputeEngineSettings.java index a11eeef1829..5f9c153bbb0 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/settings/ComputeEngineSettings.java +++ b/server/sonar-server/src/main/java/org/sonar/ce/settings/ComputeEngineSettings.java @@ -120,18 +120,18 @@ public class ComputeEngineSettings extends Settings implements ThreadLocalSettin public ServerSettingsImpl(PropertyDefinitions definitions, Properties rootProperties) { super(definitions); this.rootProperties = rootProperties; - addProperties(rootProperties); + super.addProperties(rootProperties); // Secret key is loaded from conf/sonar.properties - getEncryption().setPathToSecretKey(getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); + super.getEncryption().setPathToSecretKey(super.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); } @Override public ServerSettings activateDatabaseSettings(Map databaseProperties) { - clear(); + super.clear(); // order is important : the last override the first - addProperties(databaseProperties); - addProperties(rootProperties); + super.addProperties(databaseProperties); + super.addProperties(rootProperties); return this; } diff --git a/server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceBootstrapTest.java b/server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceBootstrapTest.java new file mode 100644 index 00000000000..b34bc9b913d --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceBootstrapTest.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.governance.bridge; + +import org.junit.Test; +import org.sonar.api.platform.Server; +import org.sonar.core.platform.ComponentContainer; +import org.sonar.server.governance.GovernanceBridge; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +public class GovernanceBootstrapTest { + private Server server = mock(Server.class); + private ComponentContainer componentContainer = spy(new ComponentContainer()); + private GovernanceBootstrap underTest = new GovernanceBootstrap(componentContainer); + + @Test + public void onServerStart_has_no_effect_when_ComponentContainer_contains_no_GovernanceBridge() { + underTest.onServerStart(server); + + verify(componentContainer).getComponentByType(GovernanceBridge.class); + verifyNoMoreInteractions(componentContainer); + } + + @Test + public void onServerStart_calls_GovernanceBridge_startGovernance_when_present_in_ComponentContainer() { + GovernanceBridge governanceBridge = mock(GovernanceBridge.class); + componentContainer.add(governanceBridge); + + underTest.onServerStart(server); + + verify(governanceBridge).startGovernance(componentContainer); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceStopperTest.java b/server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceStopperTest.java new file mode 100644 index 00000000000..46cf92e4158 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceStopperTest.java @@ -0,0 +1,60 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.governance.bridge; + +import org.junit.Test; +import org.sonar.core.platform.ComponentContainer; +import org.sonar.server.governance.GovernanceBridge; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +public class GovernanceStopperTest { + private ComponentContainer componentContainer = spy(new ComponentContainer()); + private GovernanceStopper underTest = new GovernanceStopper(componentContainer); + + @Test + public void start_has_no_effect() { + underTest.start(); + + verifyNoMoreInteractions(componentContainer); + } + + @Test + public void stop_has_no_effect_when_no_GovernanceBridge() { + underTest.stop(); + + verify(componentContainer).getComponentByType(GovernanceBridge.class); + verifyNoMoreInteractions(componentContainer); + } + + @Test + public void stop_calls_GovernanceBridge_stopGovernance_when_in_ComponentContainer() { + GovernanceBridge governanceBridge = mock(GovernanceBridge.class); + + componentContainer.add(governanceBridge); + + underTest.stop(); + + verify(governanceBridge).stopGovernance(); + } +}