Skip to content

Commit 7e47380

Browse files
authored
ITs: Remove use of orchestrator.resetData()
1 parent 3768c22 commit 7e47380

6 files changed

Lines changed: 45 additions & 44 deletions

File tree

its/plugin/it-python-plugin-test/projects/nosetests_project/sonar-project.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# Required metadata
2-
sonar.projectKey=nosetests_project
3-
sonar.projectName=nosetests_project
42
sonar.projectVersion=1
53
sonar.sourceEncoding=UTF8
64

its/plugin/it-python-plugin-test/projects/pylint_project/sonar-project.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# Required metadata
2-
sonar.projectKey=pylint_project
3-
sonar.projectName=pylint_project
42
sonar.projectVersion=1
53
sonar.sourceEncoding=UTF8
64

its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/BanditReportTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public class BanditReportTest {
4242

4343
@Test
4444
public void import_report() {
45-
ORCHESTRATOR.resetData();
4645
ORCHESTRATOR.getServer().provisionProject(PROJECT, PROJECT);
4746
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT, "py", "no_rule");
4847
ORCHESTRATOR.executeBuild(

its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/Flake8ReportTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public class Flake8ReportTest {
4242

4343
@Test
4444
public void import_report() {
45-
ORCHESTRATOR.resetData();
4645
ORCHESTRATOR.getServer().provisionProject(PROJECT, PROJECT);
4746
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT, "py", "no_rule");
4847
ORCHESTRATOR.executeBuild(

its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/PylintReportTest.java

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
public class PylintReportTest {
3737

38-
private static final String PROJECT = "pylint_project";
3938
private static final String DEFAULT_PROPERTY = "sonar.python.pylint.reportPaths";
4039
private static final String LEGACY_PROPERTY = "sonar.python.pylint.reportPath";
4140

@@ -44,53 +43,60 @@ public class PylintReportTest {
4443

4544
@Test
4645
public void import_report() {
47-
analyseProjectWithReport(DEFAULT_PROPERTY, "pylint-report.txt");
48-
assertThat(issues()).hasSize(4);
46+
final String projectKey = "pylint_project";
47+
analyseProjectWithReport(projectKey, DEFAULT_PROPERTY, "pylint-report.txt");
48+
assertThat(issues(projectKey)).hasSize(4);
4949
}
5050

5151
@Test
5252
public void import_report_legacy_key() {
53-
analyseProjectWithReport(LEGACY_PROPERTY, "pylint-report.txt");
54-
assertThat(issues()).hasSize(4);
53+
final String projectKey = "pylint_project_legacy_key";
54+
analyseProjectWithReport(projectKey, LEGACY_PROPERTY, "pylint-report.txt");
55+
assertThat(issues(projectKey)).hasSize(4);
5556
}
5657

5758
@Test
5859
public void missing_report() {
59-
analyseProjectWithReport(DEFAULT_PROPERTY, "missing");
60-
assertThat(issues()).isEmpty();
60+
final String projectKey = "pylint_project_missing_report";
61+
analyseProjectWithReport(projectKey, DEFAULT_PROPERTY, "missing");
62+
assertThat(issues(projectKey)).isEmpty();
6163
}
6264

6365
@Test
6466
public void invalid_report() {
65-
BuildResult result = analyseProjectWithReport(DEFAULT_PROPERTY, "invalid.txt");
67+
final String projectKey = "pylint_project_invalid_report";
68+
BuildResult result = analyseProjectWithReport(projectKey, DEFAULT_PROPERTY, "invalid.txt");
6669
assertThat(result.getLogs()).contains("Cannot parse the line: trash");
67-
assertThat(issues()).isEmpty();
70+
assertThat(issues(projectKey)).isEmpty();
6871
}
6972

7073
@Test
7174
public void unknown_rule() {
72-
BuildResult result = analyseProjectWithReport(DEFAULT_PROPERTY, "rule-unknown.txt");
73-
assertThat(issues()).hasSize(4);
75+
final String projectKey = "pylint_project_unknown_rule";
76+
analyseProjectWithReport(projectKey, DEFAULT_PROPERTY, "rule-unknown.txt");
77+
assertThat(issues(projectKey)).hasSize(4);
7478
}
7579

7680
@Test
7781
public void multiple_reports() {
78-
analyseProjectWithReport(DEFAULT_PROPERTY, "pylint-report.txt, rule-unknown.txt");
79-
assertThat(issues()).hasSize(8);
82+
final String projectKey = "pylint_project_multiple_reports";
83+
analyseProjectWithReport(projectKey, DEFAULT_PROPERTY, "pylint-report.txt, rule-unknown.txt");
84+
assertThat(issues(projectKey)).hasSize(8);
8085
}
8186

82-
private static List<Issue> issues() {
83-
return newWsClient().issues().search(new SearchRequest().setProjects(singletonList(PROJECT))).getIssuesList();
87+
private static List<Issue> issues(String projectKey) {
88+
return newWsClient().issues().search(new SearchRequest().setProjects(singletonList(projectKey))).getIssuesList();
8489
}
8590

86-
private static BuildResult analyseProjectWithReport(String property, String reportPaths) {
87-
ORCHESTRATOR.resetData();
88-
ORCHESTRATOR.getServer().provisionProject(PROJECT, PROJECT);
89-
ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT, "py", "no_rule");
91+
private static BuildResult analyseProjectWithReport(String projectKey, String property, String reportPaths) {
92+
ORCHESTRATOR.getServer().provisionProject(projectKey, projectKey);
93+
ORCHESTRATOR.getServer().associateProjectToQualityProfile(projectKey, "py", "no_rule");
9094

9195
return ORCHESTRATOR.executeBuild(
9296
SonarScanner.create()
9397
.setDebugLogs(true)
98+
.setProjectKey(projectKey)
99+
.setProjectName(projectKey)
94100
.setProjectDir(new File("projects/pylint_project"))
95101
.setProperty(property, reportPaths));
96102
}

its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/TestReportTest.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.HashMap;
3030
import java.util.Map;
3131
import java.util.Set;
32-
import org.junit.Before;
3332
import org.junit.ClassRule;
3433
import org.junit.Test;
3534

@@ -38,7 +37,6 @@
3837

3938
public class TestReportTest {
4039

41-
private static final String PROJECT = "nosetests_project";
4240
public static final String TESTS = "tests";
4341
public static final String TEST_FAILURES = "test_failures";
4442
public static final String TEST_ERRORS = "test_errors";
@@ -49,22 +47,20 @@ public class TestReportTest {
4947
@ClassRule
5048
public static final Orchestrator ORCHESTRATOR = Tests.ORCHESTRATOR;
5149

52-
@Before
53-
public void before() {
54-
ORCHESTRATOR.resetData();
55-
}
56-
57-
private static SonarScanner createBuild(String testReportPath) {
50+
private static SonarScanner createBuild(String projectKey, String testReportPath) {
5851
return SonarScanner.create()
52+
.setProjectKey(projectKey)
53+
.setProjectName(projectKey)
5954
.setProjectDir(new File("projects/nosetests_project"))
6055
.setProperty("sonar.python.xunit.reportPath", testReportPath);
6156
}
6257

6358
@Test
6459
public void import_report() {
60+
final String projectKey = "nosetests_project";
6561
// sonar.python.xunit.skipDetails=false by default
66-
ORCHESTRATOR.executeBuild(createBuild("nosetests.xml"));
67-
assertProjectMeasures(PROJECT, new ImmutableMap.Builder<String, Integer>()
62+
ORCHESTRATOR.executeBuild(createBuild(projectKey, "nosetests.xml"));
63+
assertProjectMeasures(projectKey, new ImmutableMap.Builder<String, Integer>()
6864
.put(TESTS, 3)
6965
.put(TEST_FAILURES, 1)
7066
.put(TEST_ERRORS, 1)
@@ -76,8 +72,9 @@ public void import_report() {
7672

7773
@Test
7874
public void import_pytest_report() {
79-
ORCHESTRATOR.executeBuild(createBuild("pytest.xml"));
80-
assertProjectMeasures(PROJECT, new ImmutableMap.Builder<String, Integer>()
75+
final String projectKey = "pytest";
76+
ORCHESTRATOR.executeBuild(createBuild(projectKey, "pytest.xml"));
77+
assertProjectMeasures(projectKey, new ImmutableMap.Builder<String, Integer>()
8178
.put(TESTS, 3)
8279
.put(TEST_FAILURES, 2)
8380
.put(TEST_ERRORS, 0)
@@ -89,7 +86,8 @@ public void import_pytest_report() {
8986

9087
@Test
9188
public void simple_mode() {
92-
ORCHESTRATOR.executeBuild(createBuild("nosetests.xml").setProperty("sonar.python.xunit.skipDetails", "true"));
89+
final String projectKey = "nosetests_simple";
90+
ORCHESTRATOR.executeBuild(createBuild(projectKey, "nosetests.xml").setProperty("sonar.python.xunit.skipDetails", "true"));
9391
Map<String, Integer> values = new HashMap<>();
9492
values.put(TESTS, 3);
9593
values.put(TEST_FAILURES, 1);
@@ -98,24 +96,27 @@ public void simple_mode() {
9896
values.put(TEST_EXECUTION_TIME, 1);
9997
values.put(TEST_SUCCESS_DENSITY, null);
10098

101-
assertProjectMeasures(PROJECT, values);
99+
assertProjectMeasures(projectKey, values);
102100
}
103101

104102
@Test
105103
public void missing_test_report() {
106-
ORCHESTRATOR.executeBuild(createBuild("missing.xml"));
107-
assertProjectMeasures(PROJECT, nullMeasures());
104+
final String projectKey = "nosetests_missing";
105+
ORCHESTRATOR.executeBuild(createBuild(projectKey, "missing.xml"));
106+
assertProjectMeasures(projectKey, nullMeasures());
108107
}
109108

110109
@Test
111110
public void missing_test_report_with_simple_mode() {
112-
ORCHESTRATOR.executeBuild(createBuild("missing.xml").setProperty("sonar.python.xunit.skipDetails", "true"));
113-
assertProjectMeasures(PROJECT, nullMeasures());
111+
final String projectKey = "nosetests_missing_simple";
112+
ORCHESTRATOR.executeBuild(createBuild(projectKey, "missing.xml").setProperty("sonar.python.xunit.skipDetails", "true"));
113+
assertProjectMeasures(projectKey, nullMeasures());
114114
}
115115

116116
@Test
117117
public void invalid_test_report() {
118-
BuildResult result = ORCHESTRATOR.executeBuildQuietly(createBuild("invalid_report.xml"));
118+
final String projectKey = "nosetests_invalid";
119+
BuildResult result = ORCHESTRATOR.executeBuildQuietly(createBuild(projectKey, "invalid_report.xml"));
119120
assertThat(result.isSuccess()).isTrue();
120121
assertThat(result.getLogs()).contains("Cannot read report 'invalid_report.xml', the following exception occurred:" +
121122
" Unexpected character 't' (code 116) in prolog; expected '<'\n" +

0 commit comments

Comments
 (0)