Browse Source

Move remaining issues ITs

tags/5.5-M1
Julien Lancelot 8 years ago
parent
commit
4b8a9341a7

+ 4
- 0
it/it-tests/src/test/java/it/issue/AbstractIssueTest.java View File

@@ -85,4 +85,8 @@ public abstract class AbstractIssueTest {
static List<Issue> searchIssues(IssueQuery issueQuery) {
return issueClient().find(issueQuery).list();
}

static List<Issue> searchIssuesByProject(String projectKey) {
return search(IssueQuery.create().componentRoots(projectKey)).list();
}
}

+ 78
- 0
it/it-tests/src/test/java/it/issue/IssueCreationTest.java View File

@@ -0,0 +1,78 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact 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 it.issue;

import com.sonar.orchestrator.locator.FileLocation;
import org.junit.Before;
import org.junit.Test;
import org.sonar.wsclient.issue.Issue;
import org.sonar.wsclient.issue.IssueQuery;
import org.sonar.wsclient.issue.Issues;

import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.runProjectAnalysis;

public class IssueCreationTest extends AbstractIssueTest {

private static final String SAMPLE_PROJECT_KEY = "sample";

@Before
public void resetData() {
ORCHESTRATOR.resetData();
}

/**
* See SONAR-4785
*/
@Test
public void use_rule_name_if_issue_has_no_message() {
ORCHESTRATOR.getServer().provisionProject(SAMPLE_PROJECT_KEY, SAMPLE_PROJECT_KEY);
ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/issue/IssueCreationTest/with-custom-message.xml"));
ORCHESTRATOR.getServer().associateProjectToQualityProfile(SAMPLE_PROJECT_KEY, "xoo", "with-custom-message");

// First analysis, the issue is generated with a message
runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample", "sonar.customMessage.message", "a message");
Issue issue = issueClient().find(IssueQuery.create()).list().get(0);
assertThat(issue.message()).isEqualTo("a message");

// Second analysis, the issue is generated without any message, the name of the rule is used
runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample");
issue = issueClient().find(IssueQuery.create()).list().get(0);
assertThat(issue.message()).isEqualTo("Issue With Custom Message");
}

@Test
public void plugin_can_override_profile_severity() throws Exception {
ORCHESTRATOR.getServer().provisionProject(SAMPLE_PROJECT_KEY, SAMPLE_PROJECT_KEY);

// The rule "OneBlockerIssuePerFile" is enabled with severity "INFO"
ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/issue/IssueCreationTest/override-profile-severity.xml"));
ORCHESTRATOR.getServer().associateProjectToQualityProfile(SAMPLE_PROJECT_KEY, "xoo", "override-profile-severity");

// But it's hardcoded "blocker" when plugin generates the issue
runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample");

Issues issues = search(IssueQuery.create().rules("xoo:OneBlockerIssuePerFile"));
assertThat(issues.size()).isGreaterThan(0);
for (Issue issue : issues.list()) {
assertThat(issue.severity()).isEqualTo("BLOCKER");
}
}
}

+ 154
- 0
it/it-tests/src/test/java/it/issue/IssueMeasureTest.java View File

@@ -0,0 +1,154 @@
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact 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 it.issue;

import com.google.common.collect.ImmutableMap;
import com.sonar.orchestrator.locator.FileLocation;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.sonar.wsclient.Sonar;
import org.sonar.wsclient.issue.Issue;
import org.sonar.wsclient.issue.NewIssue;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;

import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.runProjectAnalysis;

