use of org.sonar.api.batch.sensor.issue.ExternalIssue in project sonarqube by SonarSource.
the class ExternalIssueImporterTest method import_issue_with_complete_primary_location.
@Test
public void import_issue_with_complete_primary_location() {
ReportParser.TextRange input = new ReportParser.TextRange();
input.startLine = 1;
input.startColumn = 4;
input.endLine = 2;
input.endColumn = 3;
runOn(newIssue(input));
assertThat(context.allExternalIssues()).hasSize(1);
ExternalIssue output = context.allExternalIssues().iterator().next();
assertSameRange(input, output.primaryLocation().textRange());
}
use of org.sonar.api.batch.sensor.issue.ExternalIssue in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method should_save_external_issue.
@Test
public void should_save_external_issue() {
InputFile file = new TestInputFileBuilder("foo", "src/Foo.php").build();
DefaultExternalIssue externalIssue = new DefaultExternalIssue(project).at(new DefaultIssueLocation().on(file));
underTest.store(externalIssue);
ArgumentCaptor<ExternalIssue> argumentCaptor = ArgumentCaptor.forClass(ExternalIssue.class);
verify(moduleIssues).initAndAddExternalIssue(argumentCaptor.capture());
assertThat(argumentCaptor.getValue()).isEqualTo(externalIssue);
}
use of org.sonar.api.batch.sensor.issue.ExternalIssue in project sonarqube by SonarSource.
the class IssuePublisher method createReportExternalIssue.
private static ScannerReport.ExternalIssue createReportExternalIssue(ExternalIssue issue, int componentRef) {
// primary location of an external issue must have a message
String primaryMessage = issue.primaryLocation().message();
Severity severity = Severity.valueOf(issue.severity().name());
IssueType issueType = IssueType.valueOf(issue.type().name());
ScannerReport.ExternalIssue.Builder builder = ScannerReport.ExternalIssue.newBuilder();
ScannerReport.IssueLocation.Builder locationBuilder = IssueLocation.newBuilder();
ScannerReport.TextRange.Builder textRangeBuilder = ScannerReport.TextRange.newBuilder();
// non-null fields
builder.setSeverity(severity);
builder.setType(issueType);
builder.setEngineId(issue.engineId());
builder.setRuleId(issue.ruleId());
builder.setMsg(primaryMessage);
locationBuilder.setMsg(primaryMessage);
locationBuilder.setComponentRef(componentRef);
TextRange primaryTextRange = issue.primaryLocation().textRange();
if (primaryTextRange != null) {
builder.setTextRange(toProtobufTextRange(textRangeBuilder, primaryTextRange));
}
Long effort = issue.remediationEffort();
if (effort != null) {
builder.setEffort(effort);
}
applyFlows(builder::addFlow, locationBuilder, textRangeBuilder, issue.flows());
return builder.build();
}
use of org.sonar.api.batch.sensor.issue.ExternalIssue in project sonarqube by SonarSource.
the class ExternalIssueImporterTest method import_issue_with_minimal_info.
@Test
public void import_issue_with_minimal_info() {
ReportParser.Report report = new ReportParser.Report();
ReportParser.Issue input = new ReportParser.Issue();
input.engineId = "findbugs";
input.ruleId = "123";
input.severity = "CRITICAL";
input.type = "BUG";
input.primaryLocation = new ReportParser.Location();
input.primaryLocation.filePath = sourceFile.getProjectRelativePath();
input.primaryLocation.message = randomAlphabetic(5);
report.issues = new ReportParser.Issue[] { input };
ExternalIssueImporter underTest = new ExternalIssueImporter(this.context, report);
underTest.execute();
assertThat(context.allExternalIssues()).hasSize(1);
ExternalIssue output = context.allExternalIssues().iterator().next();
assertThat(output.engineId()).isEqualTo(input.engineId);
assertThat(output.ruleId()).isEqualTo(input.ruleId);
assertThat(output.severity()).isEqualTo(Severity.valueOf(input.severity));
assertThat(output.remediationEffort()).isNull();
assertThat(logs.logs(LoggerLevel.INFO)).contains("Imported 1 issue in 1 file");
}
Aggregations