]> source.dussan.org Git - sonarqube.git/commitdiff
add integration test to SONAR-1911
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 9 Nov 2010 11:07:14 +0000 (11:07 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 9 Nov 2010 11:07:14 +0000 (11:07 +0000)
tests/integration/tests/src/it/java/org/sonar/tests/integration/GzipCompressionTest.java
tests/integration/tests/src/it/java/org/sonar/tests/integration/ITUtils.java [new file with mode: 0644]
tests/integration/tests/src/it/java/org/sonar/tests/integration/ServerTest.java
tests/integration/tests/src/it/java/org/sonar/tests/integration/Struts139Test.java
tests/integration/tests/src/it/java/org/sonar/tests/integration/UpdateCenterTest.java
tests/integration/tests/src/it/java/org/sonar/tests/integration/selenium/SonarTestCase.java

index 852f3b96df556b44e78ae144a2b2de566141c819..841e7b59e7721b8d8fa7587bb95d7a391675508a 100644 (file)
@@ -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 (file)
index 0000000..e6d0ec7
--- /dev/null
@@ -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");
+  }
+
+
+}
index 19a1fbc31ccc1947a09e9f306a4db9dda416189f..80968f3468c64d9c4839d889a4f097959d69f02b 100644 (file)
@@ -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));
+  }
 }
index 0ffda3a252c5240c07c4c532a4e0037761f559e7..e6962275719e9be2dccb5dd435a1661756027f59 100644 (file)
@@ -50,7 +50,7 @@ public class Struts139Test {
 
   @BeforeClass
   public static void buildServer() {
-    sonar = Sonar.create("http://localhost:9000");
+    sonar = ITUtils.createSonarWsClient();
   }
 
   @Test
index f49ad613b52ffca4dea62d3dd3c5ab453a417d70..9ba4c33cb8a80add33dfab05cc285c006af76ce2 100644 (file)
@@ -37,7 +37,7 @@ public class UpdateCenterTest {
 
   @Test
   public void shouldGetInstalledPlugins() {
-    Sonar sonar = Sonar.create("http://localhost:9000");
+    Sonar sonar = ITUtils.createSonarWsClient();
     List<Plugin> plugins = sonar.findAll(UpdateCenterQuery.createForInstalledPlugins());
     assertThat(plugins.size(), greaterThan(0));
 
index 4e22057584b56a275dace608efba587b3577316e..fa56aac27e62df0d8a4ae3c37afba072650dfbdf 100644 (file)
@@ -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();
   }