use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class IssueChangeDtoTest method to_field_diffs_with_create_at.
@Test
public void to_field_diffs_with_create_at() {
IssueChangeDto changeDto = new IssueChangeDto().setKey("EFGH").setUserUuid("user_uuid").setChangeData("Some text").setIssueKey("ABCDE").setCreatedAt(System2.INSTANCE.now());
FieldDiffs diffs = changeDto.toFieldDiffs();
assertThat(diffs.userUuid()).isEqualTo("user_uuid");
assertThat(diffs.issueKey()).isEqualTo("ABCDE");
assertThat(diffs.creationDate()).isNotNull();
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class IssueChangeDtoTest method create_from_diff.
@Test
public void create_from_diff() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", "INFO", "BLOCKER");
diffs.setUserUuid("user_uuid");
diffs.setCreationDate(parseDate("2015-01-13"));
IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs, "project_uuid");
assertThat(dto.getChangeData()).isEqualTo("severity=INFO|BLOCKER");
assertThat(dto.getChangeType()).isEqualTo("diff");
assertThat(dto.getCreatedAt()).isNotNull();
assertThat(dto.getUpdatedAt()).isNotNull();
assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
assertThat(dto.getUserUuid()).isEqualTo("user_uuid");
assertThat(dto.getIssueChangeCreationDate()).isEqualTo(parseDate("2015-01-13").getTime());
assertThat(dto.getProjectUuid()).isEqualTo("project_uuid");
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class IssueWorkflowTest method addResolutionAndStatusChange.
private void addResolutionAndStatusChange(DefaultIssue issue, Date creationDate, String previousStatus, String newStatus, @Nullable String previousResolution, @Nullable String newResolution) {
checkArgument(previousResolution != null || newResolution != null, "At least one resolution must be non null");
FieldDiffs fieldDiffs = new FieldDiffs().setCreationDate(creationDate).setDiff("status", previousStatus, newStatus).setDiff("resolution", emptyIfNull(previousResolution), emptyIfNull(newResolution));
issue.addChange(fieldDiffs);
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class PersistIssuesStepTest method insert_copied_issue.
@Test
public void insert_copied_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));
when(system2.now()).thenReturn(NOW);
String issueKey = "ISSUE-1";
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).setTags(singletonList("test")).setNew(false).setCopied(true).setType(RuleType.BUG).setCreationDate(new Date(NOW)).setSelectedAt(NOW).addComment(new DefaultIssueComment().setKey("COMMENT").setIssueKey(issueKey).setUserUuid("john_uuid").setMarkdownText("Some text").setCreatedAt(new Date(NOW)).setUpdatedAt(new Date(NOW)).setNew(true)).setCurrentChange(new FieldDiffs().setIssueKey(issueKey).setUserUuid("john_uuid").setDiff("technicalDebt", null, 1L).setCreationDate(new Date(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()).containsExactlyInAnyOrder("test");
assertThat(result.isNewCodeReferenceIssue()).isFalse();
List<IssueChangeDto> changes = dbClient.issueChangeDao().selectByIssueKeys(session, Arrays.asList(issueKey));
assertThat(changes).extracting(IssueChangeDto::getChangeType).containsExactly(IssueChangeDto.TYPE_COMMENT, IssueChangeDto.TYPE_FIELD_CHANGE);
assertThat(context.getStatistics().getAll()).contains(entry("inserts", "1"), entry("updates", "0"), entry("merged", "0"));
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class ComponentIssuesLoader method loadLatestDiffChangesForReopeningOfClosedIssues.
/**
* To be efficient both in term of memory and speed:
* <ul>
* <li>only diff changes are loaded from DB, sorted by issue and then change creation date</li>
* <li>data from DB is streamed</li>
* <li>only the latest change(s) with status and resolution are added to the {@link DefaultIssue} objects</li>
* </ul>
*/
private void loadLatestDiffChangesForReopeningOfClosedIssues(DbSession dbSession, Collection<DefaultIssue> issues) {
Map<String, DefaultIssue> issuesByKey = issues.stream().collect(uniqueIndex(DefaultIssue::key));
dbClient.issueChangeDao().scrollDiffChangesOfIssues(dbSession, issuesByKey.keySet(), new ResultHandler<IssueChangeDto>() {
private DefaultIssue currentIssue = null;
private boolean previousStatusFound = false;
private boolean previousResolutionFound = false;
@Override
public void handleResult(ResultContext<? extends IssueChangeDto> resultContext) {
IssueChangeDto issueChangeDto = resultContext.getResultObject();
if (currentIssue == null || !currentIssue.key().equals(issueChangeDto.getIssueKey())) {
currentIssue = issuesByKey.get(issueChangeDto.getIssueKey());
previousStatusFound = false;
previousResolutionFound = false;
}
if (currentIssue != null) {
FieldDiffs fieldDiffs = issueChangeDto.toFieldDiffs();
boolean hasPreviousStatus = fieldDiffs.get("status") != null;
boolean hasPreviousResolution = fieldDiffs.get("resolution") != null;
if ((!previousStatusFound && hasPreviousStatus) || (!previousResolutionFound && hasPreviousResolution)) {
currentIssue.addChange(fieldDiffs);
}
previousStatusFound |= hasPreviousStatus;
previousResolutionFound |= hasPreviousResolution;
}
}
});
}
Aggregations