use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class ShowAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String hotspotKey = request.mandatoryParam(PARAM_HOTSPOT_KEY);
try (DbSession dbSession = dbClient.openSession(false)) {
IssueDto hotspot = hotspotWsSupport.loadHotspot(dbSession, hotspotKey);
Components components = loadComponents(dbSession, hotspot);
Users users = loadUsers(dbSession, hotspot);
RuleDefinitionDto rule = loadRule(dbSession, hotspot);
ShowWsResponse.Builder responseBuilder = ShowWsResponse.newBuilder();
formatHotspot(responseBuilder, hotspot, users);
formatComponents(components, responseBuilder);
formatRule(responseBuilder, rule);
formatTextRange(responseBuilder, hotspot);
formatFlows(dbSession, responseBuilder, hotspot);
FormattingContext formattingContext = formatChangeLogAndComments(dbSession, hotspot, users, components, responseBuilder);
formatUsers(responseBuilder, users, formattingContext);
writeProtobuf(responseBuilder.build(), request, response);
}
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class PersistIssuesStepTest method close_issue.
@Test
public void close_issue() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
RuleDefinitionDto rule = db.rules().insert();
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setCreatedAt(NOW - 1_000_000_000L).setUpdatedAt(NOW - 1_000_000_000L));
DiskCache.CacheAppender issueCacheAppender = protoIssueCache.newAppender();
issueCacheAppender.append(issue.toDefaultIssue().setStatus(STATUS_CLOSED).setResolution(RESOLUTION_FIXED).setSelectedAt(NOW).setNew(false).setChanged(true)).close();
TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context);
IssueDto issueReloaded = db.getDbClient().issueDao().selectByKey(db.getSession(), issue.getKey()).get();
assertThat(issueReloaded.getStatus()).isEqualTo(STATUS_CLOSED);
assertThat(issueReloaded.getResolution()).isEqualTo(RESOLUTION_FIXED);
assertThat(context.getStatistics().getAll()).contains(entry("inserts", "0"), entry("updates", "1"), entry("merged", "0"));
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class PersistIssuesStepTest method update_conflicting_issue.
@Test
public void update_conflicting_issue() {
RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
db.rules().insert(rule);
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project, null));
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setCreatedAt(NOW - 1_000_000_000L).setUpdatedAt(NOW + 1_000_000_000L));
issue = dbClient.issueDao().selectByKey(db.getSession(), issue.getKey()).get();
DiskCache.CacheAppender issueCacheAppender = protoIssueCache.newAppender();
when(system2.now()).thenReturn(NOW);
DefaultIssue defaultIssue = issue.toDefaultIssue().setStatus(STATUS_CLOSED).setResolution(RESOLUTION_FIXED).setSelectedAt(NOW).setNew(false).setChanged(true);
issueCacheAppender.append(defaultIssue).close();
TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context);
ArgumentCaptor<IssueDto> issueDtoCaptor = ArgumentCaptor.forClass(IssueDto.class);
verify(conflictResolver).resolve(eq(defaultIssue), issueDtoCaptor.capture(), any(IssueMapper.class));
assertThat(issueDtoCaptor.getValue().getKey()).isEqualTo(issue.getKey());
assertThat(context.getStatistics().getAll()).contains(entry("inserts", "0"), entry("updates", "1"), entry("merged", "1"));
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class PersistIssuesStepTest method insert_copied_issue_with_minimal_info.
@Test
public void insert_copied_issue_with_minimal_info() {
RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("xoo", "S01"));
db.rules().insert(rule);
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project, null));
when(system2.now()).thenReturn(NOW);
String issueKey = "ISSUE-2";
protoIssueCache.newAppender().append(new DefaultIssue().setKey(issueKey).setType(RuleType.CODE_SMELL).setRuleKey(rule.getKey()).setComponentUuid(file.uuid()).setComponentKey(file.getKey()).setProjectUuid(project.uuid()).setProjectKey(project.getKey()).setSeverity(BLOCKER).setStatus(STATUS_OPEN).setNew(false).setIsOnReferencedBranch(true).setCopied(true).setType(RuleType.BUG).setCreationDate(new Date(NOW)).setSelectedAt(NOW)).close();
TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context);
IssueDto result = dbClient.issueDao().selectOrFailByKey(session, issueKey);
assertThat(result.getKey()).isEqualTo(issueKey);
assertThat(result.getRuleKey()).isEqualTo(rule.getKey());
assertThat(result.getComponentUuid()).isEqualTo(file.uuid());
assertThat(result.getProjectUuid()).isEqualTo(project.uuid());
assertThat(result.getSeverity()).isEqualTo(BLOCKER);
assertThat(result.getStatus()).isEqualTo(STATUS_OPEN);
assertThat(result.getType()).isEqualTo(RuleType.BUG.getDbConstant());
assertThat(result.getTags()).isEmpty();
assertThat(result.isNewCodeReferenceIssue()).isFalse();
assertThat(dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList(issueKey))).isEmpty();
assertThat(context.getStatistics().getAll()).contains(entry("inserts", "1"), entry("updates", "0"), entry("merged", "0"));
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class IssueDaoTest method selectOpenByComponentUuid_should_correctly_map_required_fields.
@Test
public void selectOpenByComponentUuid_should_correctly_map_required_fields() {
RuleDefinitionDto rule = db.rules().insert();
ComponentDto project = db.components().insertPublicProject();
ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(BranchType.BRANCH));
ComponentDto file = db.components().insertComponent(newFileDto(projectBranch));
IssueDto fpIssue = db.issues().insert(rule, projectBranch, file, i -> i.setStatus("RESOLVED").setResolution("FALSE-POSITIVE"));
PrIssueDto fp = underTest.selectOpenByComponentUuids(db.getSession(), Collections.singletonList(file.uuid())).get(0);
assertThat(fp.getLine()).isEqualTo(fpIssue.getLine());
assertThat(fp.getMessage()).isEqualTo(fpIssue.getMessage());
assertThat(fp.getChecksum()).isEqualTo(fpIssue.getChecksum());
assertThat(fp.getRuleKey()).isEqualTo(fpIssue.getRuleKey());
assertThat(fp.getStatus()).isEqualTo(fpIssue.getStatus());
assertThat(fp.getLine()).isNotNull();
assertThat(fp.getLine()).isNotZero();
assertThat(fp.getMessage()).isNotNull();
assertThat(fp.getChecksum()).isNotNull();
assertThat(fp.getChecksum()).isNotEmpty();
assertThat(fp.getRuleKey()).isNotNull();
assertThat(fp.getStatus()).isNotNull();
assertThat(fp.getBranchKey()).isEqualTo("feature/foo");
assertThat(fp.getIssueUpdateDate()).isNotNull();
}
Aggregations