public class IssueMeasureTest extends AbstractIssueTest {

private static final String MULTI_MODULE_SAMPLE_PROJECT_KEY = "com.sonarsource.it.samples:multi-modules-sample";
private static final String SAMPLE_PROJECT_KEY = "sample";

@Before
public void resetData() {
ORCHESTRATOR.resetData();
}

@Test
public void issues_by_severity_measures() {
ORCHESTRATOR.getServer().provisionProject(MULTI_MODULE_SAMPLE_PROJECT_KEY, MULTI_MODULE_SAMPLE_PROJECT_KEY);
ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/issue/with-many-rules.xml"));
ORCHESTRATOR.getServer().associateProjectToQualityProfile(MULTI_MODULE_SAMPLE_PROJECT_KEY, "xoo", "with-many-rules");
runProjectAnalysis(ORCHESTRATOR, "shared/xoo-multi-modules-sample");

assertThat(searchIssuesByProject(MULTI_MODULE_SAMPLE_PROJECT_KEY)).hasSize(71);

Resource project = ORCHESTRATOR.getServer().getWsClient()
.find(ResourceQuery.createForMetrics(MULTI_MODULE_SAMPLE_PROJECT_KEY, "violations", "info_violations", "minor_violations", "major_violations",
"blocker_violations", "critical_violations"));
assertThat(project.getMeasureIntValue("violations")).isEqualTo(71);
assertThat(project.getMeasureIntValue("info_violations")).isEqualTo(2);
assertThat(project.getMeasureIntValue("minor_violations")).isEqualTo(61);
assertThat(project.getMeasureIntValue("major_violations")).isEqualTo(4);
assertThat(project.getMeasureIntValue("blocker_violations")).isEqualTo(0);
assertThat(project.getMeasureIntValue("critical_violations")).isEqualTo(4);
}

/**
* SONAR-4330
*/
@Test
public void issues_by_resolution_and_status_measures() {
ORCHESTRATOR.getServer().provisionProject(SAMPLE_PROJECT_KEY, SAMPLE_PROJECT_KEY);
ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/issue/one-issue-per-line-profile.xml"));
ORCHESTRATOR.getServer().associateProjectToQualityProfile(SAMPLE_PROJECT_KEY, "xoo", "one-issue-per-line-profile");
runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample");

List<Issue> issues = searchIssuesByProject(SAMPLE_PROJECT_KEY);
assertThat(issues).hasSize(17);

// 1 is a false-positive, 1 is confirmed, 1 is reopened, and the remaining ones stays open
adminIssueClient().doTransition(issues.get(0).key(), "falsepositive");
adminIssueClient().doTransition(issues.get(1).key(), "confirm");
adminIssueClient().doTransition(issues.get(2).key(), "resolve");
adminIssueClient().doTransition(issues.get(2).key(), "reopen");

// Re analyze the project to compute measures
runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample");

Resource project = ORCHESTRATOR.getServer().getWsClient().find(
ResourceQuery.createForMetrics(SAMPLE_PROJECT_KEY, "false_positive_issues", "open_issues", "reopened_issues", "confirmed_issues"));
assertThat(project.getMeasureIntValue("false_positive_issues")).isEqualTo(1);
assertThat(project.getMeasureIntValue("open_issues")).isEqualTo(14);
assertThat(project.getMeasureIntValue("reopened_issues")).isEqualTo(1);
assertThat(project.getMeasureIntValue("confirmed_issues")).isEqualTo(1);
}

@Test
public void no_issue_are_computed_on_empty_profile() {
ORCHESTRATOR.getServer().provisionProject(SAMPLE_PROJECT_KEY, SAMPLE_PROJECT_KEY);

// no active rules
ORCHESTRATOR.getServer().associateProjectToQualityProfile(SAMPLE_PROJECT_KEY, "xoo", "empty");
runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample");

assertThat(searchIssuesByProject(SAMPLE_PROJECT_KEY)).isEmpty();

Resource project = ORCHESTRATOR.getServer().getWsClient().find(ResourceQuery.createForMetrics(SAMPLE_PROJECT_KEY, "violations", "blocker_violations"));
assertThat(project.getMeasureIntValue("violations")).isEqualTo(0);
assertThat(project.getMeasureIntValue("blocker_violations")).isEqualTo(0);
}

/**
* SONAR-3746
*/
@Test
public void issues_measures_on_test_files() {
String projectKey = "sample-with-tests";
String testKey = "sample-with-tests:src/test/xoo/sample/SampleTest.xoo";

ORCHESTRATOR.getServer().provisionProject(projectKey, projectKey);
ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/issue/one-issue-per-line-profile.xml"));
ORCHESTRATOR.getServer().associateProjectToQualityProfile(projectKey, "xoo", "one-issue-per-line-profile");
runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample-with-tests");

Sonar wsClient = ORCHESTRATOR.getServer().getAdminWsClient();

// Store current number of issues
Resource project = wsClient.find(ResourceQuery.createForMetrics(projectKey, "violations"));
int issues = project.getMeasureIntValue("violations");

// Create the manual rule
createManualRule();

// Create a issue on the test source file
adminIssueClient().create(NewIssue.create().component(testKey)
.severity("MAJOR")
.rule("manual:invalidclassname").line(8)
.message("The name 'SampleTest' is too generic"));

// Re-analyse the project
runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample-with-tests");

// And check that the number of issues metrics have changed
project = wsClient.find(ResourceQuery.createForMetrics(projectKey, "violations"));
assertThat(project.getMeasureIntValue("violations")).isEqualTo(issues + 1);
}

private static void createManualRule() {
ORCHESTRATOR.getServer().adminWsClient().post("/api/rules/create", ImmutableMap.<String, Object>of(
"manual_key", "invalidclassname",
"name", "InvalidClassName",
"markdown_description", "Invalid class name"
));
}
}

