From: simonbrandhof Date: Tue, 9 Nov 2010 11:07:14 +0000 (+0000) Subject: add integration test to SONAR-1911 X-Git-Tag: 2.6~611 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b064bef048b04fc3b5d6ca4dfe6311bf90230836;p=sonarqube.git add integration test to SONAR-1911 --- diff --git a/tests/integration/tests/src/it/java/org/sonar/tests/integration/GzipCompressionTest.java b/tests/integration/tests/src/it/java/org/sonar/tests/integration/GzipCompressionTest.java index 852f3b96df5..841e7b59e77 100644 --- a/tests/integration/tests/src/it/java/org/sonar/tests/integration/GzipCompressionTest.java +++ b/tests/integration/tests/src/it/java/org/sonar/tests/integration/GzipCompressionTest.java @@ -22,14 +22,15 @@ package org.sonar.tests.integration; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.methods.GetMethod; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.junit.After; import java.io.IOException; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + public class GzipCompressionTest { private HttpClient client; @@ -38,7 +39,7 @@ public class GzipCompressionTest { @Before public void before() { client = new HttpClient(); - method = new GetMethod("http://localhost:9000"); + method = new GetMethod(ITUtils.getSonarURL()); } @After diff --git a/tests/integration/tests/src/it/java/org/sonar/tests/integration/ITUtils.java b/tests/integration/tests/src/it/java/org/sonar/tests/integration/ITUtils.java new file mode 100644 index 00000000000..e6d0ec79dd1 --- /dev/null +++ b/tests/integration/tests/src/it/java/org/sonar/tests/integration/ITUtils.java @@ -0,0 +1,41 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2009 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.tests.integration; + +import org.apache.commons.lang.StringUtils; +import org.junit.Ignore; +import org.sonar.wsclient.Sonar; + +@Ignore +public final class ITUtils { + + private ITUtils() { + } + + public static Sonar createSonarWsClient() { + return Sonar.create(getSonarURL()); + } + + public static String getSonarURL() { + return StringUtils.defaultIfEmpty(System.getProperty("sonar.url"), "http://localhost:9000"); + } + + +} diff --git a/tests/integration/tests/src/it/java/org/sonar/tests/integration/ServerTest.java b/tests/integration/tests/src/it/java/org/sonar/tests/integration/ServerTest.java index 19a1fbc31cc..80968f3468c 100644 --- a/tests/integration/tests/src/it/java/org/sonar/tests/integration/ServerTest.java +++ b/tests/integration/tests/src/it/java/org/sonar/tests/integration/ServerTest.java @@ -21,17 +21,24 @@ package org.sonar.tests.integration; import org.junit.Test; import org.sonar.wsclient.Sonar; +import org.sonar.wsclient.services.Server; import org.sonar.wsclient.services.ServerQuery; import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; public class ServerTest { @Test - public void getVersion() { - Sonar sonar = Sonar.create("http://localhost:9000"); - System.out.println(sonar.find(new ServerQuery()).getVersion()); + public void shouldGetVersion() { + Sonar sonar = ITUtils.createSonarWsClient(); assertThat(sonar.find(new ServerQuery()).getVersion(), endsWith("-SNAPSHOT")); } + + @Test + public void shouldGetStatus() { + Sonar sonar = ITUtils.createSonarWsClient(); + assertThat(sonar.find(new ServerQuery()).getStatus(), is(Server.Status.UP)); + } } diff --git a/tests/integration/tests/src/it/java/org/sonar/tests/integration/Struts139Test.java b/tests/integration/tests/src/it/java/org/sonar/tests/integration/Struts139Test.java index 0ffda3a252c..e6962275719 100644 --- a/tests/integration/tests/src/it/java/org/sonar/tests/integration/Struts139Test.java +++ b/tests/integration/tests/src/it/java/org/sonar/tests/integration/Struts139Test.java @@ -50,7 +50,7 @@ public class Struts139Test { @BeforeClass public static void buildServer() { - sonar = Sonar.create("http://localhost:9000"); + sonar = ITUtils.createSonarWsClient(); } @Test diff --git a/tests/integration/tests/src/it/java/org/sonar/tests/integration/UpdateCenterTest.java b/tests/integration/tests/src/it/java/org/sonar/tests/integration/UpdateCenterTest.java index f49ad613b52..9ba4c33cb8a 100644 --- a/tests/integration/tests/src/it/java/org/sonar/tests/integration/UpdateCenterTest.java +++ b/tests/integration/tests/src/it/java/org/sonar/tests/integration/UpdateCenterTest.java @@ -37,7 +37,7 @@ public class UpdateCenterTest { @Test public void shouldGetInstalledPlugins() { - Sonar sonar = Sonar.create("http://localhost:9000"); + Sonar sonar = ITUtils.createSonarWsClient(); List plugins = sonar.findAll(UpdateCenterQuery.createForInstalledPlugins()); assertThat(plugins.size(), greaterThan(0)); diff --git a/tests/integration/tests/src/it/java/org/sonar/tests/integration/selenium/SonarTestCase.java b/tests/integration/tests/src/it/java/org/sonar/tests/integration/selenium/SonarTestCase.java index 4e22057584b..fa56aac27e6 100644 --- a/tests/integration/tests/src/it/java/org/sonar/tests/integration/selenium/SonarTestCase.java +++ b/tests/integration/tests/src/it/java/org/sonar/tests/integration/selenium/SonarTestCase.java @@ -22,6 +22,7 @@ package org.sonar.tests.integration.selenium; import com.thoughtworks.selenium.DefaultSelenium; import org.junit.After; import org.junit.Before; +import org.sonar.tests.integration.ITUtils; /** * To execute selenium tests in IDE, you have to run the selenium server first : @@ -33,7 +34,7 @@ public abstract class SonarTestCase { @Before public void before() throws Exception { // TODO the browser and the url must be configurable - selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost:9000"); + selenium = new DefaultSelenium("localhost", 4444, "*firefox", ITUtils.getSonarURL()); selenium.start(); }