use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class ActiveRuleDaoTest method selectByTypeAndProfileUuids_ignores_rules_in_other_profiles.
@Test
public void selectByTypeAndProfileUuids_ignores_rules_in_other_profiles() {
RuleDefinitionDto rule1 = db.rules().insert(r -> r.setType(RuleType.VULNERABILITY.getDbConstant()));
ActiveRuleDto activeRule1 = createFor(profile2, rule1).setSeverity(BLOCKER);
underTest.insert(dbSession, activeRule1);
assertThat(underTest.selectByTypeAndProfileUuids(dbSession, singletonList(RuleType.VULNERABILITY.getDbConstant()), singletonList(profile1.getKee()))).isEmpty();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueIteratorFactoryTest method extract_file_path.
@Test
public void extract_file_path() {
RuleDefinitionDto rule = dbTester.rules().insert();
ComponentDto project = dbTester.components().insertPrivateProject();
ComponentDto module = dbTester.components().insertComponent(newModuleDto(project));
ComponentDto fileInRootDir = dbTester.components().insertComponent(newFileDto(module).setPath("pom.xml"));
ComponentDto fileInSubDir = dbTester.components().insertComponent(newFileDto(module).setPath("src/main/java/Action.java"));
IssueDto projectIssue = dbTester.issues().insert(rule, project, project);
IssueDto fileInSubDirIssue = dbTester.issues().insert(rule, project, fileInSubDir);
IssueDto fileInRootDirIssue = dbTester.issues().insert(rule, project, fileInRootDir);
IssueDto moduleIssue = dbTester.issues().insert(rule, project, module);
Map<String, IssueDoc> issuesByKey = issuesByKey();
assertThat(issuesByKey).hasSize(4);
assertThat(issuesByKey.get(fileInSubDirIssue.getKey()).filePath()).isEqualTo("src/main/java/Action.java");
assertThat(issuesByKey.get(fileInRootDirIssue.getKey()).filePath()).isEqualTo("pom.xml");
assertThat(issuesByKey.get(moduleIssue.getKey()).filePath()).isNull();
assertThat(issuesByKey.get(projectIssue.getKey()).filePath()).isNull();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueIteratorFactoryTest method iterator_over_one_issue.
@Test
public void iterator_over_one_issue() {
RuleDefinitionDto rule = dbTester.rules().insert();
ComponentDto project = dbTester.components().insertPrivateProject();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project).setPath("src/main/java/Action.java"));
IssueDto expected = dbTester.issues().insert(rule, project, file, t -> t.setResolution("FIXED").setStatus("RESOLVED").setSeverity("BLOCKER").setManualSeverity(false).setAssigneeUuid("uuid-of-guy1").setAuthorLogin("guy2").setChecksum("FFFFF").setGap(2D).setEffort(10L).setMessage(null).setLine(444).setRuleUuid(rule.getUuid()).setTags(List.of("tag1", "tag2", "tag3")).setCreatedAt(1400000000000L).setUpdatedAt(1400000000000L).setIssueCreationDate(new Date(1115848800000L)).setIssueUpdateDate(new Date(1356994800000L)).setIssueCloseDate(null).setType(2));
Map<String, IssueDoc> issuesByKey = issuesByKey();
assertThat(issuesByKey).hasSize(1);
IssueDoc issue = issuesByKey.get(expected.getKey());
assertThat(issue.key()).isEqualTo(expected.getKey());
assertThat(issue.resolution()).isEqualTo("FIXED");
assertThat(issue.status()).isEqualTo("RESOLVED");
assertThat(issue.severity()).isEqualTo("BLOCKER");
assertThat(issue.assigneeUuid()).isEqualTo("uuid-of-guy1");
assertThat(issue.authorLogin()).isEqualTo("guy2");
assertThat(issue.line()).isEqualTo(444);
assertThat(issue.ruleUuid()).isEqualTo(rule.getUuid());
assertThat(issue.componentUuid()).isEqualTo(file.uuid());
assertThat(issue.projectUuid()).isEqualTo(file.projectUuid());
assertThat(issue.moduleUuid()).isEqualTo(file.projectUuid());
assertThat(issue.modulePath()).isEqualTo(file.moduleUuidPath());
assertThat(issue.directoryPath()).isEqualTo("src/main/java");
assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java");
assertThat(issue.getTags()).containsOnly("tag1", "tag2", "tag3");
assertThat(issue.effort().toMinutes()).isPositive();
assertThat(issue.type().getDbConstant()).isEqualTo(2);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueIteratorFactoryTest method iterator_over_issue_from_project.
@Test
public void iterator_over_issue_from_project() {
RuleDefinitionDto rule = dbTester.rules().insert();
ComponentDto project1 = dbTester.components().insertPrivateProject();
ComponentDto module1 = dbTester.components().insertComponent(newModuleDto(project1));
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(module1));
String[] project1IssueKeys = Stream.of(project1, module1, file1).map(project1Component -> dbTester.issues().insert(rule, project1, project1Component).getKey()).toArray(String[]::new);
ComponentDto project2 = dbTester.components().insertPrivateProject();
ComponentDto module2 = dbTester.components().insertComponent(newModuleDto(project2));
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(module2));
String[] project2IssueKeys = Stream.of(project2, module2, file2).map(project2Component -> dbTester.issues().insert(rule, project2, project2Component).getKey()).toArray(String[]::new);
assertThat(issuesByKey(factory -> factory.createForProject(project1.uuid())).keySet()).containsOnly(project1IssueKeys);
assertThat(issuesByKey(factory -> factory.createForProject(project2.uuid())).keySet()).containsOnly(project2IssueKeys);
assertThat(issuesByKey(factory -> factory.createForProject("does not exist"))).isEmpty();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class ActiveRuleChangeTest method toDto.
@Test
public void toDto() {
QProfileDto profile = newQualityProfileDto();
ActiveRuleKey key = ActiveRuleKey.of(profile, RuleKey.of("P1", "R1"));
String ruleUuid = Uuids.createFast();
ActiveRuleChange underTest = new ActiveRuleChange(ACTIVATED, key, new RuleDefinitionDto().setUuid(ruleUuid));
QProfileChangeDto result = underTest.toDto(A_USER_UUID);
assertThat(result.getChangeType()).isEqualTo(ACTIVATED.name());
assertThat(result.getRulesProfileUuid()).isEqualTo(profile.getRulesProfileUuid());
assertThat(result.getUserUuid()).isEqualTo(A_USER_UUID);
assertThat(result.getDataAsMap()).containsEntry("ruleUuid", ruleUuid);
}
Aggregations