use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class SendIssueNotificationsStepTest method sendIssueChangeNotification.
private void sendIssueChangeNotification(long issueCreatedAt) {
UserDto user = db.users().insertUser();
ComponentDto project = newPrivateProjectDto().setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName());
analysisMetadataHolder.setProject(Project.from(project));
ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName());
treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(project.getDbKey()).setPublicKey(project.getKey()).setName(project.longName()).setUuid(project.uuid()).addChildren(builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()).build());
RuleDefinitionDto ruleDefinitionDto = newRule();
RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)];
DefaultIssue issue = prepareIssue(issueCreatedAt, user, project, file, ruleDefinitionDto, randomTypeExceptHotspot);
IssuesChangesNotification issuesChangesNotification = mock(IssuesChangesNotification.class);
when(notificationService.hasProjectSubscribersForTypes(project.uuid(), NOTIF_TYPES)).thenReturn(true);
when(notificationFactory.newIssuesChangesNotification(anySet(), anyMap())).thenReturn(issuesChangesNotification);
underTest.execute(new TestComputationStepContext());
verify(notificationFactory).newIssuesChangesNotification(issuesSetCaptor.capture(), assigneeByUuidCaptor.capture());
assertThat(issuesSetCaptor.getValue()).hasSize(1);
assertThat(issuesSetCaptor.getValue().iterator().next()).isEqualTo(issue);
assertThat(assigneeByUuidCaptor.getValue()).hasSize(1);
assertThat(assigneeByUuidCaptor.getValue().get(user.getUuid())).isNotNull();
verify(notificationService).hasProjectSubscribersForTypes(project.uuid(), NOTIF_TYPES);
verify(notificationService).deliverEmails(singleton(issuesChangesNotification));
verify(notificationService).deliver(issuesChangesNotification);
verifyNoMoreInteractions(notificationService);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class ComponentDaoTest method selectComponentsFromBranchesThatHaveOpenIssues_returns_nothing_if_no_open_issues_in_sibling_branches.
@Test
public void selectComponentsFromBranchesThatHaveOpenIssues_returns_nothing_if_no_open_issues_in_sibling_branches() {
final ProjectDto project = db.components().insertPrivateProjectDto(b -> b.setName("foo"));
ComponentDto branch1 = db.components().insertProjectBranch(project, ComponentTesting.newBranchDto(project.getUuid(), BRANCH).setKey("branch1"));
ComponentDto fileBranch1 = db.components().insertComponent(ComponentTesting.newFileDto(branch1));
RuleDefinitionDto rule = db.rules().insert();
db.issues().insert(new IssueDto().setKee("i").setComponent(fileBranch1).setProject(branch1).setRule(rule).setStatus(STATUS_CLOSED));
List<KeyWithUuidDto> result = underTest.selectComponentsFromBranchesThatHaveOpenIssues(db.getSession(), singleton(branch1.uuid()));
assertThat(result).isEmpty();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class PurgeCommandsTest method deleteIssues_deletes_issue_changes.
@Test
@UseDataProvider("projectsAndViews")
public void deleteIssues_deletes_issue_changes(ComponentDto projectOrView) {
RuleDefinitionDto rule = dbTester.rules().insert();
dbTester.components().insertComponent(projectOrView);
ComponentDto file = dbTester.components().insertComponent(newFileDto(projectOrView));
int count = 5;
IntStream.range(0, count).forEach(i -> {
IssueDto issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(projectOrView));
dbTester.issues().insertChange(issue);
issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(file));
dbTester.issues().insertChange(issue);
});
underTest.deleteIssues(projectOrView.uuid());
assertThat(dbTester.countRowsOfTable("ISSUE_CHANGES")).isZero();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class PurgeCommandsTest method deleteIssues_deletes_new_code_reference_issues.
@Test
@UseDataProvider("projectsAndViews")
public void deleteIssues_deletes_new_code_reference_issues(ComponentDto projectOrView) {
RuleDefinitionDto rule = dbTester.rules().insert();
dbTester.components().insertComponent(projectOrView);
ComponentDto file = dbTester.components().insertComponent(newFileDto(projectOrView));
List<String> issueKeys = new ArrayList<>();
int count = 5;
IntStream.range(0, count).forEach(i -> {
IssueDto issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(projectOrView));
dbTester.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(issue));
issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(file));
dbTester.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(issue));
issueKeys.add("'" + issue.getKey() + "'");
});
underTest.deleteIssues(projectOrView.uuid());
assertThat(dbTester.countSql("select count(uuid) from new_code_reference_issues where issue_key in (" + String.join(", ", issueKeys) + ")")).isZero();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueDbTester method insertHotspot.
/**
* Inserts a Security Hotspot.
*/
@SafeVarargs
public final IssueDto insertHotspot(ComponentDto project, ComponentDto file, Consumer<IssueDto>... populators) {
RuleDefinitionDto rule = db.rules().insertHotspotRule();
IssueDto issue = newIssue(rule, project, file).setType(SECURITY_HOTSPOT).setStatus(Issue.STATUS_TO_REVIEW).setResolution(null);
stream(populators).forEach(p -> p.accept(issue));
return insertHotspot(issue);
}
Aggregations