public static IssueChangeDto of(String issueKey, FieldDiffs diffs) { IssueChangeDto dto = newDto(issueKey); dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE); dto.setChangeData(diffs.toEncodedString()); dto.setUserUuid(diffs.userUuid()); Date createdAt = requireNonNull(diffs.creationDate(), "Diffs created at must not be null"); dto.setIssueChangeCreationDate(createdAt.getTime()); return dto; }
public static IssueChangeDto of(DefaultIssueComment comment) { IssueChangeDto dto = newDto(comment.issueKey()); dto.setKey(comment.key()); dto.setChangeType(IssueChangeDto.TYPE_COMMENT); dto.setChangeData(comment.markdownText()); dto.setUserUuid(comment.userUuid()); Date createdAt = requireNonNull(comment.createdAt(), "Comment created at must not be null"); dto.setIssueChangeCreationDate(createdAt.getTime()); return dto; }
@Test public void select_issue_changelog_from_issue_key() { IssueDto issue1 = db.issues().insertIssue(); db.issues().insertChange(issue1, c -> c.setChangeType(TYPE_FIELD_CHANGE).setChangeData("severity=MAJOR|BLOCKER")); IssueDto issue2 = db.issues().insertIssue(); db.issues().insertChange(issue2); List<FieldDiffs> changelog = underTest.selectChangelogByIssue(db.getSession(), issue1.getKey()); assertThat(changelog).hasSize(1); assertThat(changelog.get(0).diffs()).hasSize(1); assertThat(changelog.get(0).diffs().get("severity").newValue()).isEqualTo("BLOCKER"); assertThat(changelog.get(0).diffs().get("severity").oldValue()).isEqualTo("MAJOR"); assertThat(underTest.selectChangelogByIssue(db.getSession(), "unknown")).isEmpty(); }
private Consumer<CommentData> updateComment(DbSession dbSession) { return commentData -> { commentData.getIssueChangeDto().setUpdatedAt(system2.now()); commentData.getIssueChangeDto().setChangeData(commentData.getRequest().getText()); dbClient.issueChangeDao().update(dbSession, commentData.getIssueChangeDto()); dbSession.commit(); }; }
@Test public void to_field_diffs_with_issue_creation_date() { IssueChangeDto changeDto = new IssueChangeDto() .setKey("EFGH") .setUserUuid("user_uuid") .setChangeData("Some text") .setIssueKey("ABCDE") .setIssueChangeCreationDate(System2.INSTANCE.now()); FieldDiffs diffs = changeDto.toFieldDiffs(); assertThat(diffs.userUuid()).isEqualTo("user_uuid"); assertThat(diffs.issueKey()).isEqualTo("ABCDE"); assertThat(diffs.creationDate()).isNotNull(); }
@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(); }
@Test public void to_comment() { IssueChangeDto changeDto = new IssueChangeDto() .setKey("EFGH") .setUserUuid("user_uuid") .setChangeData("Some text") .setIssueKey("ABCDE") .setCreatedAt(System2.INSTANCE.now()) .setUpdatedAt(System2.INSTANCE.now()); DefaultIssueComment comment = changeDto.toComment(); assertThat(comment.key()).isEqualTo("EFGH"); assertThat(comment.markdownText()).isEqualTo("Some text"); assertThat(comment.createdAt()).isNotNull(); assertThat(comment.updatedAt()).isNotNull(); assertThat(comment.userUuid()).isEqualTo("user_uuid"); assertThat(comment.issueKey()).isEqualTo("ABCDE"); }
public static IssueChangeDto newIssuechangeDto(IssueDto issue) { return new IssueChangeDto() .setKey(UuidFactoryFast.getInstance().create()) .setIssueKey(issue.getKey()) .setChangeData("data_" + randomAlphanumeric(40)) .setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE) .setUserUuid("userUuid_" + randomAlphanumeric(40)) .setIssueChangeCreationDate(nextLong()) .setCreatedAt(nextLong()) .setUpdatedAt(nextLong()); }
@Test public void update_unknown_key() { IssueDto issue = db.issues().insertIssue(); IssueChangeDto issueChange = db.issues().insertChange(issue); assertThat(underTest.update(db.getSession(), new IssueChangeDto() .setKey("UNKNOWN") .setIssueKey("other_issue_uuid") .setChangeData("new comment") .setUpdatedAt(DateUtils.parseDate("2013-06-30").getTime()))) .isFalse(); assertThat(underTest.selectByIssueKeys(db.getSession(), singletonList(issue.getKey()))) .extracting(IssueChangeDto::getKey, IssueChangeDto::getIssueKey, IssueChangeDto::getChangeData, IssueChangeDto::getChangeType, IssueChangeDto::getIssueChangeCreationDate, IssueChangeDto::getCreatedAt, IssueChangeDto::getUpdatedAt) .containsExactlyInAnyOrder( tuple(issueChange.getKey(), issue.getKey(), issueChange.getChangeData(), issueChange.getChangeType(), issueChange.getIssueChangeCreationDate(), issueChange.getCreatedAt(), issueChange.getUpdatedAt())); }
@Test @UseDataProvider("statusOrResolutionFieldName") public void loadLatestDiffChangesForReopeningOfClosedIssues_add_diff_change_with_most_recent_status_or_resolution(String statusOrResolutionFieldName) { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); RuleDefinitionDto rule = dbTester.rules().insert(); IssueDto issue = dbTester.issues().insert(rule, project, file); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith(statusOrResolutionFieldName, "val1")).setIssueChangeCreationDate(5)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith(statusOrResolutionFieldName, "val2")).setIssueChangeCreationDate(20)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith(statusOrResolutionFieldName, "val3")).setIssueChangeCreationDate(13)); ComponentIssuesLoader underTest = new ComponentIssuesLoader(dbClient, null /* not used in method */, null /* not used in method */, newConfiguration("0"), null /* not used by method */); DefaultIssue defaultIssue = new DefaultIssue().setKey(issue.getKey()); underTest.loadLatestDiffChangesForReopeningOfClosedIssues(ImmutableList.of(defaultIssue)); assertThat(defaultIssue.changes()) .hasSize(1); assertThat(defaultIssue.changes()) .extracting(t -> t.get(statusOrResolutionFieldName)) .filteredOn(t -> hasValue(t, "val2")) .hasSize(1); }
@Test public void loadLatestDiffChangesForReopeningOfClosedIssues_add_single_diff_change_when_most_recent_status_and_resolution_is_the_same_diff() { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); RuleDefinitionDto rule = dbTester.rules().insert(); IssueDto issue = dbTester.issues().insert(rule, project, file); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus1")).setIssueChangeCreationDate(5)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus2")).setIssueChangeCreationDate(19)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus3", "resolution", "valRes3")).setIssueChangeCreationDate(20)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("resolution", "valRes4")).setIssueChangeCreationDate(13)); ComponentIssuesLoader underTest = new ComponentIssuesLoader(dbClient, null /* not used in method */, null /* not used in method */, newConfiguration("0"), null /* not used by method */); DefaultIssue defaultIssue = new DefaultIssue().setKey(issue.getKey()); underTest.loadLatestDiffChangesForReopeningOfClosedIssues(ImmutableList.of(defaultIssue)); assertThat(defaultIssue.changes()) .hasSize(1); assertThat(defaultIssue.changes()) .extracting(t -> t.get("status")) .filteredOn(t -> hasValue(t, "valStatus3")) .hasSize(1); assertThat(defaultIssue.changes()) .extracting(t -> t.get("resolution")) .filteredOn(t -> hasValue(t, "valRes3")) .hasSize(1); }
@Test public void loadLatestDiffChangesForReopeningOfClosedIssues_adds_2_diff_changes_if_most_recent_status_and_resolution_are_not_the_same_diff() { ComponentDto project = dbTester.components().insertPublicProject(); ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); RuleDefinitionDto rule = dbTester.rules().insert(); IssueDto issue = dbTester.issues().insert(rule, project, file); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus1")).setIssueChangeCreationDate(5)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus2", "resolution", "valRes2")).setIssueChangeCreationDate(19)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("status", "valStatus3")).setIssueChangeCreationDate(20)); dbTester.issues().insertChange(issue, t -> t.setChangeData(randomDiffWith("resolution", "valRes4")).setIssueChangeCreationDate(13)); ComponentIssuesLoader underTest = new ComponentIssuesLoader(dbClient, null /* not used in method */, null /* not used in method */, newConfiguration("0"), null /* not used by method */); DefaultIssue defaultIssue = new DefaultIssue().setKey(issue.getKey()); underTest.loadLatestDiffChangesForReopeningOfClosedIssues(ImmutableList.of(defaultIssue)); assertThat(defaultIssue.changes()) .hasSize(2); assertThat(defaultIssue.changes()) .extracting(t -> t.get("status")) .filteredOn(t -> hasValue(t, "valStatus3")) .hasSize(1); assertThat(defaultIssue.changes()) .extracting(t -> t.get("resolution")) .filteredOn(t -> hasValue(t, "valRes2")) .hasSize(1); }
new IssueChangeDto().setIssueKey(issue.getKey()) .setKey("COMMENT-ABCD") .setChangeData("*My comment*") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserUuid(john.getUuid()) new IssueChangeDto().setIssueKey(issue.getKey()) .setKey("COMMENT-ABCE") .setChangeData("Another comment") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserUuid(fabrice.getUuid())
new IssueChangeDto().setIssueKey(issue.getKey()) .setKey("COMMENT-ABCD") .setChangeData("*My comment*") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserUuid(john.getUuid()) new IssueChangeDto().setIssueKey(issue.getKey()) .setKey("COMMENT-ABCE") .setChangeData("Another comment") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserUuid(fabrice.getUuid())
public static IssueChangeDto of(String issueKey, FieldDiffs diffs) { IssueChangeDto dto = newDto(issueKey); dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE); dto.setChangeData(diffs.toString()); dto.setUserLogin(diffs.userLogin()); dto.setIssueChangeCreationDate(diffs.creationDate() == null ? null : diffs.creationDate().getTime()); return dto; }
public static IssueChangeDto of(DefaultIssueComment comment) { IssueChangeDto dto = newDto(comment.issueKey()); dto.setKey(comment.key()); dto.setChangeType(IssueChangeDto.TYPE_COMMENT); dto.setChangeData(comment.markdownText()); dto.setUserLogin(comment.userLogin()); dto.setIssueChangeCreationDate(comment.createdAt() == null ? null : comment.createdAt().getTime()); return dto; }
private Consumer<CommentData> updateComment(DbSession dbSession) { return commentData -> { commentData.getIssueChangeDto().setUpdatedAt(system2.now()); commentData.getIssueChangeDto().setChangeData(commentData.getRequest().getText()); dbClient.issueChangeDao().update(dbSession, commentData.getIssueChangeDto()); dbSession.commit(); }; }