use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueIndexerTest method commitAndIndexIssues_commits_db_transaction_and_adds_issues_to_index.
@Test
public void commitAndIndexIssues_commits_db_transaction_and_adds_issues_to_index() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
// insert issues in db without committing
IssueDto issue1 = IssueTesting.newIssue(rule, project, file);
IssueDto issue2 = IssueTesting.newIssue(rule, project, file);
db.getDbClient().issueDao().insert(db.getSession(), issue1, issue2);
underTest.commitAndIndexIssues(db.getSession(), asList(issue1, issue2));
// issues are persisted and indexed
assertThatIndexHasOnly(issue1, issue2);
assertThatDbHasOnly(issue1, issue2);
assertThatEsQueueTableHasSize(0);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueIndexerTest method verify_indexed_fields.
@Test
public void verify_indexed_fields() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java/foo"));
ComponentDto file = db.components().insertComponent(newFileDto(project, dir, "F1"));
IssueDto issue = db.issues().insert(rule, project, file);
underTest.indexAllIssues();
IssueDoc doc = es.getDocuments(TYPE_ISSUE, IssueDoc.class).get(0);
assertThat(doc.getId()).isEqualTo(issue.getKey());
assertThat(doc.assigneeUuid()).isEqualTo(issue.getAssigneeUuid());
assertThat(doc.authorLogin()).isEqualTo(issue.getAuthorLogin());
assertThat(doc.componentUuid()).isEqualTo(file.uuid());
assertThat(doc.projectUuid()).isEqualTo(project.uuid());
assertThat(doc.branchUuid()).isEqualTo(project.uuid());
assertThat(doc.isMainBranch()).isTrue();
assertThat(doc.closeDate()).isEqualTo(issue.getIssueCloseDate());
assertThat(doc.creationDate()).isEqualToIgnoringMillis(issue.getIssueCreationDate());
assertThat(doc.directoryPath()).isEqualTo(dir.path());
assertThat(doc.filePath()).isEqualTo(file.path());
assertThat(doc.scope()).isEqualTo(IssueScope.MAIN);
assertThat(doc.language()).isEqualTo(issue.getLanguage());
assertThat(doc.line()).isEqualTo(issue.getLine());
// functional date
assertThat(doc.updateDate()).isEqualToIgnoringMillis(new Date(issue.getIssueUpdateTime()));
assertThat(doc.getCwe()).containsExactlyInAnyOrder(SecurityStandards.UNKNOWN_STANDARD);
assertThat(doc.getOwaspTop10()).isEmpty();
assertThat(doc.getSansTop25()).isEmpty();
assertThat(doc.getSonarSourceSecurityCategory()).isEqualTo(SQCategory.OTHERS);
assertThat(doc.getVulnerabilityProbability()).isEqualTo(VulnerabilityProbability.LOW);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueIndexerTest method indexing_errors_during_commitAndIndexIssues_are_recovered.
@Test
public void indexing_errors_during_commitAndIndexIssues_are_recovered() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
// insert issues in db without committing
IssueDto issue1 = IssueTesting.newIssue(rule, project, file);
IssueDto issue2 = IssueTesting.newIssue(rule, project, file);
db.getDbClient().issueDao().insert(db.getSession(), issue1, issue2);
// index is read-only
es.lockWrites(TYPE_ISSUE);
underTest.commitAndIndexIssues(db.getSession(), asList(issue1, issue2));
// issues are persisted but not indexed
assertThatIndexHasSize(0);
assertThatDbHasOnly(issue1, issue2);
assertThatEsQueueTableHasSize(2);
// re-enable write on index
es.unlockWrites(TYPE_ISSUE);
// emulate the recovery daemon
IndexingResult result = recover();
assertThatEsQueueTableHasSize(0);
assertThatIndexHasOnly(issue1, issue2);
assertThat(result.isSuccess()).isTrue();
assertThat(result.getTotal()).isEqualTo(2L);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueIndexerTest method indexOnAnalysis_indexes_the_issues_of_project.
@Test
public void indexOnAnalysis_indexes_the_issues_of_project() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue = db.issues().insert(rule, project, file);
ComponentDto otherProject = db.components().insertPrivateProject();
ComponentDto fileOnOtherProject = db.components().insertComponent(newFileDto(otherProject));
underTest.indexOnAnalysis(project.uuid());
assertThatIndexHasOnly(issue);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class HotspotRuleDescriptionTest method parse_returns_all_empty_fields_when_empty_description.
@Test
public void parse_returns_all_empty_fields_when_empty_description() {
RuleDefinitionDto dto = RuleTesting.newRule().setDescription("");
HotspotRuleDescription result = HotspotRuleDescription.from(dto);
assertThat(result.getRisk()).isEmpty();
assertThat(result.getVulnerable()).isEmpty();
assertThat(result.getFixIt()).isEmpty();
}
Aggregations