+ 0
- 11
it/it-tests/src/test/java/it/issue/IssueTrackingTest.java View File

@@ -23,11 +23,9 @@ import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.sonar.orchestrator.locator.FileLocation;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang.time.DateUtils;
import org.junit.Before;
import org.junit.Test;
import org.sonar.wsclient.issue.Issue;
@@ -170,17 +168,8 @@ public class IssueTrackingTest extends AbstractIssueTest {
});
}

private void assertSameDate(Date date1, String date2Text) throws ParseException {
Date date2 = new SimpleDateFormat("yyyy-MM-dd").parse(date2Text);
assertThat(DateUtils.isSameDay(date1, date2)).describedAs("Expected '" + date2Text + " ' but got '" + new SimpleDateFormat("yyyy-MM-dd").format(date1) + "'").isTrue();
}

private List<Issue> searchUnresolvedIssuesByComponent(String componentKey) {
return search(IssueQuery.create().components(componentKey).resolved(false)).list();
}

private List<Issue> searchIssuesByProject(String projectKey) {
return search(IssueQuery.create().componentRoots(projectKey)).list();
}

}

+ 11
- 0
it/it-tests/src/test/resources/issue/IssueCreationTest/override-profile-severity.xml View File

@@ -0,0 +1,11 @@
<profile>
<name>override-profile-severity</name>
<language>xoo</language>
<rules>
<rule>
<repositoryKey>xoo</repositoryKey>
<key>OneBlockerIssuePerFile</key>
<priority>INFO</priority>
</rule>
</rules>
</profile>

+ 11
- 0
it/it-tests/src/test/resources/issue/IssueCreationTest/with-custom-message.xml View File

@@ -0,0 +1,11 @@
<profile>
<name>with-custom-message</name>
<language>xoo</language>
<rules>
<rule>
<repositoryKey>xoo</repositoryKey>
<key>CustomMessage</key>
<priority>MAJOR</priority>
</rule>
</rules>
</profile>

+ 2
- 0
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java View File

@@ -34,6 +34,7 @@ import org.sonar.xoo.lang.XooCpdMapping;
import org.sonar.xoo.lang.XooTokenizer;
import org.sonar.xoo.rule.ChecksSensor;
import org.sonar.xoo.rule.CreateIssueByInternalKeySensor;
import org.sonar.xoo.rule.CustomMessageSensor;
import org.sonar.xoo.rule.DeprecatedResourceApiSensor;
import org.sonar.xoo.rule.HasTagSensor;
import org.sonar.xoo.rule.MultilineIssuesSensor;
@@ -103,6 +104,7 @@ public class XooPlugin extends SonarPlugin {
OneIssueOnDirPerFileSensor.class,
CreateIssueByInternalKeySensor.class,
MultilineIssuesSensor.class,
CustomMessageSensor.class,

// Coverage
UtCoverageSensor.class,

Loading…
Cancel
Save