use of org.sonarsource.sonarlint.core.analysis.api.TextRange in project sonarlint-core by SonarSource.
the class DefaultClientIssueTests method transformIssue.
@Test
void transformIssue() {
var currentFile = mock(InputComponent.class);
var currentFileKey = "currentFileKey";
when(currentFile.key()).thenReturn(currentFileKey);
var anotherFile = mock(InputComponent.class);
when(anotherFile.key()).thenReturn("anotherFileKey");
textRange = new TextRange(1, 2, 2, 3);
when(rule.getName()).thenReturn("name");
when(rule.getType()).thenReturn("BUG");
when(rule.getSeverity()).thenReturn("MAJOR");
var issue = new Issue("rule:S123", "msg", textRange, clientInputFile, null, null);
var underTest = new DefaultClientIssue(issue, rule);
assertThat(underTest.getStartLine()).isEqualTo(1);
assertThat(underTest.getStartLineOffset()).isEqualTo(2);
assertThat(underTest.getEndLine()).isEqualTo(2);
assertThat(underTest.getEndLineOffset()).isEqualTo(3);
assertThat(underTest.getMessage()).isEqualTo("msg");
assertThat(underTest.getSeverity()).isEqualTo("MAJOR");
assertThat(underTest.getType()).isEqualTo("BUG");
assertThat(underTest.getInputFile()).isEqualTo(clientInputFile);
}
use of org.sonarsource.sonarlint.core.analysis.api.TextRange in project sonarlint-core by SonarSource.
the class ConnectedModeTest method canFetchHotspot.
@Test
public void canFetchHotspot() throws InvalidProtocolBufferException {
assumeTrue("SonarQube should support opening security hotspots", ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(8, 6));
analyzeMavenProject(PROJECT_KEY_JAVA_HOTSPOT);
var securityHotspotsService = new ServerApi(endpointParams(ORCHESTRATOR), sqHttpClient()).hotspot();
var remoteHotspot = securityHotspotsService.fetch(new GetSecurityHotspotRequestParams(getFirstHotspotKey(PROJECT_KEY_JAVA_HOTSPOT), PROJECT_KEY_JAVA_HOTSPOT));
assertThat(remoteHotspot).isNotEmpty();
var actualHotspot = remoteHotspot.get();
assertThat(actualHotspot.message).isEqualTo("Make sure using this hardcoded IP address is safe here.");
assertThat(actualHotspot.filePath).isEqualTo("src/main/java/foo/Foo.java");
assertThat(actualHotspot.textRange).isEqualToComparingFieldByField(new TextRange(5, 14, 5, 29));
assertThat(actualHotspot.author).isEmpty();
assertThat(actualHotspot.status).isEqualTo(ServerHotspot.Status.TO_REVIEW);
assertThat(actualHotspot.resolution).isNull();
assertThat(actualHotspot.rule.key).isEqualTo("java:S1313");
}
use of org.sonarsource.sonarlint.core.analysis.api.TextRange in project sonarlint-core by SonarSource.
the class IssueStorePaths method toApiIssue.
public static ServerIssue toApiIssue(Sonarlint.ServerIssue pbIssue, String idePath) {
var issue = new DefaultServerIssue();
issue.setAssigneeLogin(pbIssue.getAssigneeLogin());
issue.setLineHash(pbIssue.getLineHash());
if (pbIssue.getPrimaryLocation().hasTextRange()) {
var textRange = pbIssue.getPrimaryLocation().getTextRange();
issue.setTextRange(new TextRange(textRange.getStartLine(), textRange.getStartLineOffset(), textRange.getEndLine(), textRange.getEndLineOffset()));
issue.setCodeSnippet(trimToNull(pbIssue.getPrimaryLocation().getCodeSnippet()));
}
issue.setFilePath(idePath);
issue.setMessage(pbIssue.getPrimaryLocation().getMsg());
issue.setSeverity(pbIssue.getSeverity());
issue.setType(pbIssue.getType());
issue.setCreationDate(Instant.ofEpochMilli(pbIssue.getCreationDate()));
issue.setResolution(pbIssue.getResolution());
issue.setKey(pbIssue.getKey());
issue.setRuleKey(pbIssue.getRuleRepository() + ":" + pbIssue.getRuleKey());
for (Sonarlint.ServerIssue.Flow f : pbIssue.getFlowList()) {
issue.getFlows().add(new DefaultServerFlow(f.getLocationList()));
}
return issue;
}
Aggregations