diff options
Diffstat (limited to 'it/it-tests')
12 files changed, 311 insertions, 138 deletions
diff --git a/it/it-tests/src/test/java/it/Category1Suite.java b/it/it-tests/src/test/java/it/Category1Suite.java index 81789bc67ee..97489650fcc 100644 --- a/it/it-tests/src/test/java/it/Category1Suite.java +++ b/it/it-tests/src/test/java/it/Category1Suite.java @@ -45,6 +45,7 @@ import it.administration.UsersUITest; import it.authorisation.AuthenticationTest; import it.authorisation.IssuePermissionTest; import it.authorisation.PermissionTest; +import it.authorisation.ScanPermissionTest; import it.i18n.I18nTest; import it.measureHistory.DifferentialPeriodsTest; import it.measureHistory.HistoryUiTest; @@ -92,6 +93,7 @@ import static util.ItUtils.xooPlugin; AuthenticationTest.class, PermissionTest.class, IssuePermissionTest.class, + ScanPermissionTest.class, // measure history DifferentialPeriodsTest.class, HistoryUiTest.class, diff --git a/it/it-tests/src/test/java/it/analysis/IssuesModeTest.java b/it/it-tests/src/test/java/it/analysis/IssuesModeTest.java index 14749d888fd..40c5866655f 100644 --- a/it/it-tests/src/test/java/it/analysis/IssuesModeTest.java +++ b/it/it-tests/src/test/java/it/analysis/IssuesModeTest.java @@ -5,8 +5,6 @@ */ package it.analysis; -import org.apache.commons.io.FileUtils; -import org.sonar.wsclient.issue.IssueClient; import com.google.common.collect.Maps; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.BuildFailureException; @@ -17,7 +15,6 @@ import com.sonar.orchestrator.config.FileSystem; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.version.Version; import it.Category3Suite; - import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -29,7 +26,8 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; - +import javax.annotation.Nullable; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.ObjectUtils; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -41,12 +39,14 @@ import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.wsclient.SonarClient; import org.sonar.wsclient.issue.Issue; +import org.sonar.wsclient.issue.IssueClient; import org.sonar.wsclient.issue.IssueQuery; import org.sonar.wsclient.issue.Issues; import org.sonar.wsclient.services.Resource; import org.sonar.wsclient.services.ResourceQuery; import org.sonar.wsclient.user.UserParameters; import util.ItUtils; + import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -71,7 +71,7 @@ public class IssuesModeTest { restoreProfile("one-issue-per-line.xml"); orchestrator.getServer().provisionProject("sample", "xoo-sample"); orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line"); - SonarRunner runner = configureRunnerIssues("shared/xoo-sample", "sonar.verbose", "true"); + SonarRunner runner = configureRunnerIssues("shared/xoo-sample", null, "sonar.verbose", "true"); BuildResult result = orchestrator.executeBuild(runner); assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17); } @@ -122,7 +122,7 @@ public class IssuesModeTest { orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "with-many-rules"); // do it again, scanning nothing (all files should be unchanged) - runner = configureRunnerIssues("shared/xoo-sample", + runner = configureRunnerIssues("shared/xoo-sample", null, "sonar.verbose", "true"); result = orchestrator.executeBuild(runner); assertThat(result.getLogs()).contains("Scanning only changed files"); @@ -151,7 +151,7 @@ public class IssuesModeTest { issueClient.doTransition(serverIssues.get(1).key(), "wontfix"); // do it again, scanning nothing (all files should be unchanged) - runner = configureRunnerIssues("shared/xoo-sample", + runner = configureRunnerIssues("shared/xoo-sample", null, "sonar.verbose", "true"); result = orchestrator.executeBuild(runner); assertThat(result.getLogs()).contains("Scanning only changed files"); @@ -197,7 +197,7 @@ public class IssuesModeTest { public void non_associated_mode() throws IOException { restoreProfile("one-issue-per-line.xml"); setDefaultQualityProfile("xoo", "one-issue-per-line"); - SonarRunner runner = configureRunnerIssues("shared/xoo-sample-non-associated"); + SonarRunner runner = configureRunnerIssues("shared/xoo-sample-non-associated", null); BuildResult result = orchestrator.executeBuild(runner); assertThat(result.getLogs()).contains("Local analysis"); @@ -220,7 +220,7 @@ public class IssuesModeTest { BuildResult result = orchestrator.executeBuild(runner); assertThat(getResource("sample:my sources/main/xoo/sample/My Sample.xoo")).isNotNull(); - runner = configureRunnerIssues("analysis/xoo-sample-with-spaces/v2"); + runner = configureRunnerIssues("analysis/xoo-sample-with-spaces/v2", null); result = orchestrator.executeBuild(runner); // Analysis is not persisted in database Resource project = getResource("com.sonarsource.it.samples:simple-sample"); @@ -246,7 +246,7 @@ public class IssuesModeTest { assertThat(getResource("sample:src/main/xoo/sample/ClassAdded.xoo")).isNull(); // Re-add ClassAdded.xoo in local workspace - runner = configureRunnerIssues("shared/xoo-history-v2"); + runner = configureRunnerIssues("shared/xoo-history-v2", null); result = orchestrator.executeBuild(runner); assertThat(getResource("sample:src/main/xoo/sample/ClassAdded.xoo")).isNull(); @@ -257,7 +257,7 @@ public class IssuesModeTest { @Test public void should_fail_if_plugin_access_secured_properties() throws IOException { // Test access from task (ie BatchSettings) - SonarRunner runner = configureRunnerIssues("shared/xoo-sample", + SonarRunner runner = configureRunnerIssues("shared/xoo-sample", null, "accessSecuredFromTask", "true"); BuildResult result = orchestrator.executeBuildQuietly(runner); @@ -265,7 +265,7 @@ public class IssuesModeTest { + "The SonarQube plugin which requires this property must be deactivated in issues mode."); // Test access from sensor (ie ModuleSettings) - runner = configureRunnerIssues("shared/xoo-sample", + runner = configureRunnerIssues("shared/xoo-sample", null, "accessSecuredFromSensor", "true"); result = orchestrator.executeBuildQuietly(runner); @@ -275,74 +275,31 @@ public class IssuesModeTest { // SONAR-4602 @Test - public void no_issues_mode_cache_after_new_analysis() throws Exception { - restoreProfile("one-issue-per-line.xml"); - restoreProfile("empty.xml"); - orchestrator.getServer().provisionProject("sample", "xoo-sample"); - - // First run (publish mode) - orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "empty"); - SonarRunner runner = configureRunner("shared/xoo-sample"); - orchestrator.executeBuild(runner); + public void no_issues_mode_cache_by_default() throws Exception { + File homeDir = runFirstAnalysisAndFlagIssueAsWontFix(); - // First run issues mode - orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line"); - runner = configureRunnerIssues("shared/xoo-sample", - "sonar.scanAllFiles", "true"); + // Second issues mode using same cache dir but cache disabled by default + SonarRunner runner = configureRunnerIssues("shared/xoo-sample", homeDir); BuildResult result = orchestrator.executeBuild(runner); - // As many new issue as lines - assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17); - - // Second run (publish mode) should invalidate cache - runner = configureRunner("shared/xoo-sample"); - orchestrator.executeBuild(runner); - - // Second run issues mode - runner = configureRunnerIssues("shared/xoo-sample", - "sonar.report.export.path", "sonar-report.json", - "sonar.scanAllFiles", "true"); - result = orchestrator.executeBuild(runner); - - // No new issue this time - assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(0); + // False positive is not returned + assertThat(ItUtils.countIssuesInJsonReport(result, false)).isEqualTo(16); } - // SONAR-4602 + // SONAR-7100 @Test - public void no_issues_mode_cache_after_profile_change() throws Exception { - restoreProfile("one-issue-per-line-empty.xml"); - orchestrator.getServer().provisionProject("sample", "xoo-sample"); - orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line"); - - // First run (publish mode) - SonarRunner runner = configureRunner("shared/xoo-sample"); - orchestrator.executeBuild(runner); + public void enable_issues_cache() throws Exception { + File homeDir = runFirstAnalysisAndFlagIssueAsWontFix(); - // First issues mode - runner = configureRunnerIssues("shared/xoo-sample", - "sonar.scanAllFiles", "true"); + // Second issues mode using same cache dir and enable cache + SonarRunner runner = configureRunnerIssues("shared/xoo-sample", homeDir, "sonar.useWsCache", "true"); BuildResult result = orchestrator.executeBuild(runner); - // No new issues - assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(0); - - // Modification of QP should invalidate cache - restoreProfile("/one-issue-per-line.xml"); - - // Second issues mode - runner = configureRunnerIssues("shared/xoo-sample", - "sonar.report.export.path", "sonar-report.json", - "sonar.scanAllFiles", "true"); - result = orchestrator.executeBuild(runner); - - // As many new issue as lines - assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17); + // False positive is still visible since we are using cached issues + assertThat(ItUtils.countIssuesInJsonReport(result, false)).isEqualTo(17); } - // SONAR-4602 - @Test - public void no_issues_mode_cache_after_issue_change() throws Exception { + private File runFirstAnalysisAndFlagIssueAsWontFix() throws IOException { restoreProfile("one-issue-per-line.xml"); orchestrator.getServer().provisionProject("sample", "xoo-sample"); orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line"); @@ -352,7 +309,8 @@ public class IssuesModeTest { orchestrator.executeBuild(runner); // First issues mode - runner = configureRunnerIssues("shared/xoo-sample"); + File homeDir = temp.newFolder(); + runner = configureRunnerIssues("shared/xoo-sample", homeDir); BuildResult result = orchestrator.executeBuild(runner); // 17 issues @@ -362,13 +320,7 @@ public class IssuesModeTest { JSONObject obj = ItUtils.getJSONReport(result); String key = ((JSONObject) ((JSONArray) obj.get("issues")).get(0)).get("key").toString(); orchestrator.getServer().adminWsClient().issueClient().doTransition(key, "falsepositive"); - - // Second issues mode - runner = configureRunnerIssues("shared/xoo-sample"); - result = orchestrator.executeBuild(runner); - - // False positive is not returned - assertThat(ItUtils.countIssuesInJsonReport(result, false)).isEqualTo(16); + return homeDir; } // SONAR-6522 @@ -395,7 +347,7 @@ public class IssuesModeTest { client.issueClient().assign(issue.key(), "julien"); // Issues - runner = configureRunnerIssues("shared/xoo-sample"); + runner = configureRunnerIssues("shared/xoo-sample", null); BuildResult result = orchestrator.executeBuild(runner); JSONObject obj = ItUtils.getJSONReport(result); @@ -433,18 +385,19 @@ public class IssuesModeTest { runConcurrentIssues(); } - private void runConcurrentIssues() throws InterruptedException, ExecutionException { + private void runConcurrentIssues() throws Exception { // Install sonar-runner in advance to avoid concurrent unzip issues FileSystem fileSystem = orchestrator.getConfiguration().fileSystem(); new SonarRunnerInstaller(fileSystem).install(Version.create(SonarRunner.DEFAULT_RUNNER_VERSION), fileSystem.workspace()); final int nThreads = 3; ExecutorService executorService = Executors.newFixedThreadPool(nThreads); List<Callable<BuildResult>> tasks = new ArrayList<>(); + final File homeDir = temp.newFolder(); for (int i = 0; i < nThreads; i++) { tasks.add(new Callable<BuildResult>() { public BuildResult call() throws Exception { - SonarRunner runner = configureRunnerIssues("shared/xoo-sample"); + SonarRunner runner = configureRunnerIssues("shared/xoo-sample", homeDir, "sonar.it.enableWaitingSensor", "true"); return orchestrator.executeBuild(runner); } }); @@ -459,6 +412,8 @@ public class IssuesModeTest { BuildFailureException bfe = (BuildFailureException) e.getCause(); assertThat(bfe.getResult().getLogs()).contains("Another SonarQube analysis is already in progress for this project"); expectedError = true; + } else { + throw e; } } } @@ -475,12 +430,16 @@ public class IssuesModeTest { return orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics(key, "lines")); } - private SonarRunner configureRunnerIssues(String projectDir, String... props) throws IOException { + private SonarRunner configureRunnerIssues(String projectDir, @Nullable File homeDir, String... props) throws IOException { SonarRunner runner = SonarRunner.create(ItUtils.projectDir(projectDir), "sonar.working.directory", temp.newFolder().getAbsolutePath(), "sonar.analysis.mode", "issues", - "sonar.report.export.path", "sonar-report.json", - "sonar.userHome", temp.newFolder().getAbsolutePath()); + "sonar.report.export.path", "sonar-report.json"); + if (homeDir != null) { + runner.setProperty("sonar.userHome", homeDir.getAbsolutePath()); + } else { + runner.setProperty("sonar.userHome", temp.newFolder().getAbsolutePath()); + } runner.setProperties(props); return runner; } diff --git a/it/it-tests/src/test/java/it/authorisation/AuthenticationTest.java b/it/it-tests/src/test/java/it/authorisation/AuthenticationTest.java index 7288287edbe..806b6935183 100644 --- a/it/it-tests/src/test/java/it/authorisation/AuthenticationTest.java +++ b/it/it-tests/src/test/java/it/authorisation/AuthenticationTest.java @@ -93,7 +93,7 @@ public class AuthenticationTest { // authenticate WsClient wsClient = new HttpWsClient(new HttpConnector.Builder().url(ORCHESTRATOR.getServer().getUrl()).credentials(login, password).build()); WsResponse response = wsClient.wsConnector().call(new GetRequest("api/authentication/validate")); - assertThat(response.getContent()).isEqualTo("{\"valid\":true}"); + assertThat(response.content()).isEqualTo("{\"valid\":true}"); } @Test @@ -107,7 +107,7 @@ public class AuthenticationTest { WsResponse response = wsClient.wsConnector().call(new GetRequest("api/authentication/validate")); - assertThat(response.getContent()).isEqualTo("{\"valid\":true}"); + assertThat(response.content()).isEqualTo("{\"valid\":true}"); } /** @@ -126,7 +126,7 @@ public class AuthenticationTest { // authenticate WsClient wsClient = new HttpWsClient(new HttpConnector.Builder().url(ORCHESTRATOR.getServer().getUrl()).credentials(login, password).build()); WsResponse response = wsClient.wsConnector().call(new GetRequest("api/authentication/validate")); - assertThat(response.getContent()).isEqualTo("{\"valid\":false}"); + assertThat(response.content()).isEqualTo("{\"valid\":false}"); } @Test diff --git a/it/it-tests/src/test/java/it/authorisation/ScanPermissionTest.java b/it/it-tests/src/test/java/it/authorisation/ScanPermissionTest.java new file mode 100644 index 00000000000..141c10eed9c --- /dev/null +++ b/it/it-tests/src/test/java/it/authorisation/ScanPermissionTest.java @@ -0,0 +1,116 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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 it.authorisation; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.BuildFailureException; +import it.Category1Suite; +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonar.wsclient.SonarClient; +import org.sonar.wsclient.user.UserParameters; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; +import static util.ItUtils.runProjectAnalysis; + +/** + * SONAR-4397 + */ +public class ScanPermissionTest { + + @ClassRule + public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR; + + private final static String USER_LOGIN = "scanperm"; + + private static SonarClient adminClient; + + @Before + public void setUp() { + orchestrator.resetData(); + adminClient = orchestrator.getServer().adminWsClient(); + adminClient.userClient().create(UserParameters.create().login(USER_LOGIN).name(USER_LOGIN).password("thewhite").passwordConfirmation("thewhite")); + } + + @After + public void teraDown() { + addPermission("anyone", "scan"); + addPermission("anyone", "dryRunScan"); + adminClient.userClient().deactivate(USER_LOGIN); + } + + @Test + public void should_fail_if_no_scan_permission() throws Exception { + runProjectAnalysis(orchestrator, "shared/xoo-sample", "sonar.login", USER_LOGIN, "sonar.password", "thewhite"); + + removeGroupPermission("anyone", "scan"); + try { + runProjectAnalysis(orchestrator, "shared/xoo-sample", "sonar.login", USER_LOGIN, "sonar.password", "thewhite"); + fail(); + } catch (BuildFailureException e) { + assertThat(e.getResult().getLogs()).contains( + "You're only authorized to execute a local (preview) SonarQube analysis without pushing the results to the SonarQube server. Please contact your SonarQube administrator."); + } + + // Remove Anyone from dryrun permission + removeGroupPermission("anyone", "dryRunScan"); + try { + runProjectAnalysis(orchestrator, "shared/xoo-sample", "sonar.login", USER_LOGIN, "sonar.password", "thewhite"); + fail(); + } catch (BuildFailureException e) { + assertThat(e.getResult().getLogs()).contains( + "You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator."); + } + } + + @Test + public void no_need_for_browse_permission_to_scan() throws Exception { + // Do a first analysis, no error + runProjectAnalysis(orchestrator, "shared/xoo-sample", "sonar.login", USER_LOGIN, "sonar.password", "thewhite"); + + // Remove browse permission for groups Anyone on the project + removeGroupPermission("anyone", "sample", "user"); + + // still no error + runProjectAnalysis(orchestrator, "shared/xoo-sample", "sonar.login", USER_LOGIN, "sonar.password", "thewhite"); + } + + private static void addPermission(String groupName, String permission) { + adminClient.post("api/permissions/add_group", + "groupName", groupName, + "permission", permission); + } + + private static void removeGroupPermission(String groupName, String permission) { + adminClient.post("api/permissions/remove_group", + "groupName", groupName, + "permission", permission); + } + + private static void removeGroupPermission(String groupName, String projectKey, String permission) { + adminClient.post("api/permissions/remove_group", + "groupName", groupName, + "projectKey", projectKey, + "permission", permission); + } +} diff --git a/it/it-tests/src/test/java/it/debt/DebtConfigurationRule.java b/it/it-tests/src/test/java/it/debt/DebtConfigurationRule.java new file mode 100644 index 00000000000..8c728645b8e --- /dev/null +++ b/it/it-tests/src/test/java/it/debt/DebtConfigurationRule.java @@ -0,0 +1,107 @@ +package it.debt; + +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableSet; +import com.sonar.orchestrator.Orchestrator; +import java.util.Set; +import org.junit.rules.ExternalResource; + +import static com.google.common.base.Preconditions.checkState; +import static util.ItUtils.setServerProperty; + +/** + * This rule should be used when dealing with technical debt properties, in order to always be sure that the properties are correctly reset between each tests. + */ +public class DebtConfigurationRule extends ExternalResource { + + private static final String HOURS_IN_DAY_PROPERTY = "sonar.technicalDebt.hoursInDay"; + private static final String DEV_COST_PROPERTY = "sonar.technicalDebt.developmentCost"; + private static final String RATING_GRID_PROPERTY = "sonar.technicalDebt.ratingGrid"; + + private static final String DEV_COST_LANGUAGE_PROPERTY = "languageSpecificParameters"; + private static final String DEV_COST_LANGUAGE_NAME_PROPERTY = DEV_COST_LANGUAGE_PROPERTY + ".0.language"; + private static final String DEV_COST_LANGUAGE_COST_PROPERTY = DEV_COST_LANGUAGE_PROPERTY + ".0.man_days"; + + private static final Joiner COMA_JOINER = Joiner.on(","); + + private static final Set<String> DEV_COST_PROPERTIES = ImmutableSet.of( + DEV_COST_PROPERTY, + DEV_COST_LANGUAGE_PROPERTY, + DEV_COST_LANGUAGE_NAME_PROPERTY, + DEV_COST_LANGUAGE_COST_PROPERTY, + RATING_GRID_PROPERTY); + + private final Orchestrator orchestrator; + + private DebtConfigurationRule(Orchestrator orchestrator) { + this.orchestrator = orchestrator; + } + + public static DebtConfigurationRule create(Orchestrator orchestrator) { + return new DebtConfigurationRule(orchestrator); + } + + @Override + protected void before() throws Throwable { + reset(); + } + + @Override + protected void after() { + reset(); + } + + public void reset() { + resetHoursInDay(); + resetDevelopmentCost(); + resetRatingGrid(); + } + + public DebtConfigurationRule updateHoursInDay(int hoursInDay) { + setProperty(HOURS_IN_DAY_PROPERTY, Integer.toString(hoursInDay)); + return this; + } + + public DebtConfigurationRule resetHoursInDay() { + resetProperty(HOURS_IN_DAY_PROPERTY); + return this; + } + + public DebtConfigurationRule updateDevelopmentCost(int developmentCost) { + setProperty(DEV_COST_PROPERTY, Integer.toString(developmentCost)); + return this; + } + + public DebtConfigurationRule updateLanguageDevelopmentCost(String language, int developmentCost) { + setServerProperty(orchestrator, DEV_COST_LANGUAGE_PROPERTY, "0"); + setServerProperty(orchestrator, DEV_COST_LANGUAGE_NAME_PROPERTY, language); + setServerProperty(orchestrator, DEV_COST_LANGUAGE_COST_PROPERTY, Integer.toString(developmentCost)); + return this; + } + + public void resetDevelopmentCost() { + for (String property : DEV_COST_PROPERTIES) { + resetProperty(property); + } + } + + public DebtConfigurationRule updateRatingGrid(Double... ratingGrid) { + checkState(ratingGrid.length == 4, "Rating grid must contains 4 values"); + setProperty(RATING_GRID_PROPERTY, COMA_JOINER.join(ratingGrid)); + return this; + } + + public DebtConfigurationRule resetRatingGrid() { + resetProperty(RATING_GRID_PROPERTY); + return this; + } + + private void setProperty(String property, String value) { + setServerProperty(orchestrator, property, value); + } + + private void resetProperty(String property) { + setProperty(property, null); + } + +} diff --git a/it/it-tests/src/test/java/it/debt/SqaleRatingMeasureTest.java b/it/it-tests/src/test/java/it/debt/SqaleRatingMeasureTest.java index da898fe4125..75c50d20340 100644 --- a/it/it-tests/src/test/java/it/debt/SqaleRatingMeasureTest.java +++ b/it/it-tests/src/test/java/it/debt/SqaleRatingMeasureTest.java @@ -19,14 +19,13 @@ */ package it.debt; -import com.google.common.collect.ImmutableSet; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarRunner; import com.sonar.orchestrator.locator.FileLocation; import it.Category2Suite; -import org.junit.AfterClass; import org.junit.Before; import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; import org.sonar.wsclient.services.Measure; import org.sonar.wsclient.services.Resource; @@ -34,7 +33,6 @@ import org.sonar.wsclient.services.ResourceQuery; import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.projectDir; -import static util.ItUtils.setServerProperty; /** * SONAR-4715 @@ -46,26 +44,19 @@ public class SqaleRatingMeasureTest { private static final String SUB_MODULE = "com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1"; private static final String DIRECTORY = "com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1:src/main/xoo/com/sonar/it/samples/modules/a1"; private static final String FILE = "com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1:src/main/xoo/com/sonar/it/samples/modules/a1/HelloA1.xoo"; + @ClassRule public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR; - private static void resetDevelopmentCost() { - for (String property : ImmutableSet.of("sonar.technicalDebt.developmentCost", "sonar.technicalDebt.sizeMetric", - "languageSpecificParameters", "languageSpecificParameters.0.language", "languageSpecificParameters.0.man_days", "languageSpecificParameters.0.size_metric", - "ratingGrid")) { - setServerProperty(orchestrator, property, null); - } - } - - @AfterClass - public static void reset() { - resetDevelopmentCost(); - } + @Rule + public DebtConfigurationRule debtConfiguration = DebtConfigurationRule.create(orchestrator); @Before public void init() { - resetDevelopmentCost(); orchestrator.resetData(); + + // Set rating grid values to not depend from default value + debtConfiguration.updateRatingGrid(0.1d, 0.2d, 0.5d, 1d); } @Test @@ -119,7 +110,7 @@ public class SqaleRatingMeasureTest { assertThat(rating.getIntValue()).isEqualTo(1); assertThat(rating.getData()).isEqualTo("A"); - setServerProperty(orchestrator, "sonar.technicalDebt.developmentCost", "2"); + debtConfiguration.updateDevelopmentCost(2); orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample"))); rating = getMeasure("sample", "sqale_rating"); @@ -139,10 +130,7 @@ public class SqaleRatingMeasureTest { assertThat(rating.getIntValue()).isEqualTo(1); assertThat(rating.getData()).isEqualTo("A"); - setServerProperty(orchestrator, "languageSpecificParameters", "0"); - setServerProperty(orchestrator, "languageSpecificParameters.0.language", "xoo"); - setServerProperty(orchestrator, "languageSpecificParameters.0.man_days", "1"); - setServerProperty(orchestrator, "languageSpecificParameters.0.size_metric", "ncloc"); + debtConfiguration.updateLanguageDevelopmentCost("xoo", 1); orchestrator.executeBuild( SonarRunner.create(projectDir("shared/xoo-multi-modules-sample")) .setProfile("one-issue-per-line")); @@ -164,7 +152,7 @@ public class SqaleRatingMeasureTest { assertThat(rating.getIntValue()).isEqualTo(1); assertThat(rating.getData()).isEqualTo("A"); - setServerProperty(orchestrator, "ratingGrid", "0.001,0.005,0.010,0.015"); + debtConfiguration.updateRatingGrid(0.001d, 0.005d, 0.01d, 0.015d); orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample"))); rating = getMeasure("sample", "sqale_rating"); diff --git a/it/it-tests/src/test/java/it/debt/TechnicalDebtInIssueChangelogTest.java b/it/it-tests/src/test/java/it/debt/TechnicalDebtInIssueChangelogTest.java index 30f1ebf6ab5..9b405dd902b 100644 --- a/it/it-tests/src/test/java/it/debt/TechnicalDebtInIssueChangelogTest.java +++ b/it/it-tests/src/test/java/it/debt/TechnicalDebtInIssueChangelogTest.java @@ -24,9 +24,9 @@ import com.sonar.orchestrator.build.SonarRunner; import com.sonar.orchestrator.locator.FileLocation; import it.Category2Suite; import java.util.List; -import org.junit.AfterClass; import org.junit.Before; import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; import org.sonar.wsclient.issue.Issue; import org.sonar.wsclient.issue.IssueChange; @@ -36,7 +36,6 @@ import org.sonar.wsclient.issue.IssueQuery; import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.projectDir; -import static util.ItUtils.setServerProperty; /** * SONAR-4834 @@ -46,17 +45,15 @@ public class TechnicalDebtInIssueChangelogTest { @ClassRule public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR; - @AfterClass - public static void resetHoursInDay() throws Exception { - setServerProperty(orchestrator, "sonar.technicalDebt.hoursInDay", null); - } + @Rule + public DebtConfigurationRule debtConfiguration = DebtConfigurationRule.create(orchestrator); @Before public void deleteAnalysisData() { orchestrator.resetData(); // Set hours in day property to 8 - setServerProperty(orchestrator, "sonar.technicalDebt.hoursInDay", "8"); + debtConfiguration.updateHoursInDay(8); } @Test @@ -96,7 +93,7 @@ public class TechnicalDebtInIssueChangelogTest { orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample"))); // One day -> 10 hours - setServerProperty(orchestrator, "sonar.technicalDebt.hoursInDay", "10"); + debtConfiguration.updateHoursInDay(10); orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample")) // As OneIssuePerFile has a debt of 10 minutes, we multiply it by 72 to have 1 day and 2 hours of technical debtn diff --git a/it/it-tests/src/test/java/it/debt/TechnicalDebtTest.java b/it/it-tests/src/test/java/it/debt/TechnicalDebtTest.java index 9522ee9458f..933a698ae6a 100644 --- a/it/it-tests/src/test/java/it/debt/TechnicalDebtTest.java +++ b/it/it-tests/src/test/java/it/debt/TechnicalDebtTest.java @@ -24,9 +24,9 @@ import com.sonar.orchestrator.build.SonarRunner; import com.sonar.orchestrator.locator.FileLocation; import it.Category2Suite; import java.util.List; -import org.junit.AfterClass; import org.junit.Before; import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; import org.sonar.wsclient.issue.Issue; import org.sonar.wsclient.issue.IssueClient; @@ -34,23 +34,21 @@ import org.sonar.wsclient.issue.IssueQuery; import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.projectDir; -import static util.ItUtils.setServerProperty; public class TechnicalDebtTest { @ClassRule public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR; - @AfterClass - public static void resetHoursInDay() throws Exception { - setServerProperty(orchestrator, "sonar.technicalDebt.hoursInDay", null); - } + @Rule + public DebtConfigurationRule debtConfiguration = DebtConfigurationRule.create(orchestrator); @Before public void deleteAnalysisData() { orchestrator.resetData(); + // Set hours in day property to 8 - setServerProperty(orchestrator, "sonar.technicalDebt.hoursInDay", "8"); + debtConfiguration.updateHoursInDay(8); } /** @@ -80,7 +78,7 @@ public class TechnicalDebtTest { orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-file"); // One day -> 10 hours - setServerProperty(orchestrator, "sonar.technicalDebt.hoursInDay", "10"); + debtConfiguration.updateHoursInDay(10); orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample")) // As OneIssuePerFile has a debt of 10 minutes, we multiply it by 72 to have 1 day and 2 hours of technical debt @@ -100,13 +98,13 @@ public class TechnicalDebtTest { orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-day-debt-per-file"); // One day -> 10 hours : debt will be stored as 360.000 seconds (1 day * 10 hours per day * 60 * 60) - setServerProperty(orchestrator, "sonar.technicalDebt.hoursInDay", "10"); + debtConfiguration.updateHoursInDay(10); orchestrator.executeBuild(SonarRunner.create(projectDir("shared/xoo-sample"))); // Issue debt was 1 day during analysis but will be displayed as 1 day and 2 hours (hours in day property was set // to 10 during analysis but is now 8) - setServerProperty(orchestrator, "sonar.technicalDebt.hoursInDay", "8"); + debtConfiguration.updateHoursInDay(8); IssueClient issueClient = orchestrator.getServer().wsClient().issueClient(); Issue issue = issueClient.find(IssueQuery.create()).list().get(0); diff --git a/it/it-tests/src/test/java/it/debt/TechnicalDebtWidgetTest.java b/it/it-tests/src/test/java/it/debt/TechnicalDebtWidgetTest.java index a9d9df0f6e7..4d15720fa1f 100644 --- a/it/it-tests/src/test/java/it/debt/TechnicalDebtWidgetTest.java +++ b/it/it-tests/src/test/java/it/debt/TechnicalDebtWidgetTest.java @@ -36,10 +36,16 @@ public class TechnicalDebtWidgetTest { @ClassRule public static Orchestrator orchestrator = Category2Suite.ORCHESTRATOR; + @ClassRule + public static DebtConfigurationRule debtConfiguration = DebtConfigurationRule.create(orchestrator); + @BeforeClass public static void init() { orchestrator.resetData(); + // Set rating grid values to not depend from default value + debtConfiguration.updateRatingGrid(0.1d, 0.2d, 0.5d, 1d); + orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/debt/with-many-rules.xml")); orchestrator.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "com.sonarsource.it.samples:multi-modules-sample"); orchestrator.getServer().associateProjectToQualityProfile("com.sonarsource.it.samples:multi-modules-sample", "xoo", "with-many-rules"); diff --git a/it/it-tests/src/test/resources/projectOverview/ProjectOverviewTest/test_it_coverage_on_project_overview.html b/it/it-tests/src/test/resources/projectOverview/ProjectOverviewTest/test_it_coverage_on_project_overview.html index 896815ce200..db38e860191 100644 --- a/it/it-tests/src/test/resources/projectOverview/ProjectOverviewTest/test_it_coverage_on_project_overview.html +++ b/it/it-tests/src/test/resources/projectOverview/ProjectOverviewTest/test_it_coverage_on_project_overview.html @@ -32,17 +32,17 @@ <tr> <td>waitForText</td> <td>id=content</td> - <td>*50.0%*IT coverage*</td> + <td>*IT coverage*50.0%*</td> </tr> <tr> <td>waitForText</td> <td>id=content</td> - <td>*50.0%*IT line coverage*</td> + <td>*IT line coverage*50.0%*</td> </tr> <tr> <td>waitForText</td> <td>id=content</td> - <td>*50.0%*IT condition coverage*</td> + <td>*IT condition coverage*50.0%*</td> </tr> <tr> <td>waitForText</td> @@ -57,7 +57,7 @@ <tr> <td>waitForText</td> <td>id=content</td> - <td>*X*Complexity*Y*IT coverage*Size*IT uncovered lines*</td> + <td>*Size*IT uncovered lines*</td> </tr> <tr> <td>waitForText</td> diff --git a/it/it-tests/src/test/resources/projectOverview/ProjectOverviewTest/test_overall_coverage_on_project_overview.html b/it/it-tests/src/test/resources/projectOverview/ProjectOverviewTest/test_overall_coverage_on_project_overview.html index 02eea808417..9d5fd67fee2 100644 --- a/it/it-tests/src/test/resources/projectOverview/ProjectOverviewTest/test_overall_coverage_on_project_overview.html +++ b/it/it-tests/src/test/resources/projectOverview/ProjectOverviewTest/test_overall_coverage_on_project_overview.html @@ -32,17 +32,17 @@ <tr> <td>waitForText</td> <td>id=content</td> - <td>*62.5%*Overall coverage*</td> + <td>*Overall coverage*62.5%*</td> </tr> <tr> <td>waitForText</td> <td>id=content</td> - <td>*75.0%*Overall line coverage*</td> + <td>*Overall line coverage*75.0%*</td> </tr> <tr> <td>waitForText</td> <td>id=content</td> - <td>*50.0%*Overall condition coverage*</td> + <td>*Overall condition coverage*50.0%*</td> </tr> <tr> <td>waitForText</td> @@ -77,7 +77,7 @@ <tr> <td>waitForText</td> <td>id=content</td> - <td>*X*Complexity*Y*Overall coverage*Size*Overall uncovered lines*</td> + <td>*Size*Overall uncovered lines*</td> </tr> <tr> <td>waitForText</td> diff --git a/it/it-tests/src/test/resources/projectOverview/ProjectOverviewTest/test_ut_coverage_on_project_overview.html b/it/it-tests/src/test/resources/projectOverview/ProjectOverviewTest/test_ut_coverage_on_project_overview.html index 69bc51e7f38..fd88d0fc0aa 100644 --- a/it/it-tests/src/test/resources/projectOverview/ProjectOverviewTest/test_ut_coverage_on_project_overview.html +++ b/it/it-tests/src/test/resources/projectOverview/ProjectOverviewTest/test_ut_coverage_on_project_overview.html @@ -32,17 +32,17 @@ <tr> <td>waitForText</td> <td>id=content</td> - <td>*50.0%*Coverage*</td> + <td>*Coverage*50.0%*</td> </tr> <tr> <td>waitForText</td> <td>id=content</td> - <td>*50.0%*Line coverage*</td> + <td>*Line coverage*50.0%*</td> </tr> <tr> <td>waitForText</td> <td>id=content</td> - <td>*50.0%*Condition coverage*</td> + <td>*Condition coverage*50.0%*</td> </tr> <tr> <td>waitForText</td> @@ -62,7 +62,7 @@ <tr> <td>waitForText</td> <td>id=content</td> - <td>*X*Complexity*Y*Coverage*Size*Uncovered lines*</td> + <td>*Size*Uncovered lines*</td> </tr> <tr> <td>waitForText</td> |