From: Simon Brandhof Date: Fri, 10 Nov 2017 13:06:24 +0000 (+0100) Subject: Add category "source" to integration tests X-Git-Tag: 7.0-RC1~331 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=808130822501beb240ec6d19db8b20dc86fc13b8;p=sonarqube.git Add category "source" to integration tests --- diff --git a/cix.sh b/cix.sh index 90b86f23891..0f90a527edc 100755 --- a/cix.sh +++ b/cix.sh @@ -33,6 +33,7 @@ case "$RUN_ACTIVITY" in case "$CATEGORY_GROUP" in Category1) CATEGORY=Category1 && runCategory + CATEGORY=source && runCategory ;; Category2) diff --git a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java index 8b0c9724871..54ff60c0826 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category1Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category1Suite.java @@ -50,9 +50,6 @@ import org.sonarqube.tests.settings.DeprecatedPropertiesWsTest; import org.sonarqube.tests.settings.EmailsTest; import org.sonarqube.tests.settings.PropertySetsTest; import org.sonarqube.tests.settings.SettingsTest; -import org.sonarqube.tests.sourceCode.EncodingTest; -import org.sonarqube.tests.sourceCode.HighlightingTest; -import org.sonarqube.tests.sourceCode.ProjectCodeTest; import org.sonarqube.tests.user.UsersPageTest; import static util.ItUtils.pluginArtifact; @@ -95,10 +92,6 @@ import static util.ItUtils.xooPlugin; SincePreviousVersionHistoryTest.class, SinceXDaysHistoryTest.class, TimeMachineTest.class, - // source code - EncodingTest.class, - HighlightingTest.class, - ProjectCodeTest.class, // complexity ComplexityMeasuresTest.class }) diff --git a/tests/src/test/java/org/sonarqube/tests/Category2Suite.java b/tests/src/test/java/org/sonarqube/tests/Category2Suite.java index b5b27ac1d4b..10e6fbca5dc 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category2Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category2Suite.java @@ -51,7 +51,6 @@ import org.sonarqube.tests.qualityModel.TechnicalDebtAndIssueNewMeasuresTest; import org.sonarqube.tests.qualityModel.TechnicalDebtInIssueChangelogTest; import org.sonarqube.tests.qualityModel.TechnicalDebtTest; import org.sonarqube.tests.rule.RulesPageTest; -import org.sonarqube.tests.scm.ScmTest; import org.sonarqube.tests.test.CoverageTest; import org.sonarqube.tests.test.CoverageTrackingTest; import org.sonarqube.tests.test.NewCoverageTest; @@ -67,8 +66,6 @@ import static util.ItUtils.xooPlugin; CoverageTest.class, NewCoverageTest.class, TestExecutionTest.class, - // scm - ScmTest.class, // issue AutoAssignTest.class, CommonRulesTest.class, diff --git a/tests/src/test/java/org/sonarqube/tests/Category4Suite.java b/tests/src/test/java/org/sonarqube/tests/Category4Suite.java index 6bec598e4c9..f1ff5a039d8 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category4Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category4Suite.java @@ -29,7 +29,6 @@ import org.sonarqube.tests.ce.CeTempDirTest; import org.sonarqube.tests.ce.CeWsTest; import org.sonarqube.tests.component.ComponentsWsTest; import org.sonarqube.tests.component.ProjectsWsTest; -import org.sonarqube.tests.user.RootUserInStandaloneModeTest; import org.sonarqube.tests.projectEvent.ProjectActivityPageTest; import org.sonarqube.tests.qualityProfile.QualityProfilesUiTest; import org.sonarqube.tests.serverSystem.HttpHeadersTest; @@ -37,7 +36,6 @@ import org.sonarqube.tests.serverSystem.LogsTest; import org.sonarqube.tests.serverSystem.PingTest; import org.sonarqube.tests.serverSystem.ServerSystemTest; import org.sonarqube.tests.serverSystem.SystemInfoTest; -import org.sonarqube.tests.ui.SourceViewerTest; import org.sonarqube.tests.ui.UiExtensionsTest; import org.sonarqube.tests.ui.UiTest; import org.sonarqube.tests.user.BaseIdentityProviderTest; @@ -46,6 +44,7 @@ import org.sonarqube.tests.user.ForceAuthenticationTest; import org.sonarqube.tests.user.LocalAuthenticationTest; import org.sonarqube.tests.user.MyAccountPageTest; import org.sonarqube.tests.user.OAuth2IdentityProviderTest; +import org.sonarqube.tests.user.RootUserInStandaloneModeTest; import org.sonarqube.tests.ws.WsLocalCallTest; import org.sonarqube.tests.ws.WsTest; @@ -80,7 +79,6 @@ import static util.ItUtils.xooPlugin; HttpHeadersTest.class, // ui UiTest.class, - SourceViewerTest.class, // ui extensions UiExtensionsTest.class, WsLocalCallTest.class, diff --git a/tests/src/test/java/org/sonarqube/tests/scm/ScmTest.java b/tests/src/test/java/org/sonarqube/tests/scm/ScmTest.java deleted file mode 100644 index 16cc5fbe942..00000000000 --- a/tests/src/test/java/org/sonarqube/tests/scm/ScmTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.sonarqube.tests.scm; - -import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.build.BuildResult; -import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category2Suite; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.assertj.core.data.MapEntry; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.sonar.wsclient.jsonsimple.JSONArray; -import org.sonar.wsclient.jsonsimple.JSONObject; -import org.sonar.wsclient.jsonsimple.JSONValue; - -import static org.assertj.core.api.Assertions.assertThat; -import static util.ItUtils.projectDir; - -public class ScmTest { - - @ClassRule - public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR; - - private static final SimpleDateFormat DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); - - @Before - public void delete_data() { - orchestrator.resetData(); - } - - @Test - public void scm_optimization() throws Exception { - SonarScanner build = SonarScanner.create(projectDir("scm/xoo-sample-with-scm")) - .setProperty("sonar.scm.provider", "xoo") - .setProperty("sonar.scm.disabled", "false"); - - // First run - BuildResult buildResult = orchestrator.executeBuild(build); - - assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")) - .containsExactly( - MapEntry.entry(1, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), - MapEntry.entry(3, new LineData("2", "2013-01-04T00:00:00+0000", "jhenry")), - MapEntry.entry(4, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), - MapEntry.entry(8, new LineData("3", "2014-01-04T00:00:00+0000", "toto"))); - - assertThat(buildResult.getLogs()).containsSequence("1 files to be analyzed", "1/1 files analyzed"); - - // Second run with same file should not trigger blame but SCM data are copied from previous analysis - buildResult = orchestrator.executeBuild(build); - - assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")) - .containsExactly( - MapEntry.entry(1, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), - MapEntry.entry(3, new LineData("2", "2013-01-04T00:00:00+0000", "jhenry")), - MapEntry.entry(4, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), - MapEntry.entry(8, new LineData("3", "2014-01-04T00:00:00+0000", "toto"))); - - assertThat(buildResult.getLogs()).doesNotContain("1 files to be analyzed"); - assertThat(buildResult.getLogs()).doesNotContain("1/1 files analyzed"); - - // Now if SCM is explicitely disabled it should clear SCM data on server side - buildResult = orchestrator.executeBuild(build.setProperty("sonar.scm.disabled", "true")); - - assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")).isEmpty(); - - assertThat(buildResult.getLogs()).doesNotContain("1 files to be analyzed"); - assertThat(buildResult.getLogs()).doesNotContain("1/1 files analyzed"); - } - - private class LineData { - - final String revision; - final Date date; - final String author; - - public LineData(String revision, String datetime, String author) throws ParseException { - this.revision = revision; - this.date = DATETIME_FORMAT.parse(datetime); - this.author = author; - } - - @Override - public boolean equals(Object obj) { - return EqualsBuilder.reflectionEquals(this, obj); - } - - @Override - public int hashCode() { - return new HashCodeBuilder().append(revision).append(date).append(author).toHashCode(); - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this, ToStringStyle.SIMPLE_STYLE); - } - } - - private Map getScmData(String fileKey) throws ParseException { - Map result = new HashMap<>(); - String json = orchestrator.getServer().adminWsClient().get("api/sources/scm", "key", fileKey); - JSONObject obj = (JSONObject) JSONValue.parse(json); - JSONArray array = (JSONArray) obj.get("scm"); - for (Object anArray : array) { - JSONArray item = (JSONArray) anArray; - String datetime = (String) item.get(2); - result.put(((Long) item.get(0)).intValue(), new LineData((String) item.get(3), datetime, (String) item.get(1))); - } - return result; - } - -} diff --git a/tests/src/test/java/org/sonarqube/tests/source/EncodingTest.java b/tests/src/test/java/org/sonarqube/tests/source/EncodingTest.java new file mode 100644 index 00000000000..ea9ef78292e --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/source/EncodingTest.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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.sonarqube.tests.source; + +import com.sonar.orchestrator.Orchestrator; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.qa.util.Tester; +import util.selenium.Selenese; + +import static util.ItUtils.runProjectAnalysis; + +public class EncodingTest { + + @ClassRule + public static Orchestrator orchestrator = SourceSuite.ORCHESTRATOR; + + @Rule + public Tester tester = new Tester(orchestrator); + + @Test + public void support_japanese_charset() { + runProjectAnalysis(orchestrator, "sourceCode/japanese-charset", "sonar.sourceEncoding", "Shift_JIS"); + + Selenese.runSelenese(orchestrator, "/sourceCode/EncodingTest/japanese_sources.html"); + } +} diff --git a/tests/src/test/java/org/sonarqube/tests/source/ProjectCodeTest.java b/tests/src/test/java/org/sonarqube/tests/source/ProjectCodeTest.java new file mode 100644 index 00000000000..974ea41abf3 --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/source/ProjectCodeTest.java @@ -0,0 +1,95 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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.sonarqube.tests.source; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.SonarScanner; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.qa.util.Tester; +import org.sonarqube.ws.WsProjects.CreateWsResponse.Project; + +import static util.ItUtils.projectDir; + +public class ProjectCodeTest { + + @ClassRule + public static Orchestrator orchestrator = SourceSuite.ORCHESTRATOR; + + @Rule + public Tester tester = new Tester(orchestrator); + + @Test + public void browse() { + Project project = tester.projects().generate(null); + executeAnalysis(project); + + tester.openBrowser().openCode(project.getKey()) + .shouldHaveComponent("src/main/xoo/sample") + .openFirstComponent() + .shouldHaveComponent("Sample.xoo") + .openFirstComponent() + .shouldHaveCode("public class Sample") + .shouldHaveBreadcrumbs(project.getName(), "src/main/xoo/sample", "Sample.xoo"); + } + + @Test + public void search() { + Project project = tester.projects().generate(null); + executeAnalysis(project); + + tester.openBrowser().openCode(project.getKey()) + .shouldHaveComponent(project.getName()) + .search("xoo") + .shouldSearchResult("Sample.xoo"); + } + + @Test + public void permalink() { + Project project = tester.projects().generate(null); + executeAnalysis(project); + + tester.openBrowser().openCode(project.getKey(), project.getKey() + "%3Asrc%2Fmain%2Fxoo%2Fsample%2FSample.xoo") + .shouldHaveCode("public class Sample") + .shouldHaveBreadcrumbs(project.getName(), "src/main/xoo/sample", "Sample.xoo"); + } + + @Test + public void expand_root_dir() { + Project project = tester.projects().generate(null); + executeAnalysis(project, "shared/xoo-sample-with-root-dir"); + + tester.openBrowser().openCode(project.getKey()) + .shouldHaveComponent("Hello.xoo") + .shouldHaveComponent("src/main/xoo/sample"); + } + + private void executeAnalysis(Project project, String path) { + orchestrator.executeBuild( + SonarScanner.create(projectDir(path)) + .setProjectKey(project.getKey()) + .setProjectName(project.getName())); + } + + private void executeAnalysis(Project project) { + executeAnalysis(project, "shared/xoo-sample"); + } +} diff --git a/tests/src/test/java/org/sonarqube/tests/source/ScmTest.java b/tests/src/test/java/org/sonarqube/tests/source/ScmTest.java new file mode 100644 index 00000000000..91b0030d59d --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/source/ScmTest.java @@ -0,0 +1,140 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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.sonarqube.tests.source; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.BuildResult; +import com.sonar.orchestrator.build.SonarScanner; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; +import org.assertj.core.data.MapEntry; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.wsclient.jsonsimple.JSONArray; +import org.sonar.wsclient.jsonsimple.JSONObject; +import org.sonar.wsclient.jsonsimple.JSONValue; +import org.sonarqube.qa.util.Tester; + +import static org.assertj.core.api.Assertions.assertThat; +import static util.ItUtils.projectDir; + +public class ScmTest { + + @ClassRule + public static Orchestrator orchestrator = SourceSuite.ORCHESTRATOR; + + private static final SimpleDateFormat DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + + @Rule + public Tester tester = new Tester(orchestrator); + + /** + * SONAR-6897 + */ + @Test + public void load_scm_from_previous_analysis_if_scm_missing_in_analysis() throws Exception { + SonarScanner build = SonarScanner.create(projectDir("scm/xoo-sample-with-scm")) + .setProperty("sonar.scm.provider", "xoo") + .setProperty("sonar.scm.disabled", "false"); + + // First run + BuildResult buildResult = orchestrator.executeBuild(build); + + assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")) + .containsExactly( + MapEntry.entry(1, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), + MapEntry.entry(3, new LineData("2", "2013-01-04T00:00:00+0000", "jhenry")), + MapEntry.entry(4, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), + MapEntry.entry(8, new LineData("3", "2014-01-04T00:00:00+0000", "toto"))); + + assertThat(buildResult.getLogs()).containsSequence("1 files to be analyzed", "1/1 files analyzed"); + + // Second run with same file should not trigger blame but SCM data are copied from previous analysis + buildResult = orchestrator.executeBuild(build); + + assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")) + .containsExactly( + MapEntry.entry(1, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), + MapEntry.entry(3, new LineData("2", "2013-01-04T00:00:00+0000", "jhenry")), + MapEntry.entry(4, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), + MapEntry.entry(8, new LineData("3", "2014-01-04T00:00:00+0000", "toto"))); + + assertThat(buildResult.getLogs()).doesNotContain("1 files to be analyzed"); + assertThat(buildResult.getLogs()).doesNotContain("1/1 files analyzed"); + + // Now if SCM is explicitely disabled it should clear SCM data on server side + buildResult = orchestrator.executeBuild(build.setProperty("sonar.scm.disabled", "true")); + + assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")).isEmpty(); + + assertThat(buildResult.getLogs()).doesNotContain("1 files to be analyzed"); + assertThat(buildResult.getLogs()).doesNotContain("1/1 files analyzed"); + } + + private class LineData { + + final String revision; + final Date date; + final String author; + + public LineData(String revision, String datetime, String author) throws ParseException { + this.revision = revision; + this.date = DATETIME_FORMAT.parse(datetime); + this.author = author; + } + + @Override + public boolean equals(Object obj) { + return EqualsBuilder.reflectionEquals(this, obj); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(revision).append(date).append(author).toHashCode(); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.SIMPLE_STYLE); + } + } + + private Map getScmData(String fileKey) throws ParseException { + Map result = new HashMap<>(); + String json = orchestrator.getServer().adminWsClient().get("api/sources/scm", "key", fileKey); + JSONObject obj = (JSONObject) JSONValue.parse(json); + JSONArray array = (JSONArray) obj.get("scm"); + for (Object anArray : array) { + JSONArray item = (JSONArray) anArray; + String datetime = (String) item.get(2); + result.put(((Long) item.get(0)).intValue(), new LineData((String) item.get(3), datetime, (String) item.get(1))); + } + return result; + } + +} diff --git a/tests/src/test/java/org/sonarqube/tests/source/SourceSuite.java b/tests/src/test/java/org/sonarqube/tests/source/SourceSuite.java new file mode 100644 index 00000000000..90fb2a72988 --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/source/SourceSuite.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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.sonarqube.tests.source; + +import com.sonar.orchestrator.Orchestrator; +import org.junit.ClassRule; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +import static util.ItUtils.xooPlugin; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + EncodingTest.class, + ProjectCodeTest.class, + ScmTest.class, + SourceViewerTest.class +}) +public class SourceSuite { + + @ClassRule + public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() + .addPlugin(xooPlugin()) + // reduce memory for Elasticsearch + .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m") + .build(); + +} diff --git a/tests/src/test/java/org/sonarqube/tests/source/SourceViewerTest.java b/tests/src/test/java/org/sonarqube/tests/source/SourceViewerTest.java new file mode 100644 index 00000000000..ed24305774c --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/source/SourceViewerTest.java @@ -0,0 +1,76 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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.sonarqube.tests.source; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.SonarScanner; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.qa.util.Tester; +import org.sonarqube.qa.util.pageobjects.Navigation; +import util.selenium.Selenese; + +import static com.codeborne.selenide.Condition.exist; +import static com.codeborne.selenide.Selenide.$; +import static util.ItUtils.projectDir; +import static util.ItUtils.runProjectAnalysis; + +public class SourceViewerTest { + + @ClassRule + public static Orchestrator orchestrator = SourceSuite.ORCHESTRATOR; + + @Rule + public Tester tester = new Tester(orchestrator); + + @Test + public void line_permalink() { + orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"))); + Navigation navigation = tester.openBrowser(); + navigation.open("/component?id=sample%3Asrc%2Fmain%2Fxoo%2Fsample%2FSample.xoo&line=6"); + $(".source-line").should(exist); + $(".source-line-highlighted[data-line-number=\"6\"]").should(exist); + } + + @Test + public void highlight_source_code_and_symbols_usage() { + runProjectAnalysis(orchestrator, "highlighting/xoo-sample-with-highlighting-v2"); + + // SONAR-3893 & SONAR-4247 + Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/syntax-highlighting.html"); + + // SONAR-4249 & SONAR-4250 + Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/symbol-usages-highlighting.html"); + } + + // Check that E/S index is updated when file content is unchanged but plugin generates different syntax/symbol highlighting + @Test + public void update_highlighting_even_when_code_unchanged() { + runProjectAnalysis(orchestrator, "highlighting/xoo-sample-with-highlighting-v1"); + + Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/syntax-highlighting-v1.html"); + + runProjectAnalysis(orchestrator, "highlighting/xoo-sample-with-highlighting-v2"); + + Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/syntax-highlighting-v2.html"); + Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/symbol-usages-highlighting.html"); + } +} diff --git a/tests/src/test/java/org/sonarqube/tests/sourceCode/EncodingTest.java b/tests/src/test/java/org/sonarqube/tests/sourceCode/EncodingTest.java deleted file mode 100644 index 397b83d5fbd..00000000000 --- a/tests/src/test/java/org/sonarqube/tests/sourceCode/EncodingTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.sonarqube.tests.sourceCode; - -import com.sonar.orchestrator.Orchestrator; -import org.sonarqube.tests.Category1Suite; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.sonarqube.qa.util.Tester; -import util.selenium.Selenese; - -import static util.ItUtils.runProjectAnalysis; - -public class EncodingTest { - - @ClassRule - public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; - - @Rule - public Tester tester = new Tester(orchestrator).disableOrganizations(); - - @Test - public void support_japanese_charset() { - runProjectAnalysis(orchestrator, "sourceCode/japanese-charset", "sonar.sourceEncoding", "Shift_JIS"); - - Selenese.runSelenese(orchestrator, "/sourceCode/EncodingTest/japanese_sources.html"); - } -} diff --git a/tests/src/test/java/org/sonarqube/tests/sourceCode/HighlightingTest.java b/tests/src/test/java/org/sonarqube/tests/sourceCode/HighlightingTest.java deleted file mode 100644 index 1f20c8c0700..00000000000 --- a/tests/src/test/java/org/sonarqube/tests/sourceCode/HighlightingTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.sonarqube.tests.sourceCode; - -import com.sonar.orchestrator.Orchestrator; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.sonarqube.qa.util.Tester; -import org.sonarqube.tests.Category1Suite; -import util.selenium.Selenese; - -import static util.ItUtils.runProjectAnalysis; - -public class HighlightingTest { - - @ClassRule - public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; - - @Rule - public Tester tester = new Tester(orchestrator).disableOrganizations(); - - @Test - public void highlight_source_code_and_symbols_usage() { - runProjectAnalysis(orchestrator, "highlighting/xoo-sample-with-highlighting-v2"); - - // SONAR-3893 & SONAR-4247 - Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/syntax-highlighting.html"); - - // SONAR-4249 & SONAR-4250 - Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/symbol-usages-highlighting.html"); - } - - // Check that E/S index is updated when file content is unchanged but plugin generates different syntax/symbol highlighting - @Test - public void update_highlighting_even_when_code_unchanged() { - runProjectAnalysis(orchestrator, "highlighting/xoo-sample-with-highlighting-v1"); - - Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/syntax-highlighting-v1.html"); - - runProjectAnalysis(orchestrator, "highlighting/xoo-sample-with-highlighting-v2"); - - Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/syntax-highlighting-v2.html"); - Selenese.runSelenese(orchestrator, "/sourceCode/HighlightingTest/symbol-usages-highlighting.html"); - } -} diff --git a/tests/src/test/java/org/sonarqube/tests/sourceCode/ProjectCodeTest.java b/tests/src/test/java/org/sonarqube/tests/sourceCode/ProjectCodeTest.java deleted file mode 100644 index 0ee1c7ee0af..00000000000 --- a/tests/src/test/java/org/sonarqube/tests/sourceCode/ProjectCodeTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.sonarqube.tests.sourceCode; - -import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.build.SonarScanner; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.sonarqube.tests.Category1Suite; -import org.sonarqube.qa.util.Tester; -import org.sonarqube.ws.WsProjects.CreateWsResponse.Project; - -import static util.ItUtils.projectDir; - -public class ProjectCodeTest { - - @ClassRule - public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; - - @Rule - public Tester tester = new Tester(orchestrator).disableOrganizations(); - - @Test - public void browse() { - Project project = tester.projects().generate(null); - executeAnalysis(project); - - tester.openBrowser().openCode(project.getKey()) - .shouldHaveComponent("src/main/xoo/sample") - .openFirstComponent() - .shouldHaveComponent("Sample.xoo") - .openFirstComponent() - .shouldHaveCode("public class Sample") - .shouldHaveBreadcrumbs(project.getName(), "src/main/xoo/sample", "Sample.xoo"); - } - - @Test - public void search() { - Project project = tester.projects().generate(null); - executeAnalysis(project); - - tester.openBrowser().openCode(project.getKey()) - .shouldHaveComponent(project.getName()) - .search("xoo") - .shouldSearchResult("Sample.xoo"); - } - - @Test - public void permalink() { - Project project = tester.projects().generate(null); - executeAnalysis(project); - - tester.openBrowser().openCode(project.getKey(), project.getKey() + "%3Asrc%2Fmain%2Fxoo%2Fsample%2FSample.xoo") - .shouldHaveCode("public class Sample") - .shouldHaveBreadcrumbs(project.getName(), "src/main/xoo/sample", "Sample.xoo"); - } - - @Test - public void expand_root_dir() { - Project project = tester.projects().generate(null); - executeAnalysis(project, "shared/xoo-sample-with-root-dir"); - - tester.openBrowser().openCode(project.getKey()) - .shouldHaveComponent("Hello.xoo") - .shouldHaveComponent("src/main/xoo/sample"); - } - - private void executeAnalysis(Project project, String path) { - orchestrator.executeBuild( - SonarScanner.create(projectDir(path)) - .setProjectKey(project.getKey()) - .setProjectName(project.getName())); - } - - private void executeAnalysis(Project project) { - executeAnalysis(project, "shared/xoo-sample"); - } -} diff --git a/tests/src/test/java/org/sonarqube/tests/ui/SourceViewerTest.java b/tests/src/test/java/org/sonarqube/tests/ui/SourceViewerTest.java deleted file mode 100644 index f37daa3229f..00000000000 --- a/tests/src/test/java/org/sonarqube/tests/ui/SourceViewerTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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.sonarqube.tests.ui; - -import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.build.SonarScanner; -import org.sonarqube.tests.Category4Suite; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.sonarqube.qa.util.pageobjects.Navigation; - -import static com.codeborne.selenide.Condition.exist; -import static com.codeborne.selenide.Selenide.$; -import static util.ItUtils.projectDir; - -public class SourceViewerTest { - - @ClassRule - public static final Orchestrator ORCHESTRATOR = Category4Suite.ORCHESTRATOR; - - private Navigation nav = Navigation.create(ORCHESTRATOR); - - @BeforeClass - public static void beforeClass() { - ORCHESTRATOR.resetData(); - analyzeSampleProject(); - } - - @Test - public void line_permalink() { - nav.open("/component?id=sample%3Asrc%2Fmain%2Fxoo%2Fsample%2FSample.xoo&line=6"); - $(".source-line").should(exist); - $(".source-line-highlighted[data-line-number=\"6\"]").should(exist); - } - - private static void analyzeSampleProject() { - ORCHESTRATOR.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"))); - } -}