Search in sources :

Example 86 with RuleDefinitionDto

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();
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 87 with RuleDefinitionDto

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();
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 88 with RuleDefinitionDto

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);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) Date(java.util.Date) Test(org.junit.Test)

Example 89 with RuleDefinitionDto

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();
}
Also used : DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Date(java.util.Date) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Maps(com.google.common.collect.Maps) Function(java.util.function.Function) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Stream(java.util.stream.Stream) Rule(org.junit.Rule) Map(java.util.Map) IssueTesting.newCodeReferenceIssue(org.sonar.db.issue.IssueTesting.newCodeReferenceIssue) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 90 with RuleDefinitionDto

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);
}
Also used : QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) QProfileChangeDto(org.sonar.db.qualityprofile.QProfileChangeDto) Test(org.junit.Test)

Aggregations

RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)654 Test (org.junit.Test)583 ComponentDto (org.sonar.db.component.ComponentDto)305 IssueDto (org.sonar.db.issue.IssueDto)219 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)144 UserDto (org.sonar.db.user.UserDto)96 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)93 DbTester (org.sonar.db.DbTester)93 System2 (org.sonar.api.utils.System2)91 UserSessionRule (org.sonar.server.tester.UserSessionRule)84 List (java.util.List)80 Rule (org.junit.Rule)77 DbClient (org.sonar.db.DbClient)68 RuleParamDto (org.sonar.db.rule.RuleParamDto)67 Mockito.mock (org.mockito.Mockito.mock)65 TestRequest (org.sonar.server.ws.TestRequest)64 Consumer (java.util.function.Consumer)63 EsTester (org.sonar.server.es.EsTester)61 Random (java.util.Random)60 RuleType (org.sonar.api.rules.RuleType)60