]> source.dussan.org Git - sonarqube.git/commitdiff
fix quality flaw and some missing UT coverage 861/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 22 Mar 2016 17:15:29 +0000 (18:15 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 23 Mar 2016 08:35:43 +0000 (09:35 +0100)
server/sonar-ce/src/test/java/org/sonar/ce/app/WebServerWatcherImplTest.java
server/sonar-server/src/main/java/org/sonar/ce/settings/ComputeEngineSettings.java
server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceBootstrapTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceStopperTest.java [new file with mode: 0644]

index a2b0fb7d757c3d241c9fbe9ac9bd1007ddac08b5..32007dc60f1e69613c68d446e0c9885ba4f3f828 100644 (file)
@@ -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();
+    }
+  }
 }
index a11eeef18297d5c1b6736bb63cf80328dcf639b8..5f9c153bbb042edd1dbe5c6ca20b6b35c576582e 100644 (file)
@@ -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<String, String> 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 (file)
index 0000000..b34bc9b
--- /dev/null
@@ -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 (file)
index 0000000..46cf92e
--- /dev/null
@@ -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();
+  }
+}