From 1d155007f27ffaee6617cc2fd0cd41d7dcb0bff9 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 28 Jul 2015 08:38:08 +0200 Subject: [PATCH] Reactivate administration and server ITs --- .travis.yml | 2 + .../src/test/java/server/ServerTest.java | 129 ---------------- .../test/java/server/suite/ServerTest.java | 139 ++++++++++++++++++ .../java/server/suite/ServerTestSuite.java | 10 +- 4 files changed, 150 insertions(+), 130 deletions(-) create mode 100644 it/it-tests/src/test/java/server/suite/ServerTest.java diff --git a/.travis.yml b/.travis.yml index 9c2829f22c7..86c3bc28866 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,8 @@ env: - JOB=WEB - JOB=ITS IT_CATEGORY=issue - JOB=ITS IT_CATEGORY=analysis + - JOB=ITS IT_CATEGORY=administration + - JOB=ITS IT_CATEGORY=server - JOB=ITS IT_CATEGORY=plugins - JOB=ITS IT_CATEGORY=qualitygate - JOB=ITS IT_CATEGORY=updatecenter diff --git a/it/it-tests/src/test/java/server/ServerTest.java b/it/it-tests/src/test/java/server/ServerTest.java index 477ded8658f..acaffab22ee 100644 --- a/it/it-tests/src/test/java/server/ServerTest.java +++ b/it/it-tests/src/test/java/server/ServerTest.java @@ -6,27 +6,17 @@ package server; import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.OrchestratorBuilder; import com.sonar.orchestrator.build.SonarRunner; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.selenium.Selenese; import java.io.File; -import java.io.IOException; import java.net.URL; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.SystemUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.util.EntityUtils; import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.wsclient.base.HttpException; -import org.sonar.wsclient.services.PropertyDeleteQuery; -import org.sonar.wsclient.services.PropertyUpdateQuery; import org.sonar.wsclient.services.Server; import org.sonar.wsclient.services.ServerQuery; import util.ItUtils; @@ -48,35 +38,6 @@ public class ServerTest { } } - /** - * See http://jira.codehaus.org/browse/SONAR-2727 - */ - @Test - public void display_warnings_when_using_h2() { - OrchestratorBuilder builder = Orchestrator.builderEnv(); - if (builder.getOrchestratorConfiguration().getString("sonar.jdbc.dialect").equals("h2")) { - orchestrator = builder.build(); - orchestrator.start(); - - Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("derby-warnings", - "/server/ServerTest/derby-warning.html").build(); - orchestrator.executeSelenese(selenese); - } - } - - /** - * See http://jira.codehaus.org/browse/SONAR-2840 - */ - @Test - public void hide_jdbc_settings_to_non_admin() { - orchestrator = Orchestrator.createEnv(); - orchestrator.start(); - - Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("jdbc-settings", - "/server/ServerTest/hide-jdbc-settings.html").build(); - orchestrator.executeSelenese(selenese); - } - @Test public void test_settings() { URL secretKeyUrl = getClass().getResource("/server/ServerTest/sonar-secret.txt"); @@ -134,67 +95,6 @@ public class ServerTest { orchestrator.executeSelenese(selenese); } - /** - * SONAR-5542 - */ - @Test - public void force_authentication_should_be_used_on_java_web_services_but_not_on_batch_index_and_file() throws IOException { - orchestrator = Orchestrator.createEnv(); - orchestrator.start(); - - try { - orchestrator.getServer().getAdminWsClient().update(new PropertyUpdateQuery("sonar.forceAuthentication", "true")); - - // /batch/index should never need authentication - String batchIndex = orchestrator.getServer().wsClient().get("/batch/index"); - assertThat(batchIndex).isNotEmpty(); - - String jar = batchIndex.split("\\|")[0]; - - // /batch/file should never need authentication - HttpClient httpclient = new DefaultHttpClient(); - try { - HttpGet get = new HttpGet(orchestrator.getServer().getUrl() + "/batch/file?name=" + jar); - HttpResponse response = httpclient.execute(get); - assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200); - EntityUtils.consume(response.getEntity()); - - // As Sonar runner is still using /batch/key, we have to also verify it - get = new HttpGet(orchestrator.getServer().getUrl() + "/batch/" + jar); - response = httpclient.execute(get); - assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200); - EntityUtils.consume(response.getEntity()); - - } finally { - httpclient.getConnectionManager().shutdown(); - } - - // but other java web services should need authentication - try { - orchestrator.getServer().wsClient().get("/api"); - } catch (HttpException e) { - assertThat(e.getMessage()).contains("401"); - } - - } finally { - orchestrator.getServer().getAdminWsClient().delete(new PropertyDeleteQuery("sonar.forceAuthentication")); - } - } - - /** - * SONAR-3320 - */ - @Test - public void global_property_change_extension_point() throws IOException { - orchestrator = Orchestrator.builderEnv() - .addPlugin(ItUtils.pluginArtifact("global-property-change-plugin")) - .build(); - orchestrator.start(); - - orchestrator.getServer().adminWsClient().post("api/properties/create?id=globalPropertyChange.received&value=NEWVALUE"); - assertThat(FileUtils.readFileToString(orchestrator.getServer().getLogs()).contains("Received change: NEWVALUE")); - } - /** * SONAR-3516 */ @@ -212,22 +112,6 @@ public class ServerTest { } } - /** - * SONAR-3962 - */ - @Test - public void not_fail_with_url_ending_by_jsp() { - orchestrator = Orchestrator.builderEnv().addPlugin(ItUtils.xooPlugin()).build(); - orchestrator.start(); - - orchestrator.executeBuild(SonarRunner.create(ItUtils.projectDir("shared/xoo-sample")) - .setProperty("sonar.projectKey", "myproject.jsp")); - // Access dashboard - Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("url_ending_by_jsp", - "/server/ServerTest/url_ending_by_jsp.html").build(); - orchestrator.executeSelenese(selenese); - } - @Test public void support_install_dir_with_whitespaces() throws Exception { String dirName = "target/has space"; @@ -239,19 +123,6 @@ public class ServerTest { assertThat(status).isEqualTo(Server.Status.UP); } - // SONAR-4404 - @Test - public void should_get_settings_default_value() { - orchestrator = Orchestrator.builderEnv() - .addPlugin(ItUtils.pluginArtifact("server-plugin")) - .build(); - orchestrator.start(); - - Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("settings-default-value", - "/server/ServerTest/settings-default-value.html").build(); - orchestrator.executeSelenese(selenese); - } - // SONAR-4748 @Test public void should_create_in_temp_folder() throws Exception { diff --git a/it/it-tests/src/test/java/server/suite/ServerTest.java b/it/it-tests/src/test/java/server/suite/ServerTest.java new file mode 100644 index 00000000000..725dbf7dddb --- /dev/null +++ b/it/it-tests/src/test/java/server/suite/ServerTest.java @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2009-2014 SonarSource SA + * All rights reserved + * mailto:contact AT sonarsource DOT com + */ +package server.suite; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.SonarRunner; +import com.sonar.orchestrator.selenium.Selenese; +import java.io.IOException; +import org.apache.commons.io.FileUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.util.EntityUtils; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.wsclient.base.HttpException; +import org.sonar.wsclient.services.PropertyDeleteQuery; +import org.sonar.wsclient.services.PropertyUpdateQuery; +import util.ItUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ServerTest { + + @ClassRule + public static final Orchestrator orchestrator = ServerTestSuite.ORCHESTRATOR; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Before + public void cleanDatabase() { + orchestrator.resetData(); + } + + /** + * See http://jira.codehaus.org/browse/SONAR-2727 + */ + @Test + public void display_warnings_when_using_h2() { + if (orchestrator.getConfiguration().getString("sonar.jdbc.dialect").equals("h2")) { + Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("derby-warnings", + "/server/ServerTest/derby-warning.html").build(); + orchestrator.executeSelenese(selenese); + } + } + + /** + * See http://jira.codehaus.org/browse/SONAR-2840 + */ + @Test + public void hide_jdbc_settings_to_non_admin() { + Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("jdbc-settings", + "/server/ServerTest/hide-jdbc-settings.html").build(); + orchestrator.executeSelenese(selenese); + } + + /** + * SONAR-5542 + */ + @Test + public void force_authentication_should_be_used_on_java_web_services_but_not_on_batch_index_and_file() throws IOException { + try { + orchestrator.getServer().getAdminWsClient().update(new PropertyUpdateQuery("sonar.forceAuthentication", "true")); + + // /batch/index should never need authentication + String batchIndex = orchestrator.getServer().wsClient().get("/batch/index"); + assertThat(batchIndex).isNotEmpty(); + + String jar = batchIndex.split("\\|")[0]; + + // /batch/file should never need authentication + HttpClient httpclient = new DefaultHttpClient(); + try { + HttpGet get = new HttpGet(orchestrator.getServer().getUrl() + "/batch/file?name=" + jar); + HttpResponse response = httpclient.execute(get); + assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200); + EntityUtils.consume(response.getEntity()); + + // As Sonar runner is still using /batch/key, we have to also verify it + get = new HttpGet(orchestrator.getServer().getUrl() + "/batch/" + jar); + response = httpclient.execute(get); + assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200); + EntityUtils.consume(response.getEntity()); + + } finally { + httpclient.getConnectionManager().shutdown(); + } + + // but other java web services should need authentication + try { + orchestrator.getServer().wsClient().get("/api"); + } catch (HttpException e) { + assertThat(e.getMessage()).contains("401"); + } + + } finally { + orchestrator.getServer().getAdminWsClient().delete(new PropertyDeleteQuery("sonar.forceAuthentication")); + } + } + + /** + * SONAR-3320 + */ + @Test + public void global_property_change_extension_point() throws IOException { + orchestrator.getServer().adminWsClient().post("api/properties/create?id=globalPropertyChange.received&value=NEWVALUE"); + assertThat(FileUtils.readFileToString(orchestrator.getServer().getLogs()).contains("Received change: NEWVALUE")); + } + + /** + * SONAR-3962 + */ + @Test + public void not_fail_with_url_ending_by_jsp() { + orchestrator.executeBuild(SonarRunner.create(ItUtils.projectDir("shared/xoo-sample")) + .setProperty("sonar.projectKey", "myproject.jsp")); + // Access dashboard + Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("url_ending_by_jsp", + "/server/ServerTest/url_ending_by_jsp.html").build(); + orchestrator.executeSelenese(selenese); + } + + // SONAR-4404 + @Test + public void should_get_settings_default_value() { + Selenese selenese = Selenese.builder().setHtmlTestsInClasspath("settings-default-value", + "/server/ServerTest/settings-default-value.html").build(); + orchestrator.executeSelenese(selenese); + } + +} diff --git a/it/it-tests/src/test/java/server/suite/ServerTestSuite.java b/it/it-tests/src/test/java/server/suite/ServerTestSuite.java index 75dafab3ef3..dd5897799cc 100644 --- a/it/it-tests/src/test/java/server/suite/ServerTestSuite.java +++ b/it/it-tests/src/test/java/server/suite/ServerTestSuite.java @@ -29,12 +29,20 @@ import util.ItUtils; @RunWith(Suite.class) @Suite.SuiteClasses({ ServerAdministrationTest.class, - WebServiceTest.class + WebServiceTest.class, + ServerTest.class }) public class ServerTestSuite { @ClassRule public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() .addPlugin(ItUtils.xooPlugin()) + + // Used in global_property_change_extension_point + .addPlugin(ItUtils.pluginArtifact("global-property-change-plugin")) + + // Used in should_get_settings_default_value + .addPlugin(ItUtils.pluginArtifact("server-plugin")) + .build(); } -- 2.39.5