diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2018-04-23 11:45:03 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-04-26 20:20:53 +0200 |
commit | 5958b88243b4d4db54cdb20fb91fc45fac34e9d3 (patch) | |
tree | e409139da361b6be16b9ab45159c0e380197601f /sonar-scanner-engine/src/test/java | |
parent | 601f29b81dab124ceacbce88caac687d70a298c6 (diff) | |
download | sonarqube-5958b88243b4d4db54cdb20fb91fc45fac34e9d3.tar.gz sonarqube-5958b88243b4d4db54cdb20fb91fc45fac34e9d3.zip |
SONAR-10544 Set effort for external issues
Diffstat (limited to 'sonar-scanner-engine/src/test/java')
2 files changed, 30 insertions, 5 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java index e13e64d6b85..add4404b2a9 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java @@ -39,7 +39,7 @@ public class ReportParserTest { System.out.println(Paths.get("org/sonar/scanner/externalissue/report.json").toAbsolutePath()); Report report = parser.parse(); - assertThat(report.issues).hasSize(3); + assertThat(report.issues).hasSize(4); assertThat(report.issues[0].engineId).isEqualTo("eslint"); assertThat(report.issues[0].ruleId).isEqualTo("rule1"); assertThat(report.issues[0].severity).isEqualTo("MAJOR"); @@ -52,6 +52,19 @@ public class ReportParserTest { assertThat(report.issues[0].primaryLocation.textRange.endColumn).isEqualTo(4); assertThat(report.issues[0].primaryLocation.textRange.endLine).isEqualTo(3); assertThat(report.issues[0].secondaryLocations).isNull(); + + assertThat(report.issues[3].engineId).isEqualTo("eslint"); + assertThat(report.issues[3].ruleId).isEqualTo("rule3"); + assertThat(report.issues[3].severity).isEqualTo("MAJOR"); + assertThat(report.issues[3].effortMinutes).isNull(); + assertThat(report.issues[3].type).isEqualTo("BUG"); + assertThat(report.issues[3].secondaryLocations).hasSize(2); + assertThat(report.issues[3].secondaryLocations[0].filePath).isEqualTo("file1.js"); + assertThat(report.issues[3].secondaryLocations[0].message).isEqualTo("fix the bug here"); + assertThat(report.issues[3].secondaryLocations[0].textRange.startLine).isEqualTo(1); + assertThat(report.issues[3].secondaryLocations[1].filePath).isEqualTo("file2.js"); + assertThat(report.issues[3].secondaryLocations[1].message).isNull(); + assertThat(report.issues[3].secondaryLocations[1].textRange.startLine).isEqualTo(2); } private Path path(String reportName) { @@ -121,4 +134,12 @@ public class ReportParserTest { exception.expectMessage("missing mandatory field 'filePath'"); parser.parse(); } + + @Test + public void fail_if_message_not_set_in_primaryLocation() { + ReportParser parser = new ReportParser(path("report_missing_message.json")); + exception.expect(IllegalStateException.class); + exception.expectMessage("missing mandatory field 'message'"); + parser.parse(); + } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java index 6d406300c3b..92e01b6491d 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/ExternalIssuesMediumTest.java @@ -28,7 +28,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.utils.log.LogTester; -import org.sonar.api.utils.log.LoggersTest; import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.TaskResult; import org.sonar.scanner.protocol.Constants.Severity; @@ -111,18 +110,23 @@ public class ExternalIssuesMediumTest { assertThat(issue.getTextRange().getStartOffset()).isEqualTo(0); assertThat(issue.getTextRange().getEndOffset()).isEqualTo(24); - // One file-level issue in helloscala + // One file-level issue in helloscala, with secondary location List<ExternalIssue> externalIssues2 = result.externalIssuesFor(result.inputFile("xources/hello/helloscala.xoo")); assertThat(externalIssues2).hasSize(1); issue = externalIssues2.iterator().next(); - assertThat(issue.getFlowCount()).isZero(); + assertThat(issue.getFlowCount()).isEqualTo(2); assertThat(issue.getMsg()).isEqualTo("fix the bug here"); assertThat(issue.getRuleKey()).isEqualTo("rule3"); assertThat(issue.getSeverity()).isEqualTo(Severity.MAJOR); assertThat(issue.getType()).isEqualTo(IssueType.BUG); assertThat(issue.hasTextRange()).isFalse(); - + assertThat(issue.getFlow(0).getLocationCount()).isOne(); + assertThat(issue.getFlow(0).getLocation(0).getTextRange().getStartLine()).isOne(); + assertThat(issue.getFlow(1).getLocationCount()).isOne(); + assertThat(issue.getFlow(1).getLocation(0).getTextRange().getStartLine()).isEqualTo(3); + + // one issue is located in a non-existing file assertThat(logs.logs()).contains("External issues ignored for 1 unknown files, including: invalidFile"); |