aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-application/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-10-02 07:47:16 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-10-02 07:47:16 +0200
commit6f125c33284cc5b7231cf982d8b7157c8097eb27 (patch)
treeaab128a40f1941f6297d48e28f103246ea9874ea /sonar-application/src
parent481a4dcc418f9c589934220ba4799d6124e4c690 (diff)
downloadsonarqube-6f125c33284cc5b7231cf982d8b7157c8097eb27.tar.gz
sonarqube-6f125c33284cc5b7231cf982d8b7157c8097eb27.zip
SONAR-4675 fix some quality flaws
Diffstat (limited to 'sonar-application/src')
-rw-r--r--sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java2
-rw-r--r--sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java14
-rw-r--r--sonar-application/src/test/java/org/sonar/application/PropsTest.java3
-rw-r--r--sonar-application/src/test/java/org/sonar/application/WebappTest.java55
4 files changed, 74 insertions, 0 deletions
diff --git a/sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java b/sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java
index db22f41ff3b..44679ab214f 100644
--- a/sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java
+++ b/sonar-application/src/main/java/org/sonar/application/EmbeddedTomcat.java
@@ -47,6 +47,8 @@ class EmbeddedTomcat {
// See Ruby on Rails url_for
System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
+ System.setProperty("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE", "true");
+
// Required for webapp and logback xml files
System.setProperty("SONAR_HOME", env.rootDir().getAbsolutePath());
diff --git a/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java b/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java
index b437227211f..b40b79b32f0 100644
--- a/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/ConnectorsTest.java
@@ -61,6 +61,20 @@ public class ConnectorsTest {
}
@Test
+ public void disable_shutdown_port_if_missing_token() throws Exception {
+ Properties p = new Properties();
+ // only the port, but not the token
+ p.setProperty(Connectors.PROPERTY_SHUTDOWN_PORT, "9010");
+ Props props = new Props(p);
+
+ Tomcat tomcat = mock(Tomcat.class, Mockito.RETURNS_DEEP_STUBS);
+ Connectors.configure(tomcat, props);
+
+ verify(tomcat.getServer(), never()).setPort(anyInt());
+ verify(tomcat.getServer(), never()).setShutdown(anyString());
+ }
+
+ @Test
public void configure_thread_pool() throws Exception {
Properties p = new Properties();
p.setProperty(Connectors.PROPERTY_MIN_THREADS, "2");
diff --git a/sonar-application/src/test/java/org/sonar/application/PropsTest.java b/sonar-application/src/test/java/org/sonar/application/PropsTest.java
index b2bd5d0fd69..99236b7fb68 100644
--- a/sonar-application/src/test/java/org/sonar/application/PropsTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/PropsTest.java
@@ -46,10 +46,13 @@ public class PropsTest {
public void intOf() throws Exception {
Properties p = new Properties();
p.setProperty("foo", "33");
+ p.setProperty("blank", "");
Props props = new Props(p);
assertThat(props.intOf("foo")).isEqualTo(33);
assertThat(props.intOf("foo", 44)).isEqualTo(33);
+ assertThat(props.intOf("blank")).isNull();
+ assertThat(props.intOf("blank", 55)).isEqualTo(55);
assertThat(props.intOf("unknown")).isNull();
assertThat(props.intOf("unknown", 44)).isEqualTo(44);
}
diff --git a/sonar-application/src/test/java/org/sonar/application/WebappTest.java b/sonar-application/src/test/java/org/sonar/application/WebappTest.java
new file mode 100644
index 00000000000..8bc39746308
--- /dev/null
+++ b/sonar-application/src/test/java/org/sonar/application/WebappTest.java
@@ -0,0 +1,55 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.application;
+
+import org.apache.catalina.startup.Tomcat;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
+import static org.mockito.Mockito.*;
+
+public class WebappTest {
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ @Test
+ public void fail_on_error() throws Exception {
+ Env env = mock(Env.class);
+ File webDir = temp.newFolder("web");
+ when(env.file("web")).thenReturn(webDir);
+
+ Tomcat tomcat = mock(Tomcat.class, RETURNS_DEEP_STUBS);
+ when(tomcat.addContext("", webDir.getAbsolutePath())).thenThrow(new NullPointerException());
+
+ try {
+ Webapp.configure(tomcat, env, mock(Props.class));
+ fail();
+ } catch (IllegalStateException e) {
+ assertThat(e).hasMessage("Fail to configure webapp");
+ }
+
+ }
+}