use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class ComponentCleanerServiceTest method insertProjectData.
private DbData insertProjectData() {
ComponentDto componentDto = db.components().insertPublicProject();
ProjectDto project = dbClient.projectDao().selectByUuid(dbSession, componentDto.uuid()).get();
BranchDto branch = dbClient.branchDao().selectByUuid(dbSession, project.getUuid()).get();
RuleDefinitionDto rule = db.rules().insert();
IssueDto issue = db.issues().insert(rule, project, componentDto);
SnapshotDto analysis = db.components().insertSnapshot(componentDto);
mockResourceTypeAsValidProject();
return new DbData(project, branch, analysis, issue);
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class AddCommentActionTest method succeeds_on_public_project.
@Test
public void succeeds_on_public_project() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.logIn().registerComponents(project);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = dbTester.rules().insertHotspotRule();
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
String comment = randomAlphabetic(12);
newRequest(hotspot, comment).execute().assertNoContent();
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class AddCommentActionTest method fails_with_NotFoundException_if_issue_is_not_a_hotspot.
@Test
@UseDataProvider("ruleTypesByHotspot")
public void fails_with_NotFoundException_if_issue_is_not_a_hotspot(RuleType ruleType) {
ComponentDto project = dbTester.components().insertPublicProject();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = dbTester.rules().insert(t -> t.setType(ruleType));
IssueDto notAHotspot = dbTester.issues().insertIssue(rule, project, file, i -> i.setType(ruleType));
userSessionRule.logIn();
TestRequest request = newRequest(notAHotspot, randomAlphabetic(12));
assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("Hotspot '%s' does not exist", notAHotspot.getKey());
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class AddCommentActionTest method persists_comment_if_hotspot_status_changes_and_transition_done.
@Test
@UseDataProvider("validStatusAndResolutions")
public void persists_comment_if_hotspot_status_changes_and_transition_done(String currentStatus, @Nullable String currentResolution) {
long now = RANDOM.nextInt(232_323);
when(system2.now()).thenReturn(now);
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.logIn().registerComponents(project);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = dbTester.rules().insertHotspotRule();
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(currentStatus).setResolution(currentResolution));
String comment = randomAlphabetic(12);
newRequest(hotspot, comment).execute().assertNoContent();
IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(now), userSessionRule.getUuid());
ArgumentCaptor<DefaultIssue> defaultIssueCaptor = ArgumentCaptor.forClass(DefaultIssue.class);
verify(issueFieldsSetter).addComment(defaultIssueCaptor.capture(), eq(comment), eq(issueChangeContext));
verify(issueUpdater).saveIssueAndPreloadSearchResponseData(any(DbSession.class), defaultIssueCaptor.capture(), eq(issueChangeContext), eq(false));
// because it is mutated by FieldSetter and IssueUpdater, the same object must be passed to all methods
List<DefaultIssue> capturedDefaultIssues = defaultIssueCaptor.getAllValues();
assertThat(capturedDefaultIssues).hasSize(2);
assertThat(capturedDefaultIssues.get(0)).isSameAs(capturedDefaultIssues.get(1));
}
use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.
the class SearchActionTest method returns_hotspots_with_specified_cwes.
@Test
public void returns_hotspots_with_specified_cwes() {
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule1 = newRule(SECURITY_HOTSPOT);
RuleDefinitionDto rule2 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("cwe:117", "cwe:190")));
RuleDefinitionDto rule3 = newRule(SECURITY_HOTSPOT, r -> r.setSecurityStandards(of("owaspTop10:a1", "cwe:601")));
insertHotspot(project, file, rule1);
IssueDto hotspot2 = insertHotspot(project, file, rule2);
insertHotspot(project, file, rule3);
indexIssues();
SearchWsResponse response = newRequest(project).setParam("cwe", "117,190").executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactly(hotspot2.getKey());
}
Aggregations