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 public void create_from_comment() { DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "user_uuid", "the comment"); IssueChangeDto dto = IssueChangeDto.of(comment); assertThat(dto.getChangeData()).isEqualTo("the comment"); assertThat(dto.getChangeType()).isEqualTo("comment"); assertThat(dto.getCreatedAt()).isNotNull(); assertThat(dto.getUpdatedAt()).isNotNull(); assertThat(dto.getIssueChangeCreationDate()).isNotNull(); assertThat(dto.getIssueKey()).isEqualTo("ABCDE"); assertThat(dto.getUserUuid()).isEqualTo("user_uuid"); }
private static IssueChangeDto newDto(String issueKey) { IssueChangeDto dto = new IssueChangeDto(); dto.setIssueKey(issueKey); // technical dates - do not use the context date dto.setCreatedAt(System2.INSTANCE.now()); dto.setUpdatedAt(System2.INSTANCE.now()); return dto; }
private static void addChangeOrComment(DefaultIssue i, IssueChangeDto c) { switch (c.getChangeType()) { case IssueChangeDto.TYPE_FIELD_CHANGE: i.addChange(c.toFieldDiffs()); break; case IssueChangeDto.TYPE_COMMENT: i.addComment(c.toComment()); break; default: throw new IllegalStateException("Unknow change type: " + c.getChangeType()); } }
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; }
@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"); }
@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 select_comment_by_key() { IssueDto issue = db.issues().insertIssue(); IssueChangeDto issueChange = db.issues().insertChange(issue, c -> c.setChangeType(TYPE_COMMENT)); db.issues().insertChange(issue, c -> c.setChangeType(TYPE_COMMENT)); Optional<IssueChangeDto> issueChangeDto = underTest.selectCommentByKey(db.getSession(), issueChange.getKey()); assertThat(issueChangeDto).isPresent(); assertThat(issueChangeDto.get().getKey()).isEqualTo(issueChange.getKey()); assertThat(issueChangeDto.get().getChangeType()).isEqualTo(TYPE_COMMENT); assertThat(issueChangeDto.get().getUserUuid()).isEqualTo(issueChange.getUserUuid()); assertThat(issueChangeDto.get().getChangeData()).isEqualTo(issueChange.getChangeData()); assertThat(issueChangeDto.get().getIssueChangeCreationDate()).isNotNull(); assertThat(issueChangeDto.get().getCreatedAt()).isNotNull(); assertThat(issueChangeDto.get().getUpdatedAt()).isNotNull(); }
@Test public void add_comment() { IssueDto issueDto = issueDbTester.insertIssue(); loginWithBrowsePermission(issueDto, USER); call(issueDto.getKey(), "please fix it"); verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); verifyContentOfPreloadedSearchResponseData(issueDto); IssueChangeDto issueComment = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbTester.getSession(), singletonList(issueDto.getKey()), TYPE_COMMENT).get(0); assertThat(issueComment.getKey()).isNotNull(); assertThat(issueComment.getUserUuid()).isEqualTo(userSession.getUuid()); assertThat(issueComment.getChangeType()).isEqualTo(TYPE_COMMENT); assertThat(issueComment.getChangeData()).isEqualTo("please fix it"); assertThat(issueComment.getCreatedAt()).isNotNull(); assertThat(issueComment.getUpdatedAt()).isNotNull(); assertThat(issueComment.getIssueKey()).isEqualTo(issueDto.getKey()); assertThat(issueComment.getIssueChangeCreationDate()).isNotNull(); IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issueDto.getKey()).get(); assertThat(issueReloaded.getIssueUpdateTime()).isEqualTo(NOW); assertThat(issueChangePostProcessor.wasCalled()).isFalse(); }
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); dbClient.issueChangeDao().insert(session, new IssueChangeDto().setIssueKey(issue.getKey()) .setKey("COMMENT-ABCD") .setChangeData("*My comment*") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserUuid(john.getUuid()) .setIssueChangeCreationDate(parseDateTime("2014-09-09T12:00:00+0000").getTime())); dbClient.issueChangeDao().insert(session, new IssueChangeDto().setIssueKey(issue.getKey()) .setKey("COMMENT-ABCE") .setChangeData("Another comment") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserUuid(fabrice.getUuid()) .setIssueChangeCreationDate(parseDateTime("2014-09-10T12:00:00+0000").getTime())); session.commit(); indexIssues();
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; }
IssueDto issue = db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); dbClient.issueChangeDao().insert(session, new IssueChangeDto().setIssueKey(issue.getKey()) .setKey("COMMENT-ABCD") .setChangeData("*My comment*") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserUuid(john.getUuid()) .setCreatedAt(parseDateTime("2014-09-09T12:00:00+0000").getTime())); dbClient.issueChangeDao().insert(session, new IssueChangeDto().setIssueKey(issue.getKey()) .setKey("COMMENT-ABCE") .setChangeData("Another comment") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserUuid(fabrice.getUuid()) .setCreatedAt(parseDateTime("2014-09-10T19:10:03+0000").getTime())); session.commit(); indexIssues();
private static void formatIssueComments(SearchResponseData data, Issue.Builder wsIssue, IssueDto dto) { Comments.Builder wsComments = Comments.newBuilder(); List<IssueChangeDto> comments = data.getCommentsForIssueKey(dto.getKey()); if (comments != null) { Comment.Builder wsComment = Comment.newBuilder(); for (IssueChangeDto comment : comments) { String markdown = comment.getChangeData(); wsComment .clear() .setKey(comment.getKey()) .setUpdatable(data.isUpdatableComment(comment.getKey())) .setCreatedAt(DateUtils.formatDateTime(new Date(comment.getIssueChangeCreationDate()))); ofNullable(data.getUserByUuid(comment.getUserUuid())).ifPresent(user -> wsComment.setLogin(user.getLogin())); if (markdown != null) { wsComment .setHtmlText(Markdown.convertToHtml(markdown)) .setMarkdown(markdown); } wsComments.addComments(wsComment); } } wsIssue.setComments(wsComments); }
@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 scrollDiffChangesOfIssues_orders_changes_by_issue_and_then_creationDate() { IssueDto issue1 = db.issues().insertIssue(); IssueChangeDto[] diffChanges = { db.issues().insertChange(issue1, t -> t.setChangeType(TYPE_FIELD_CHANGE).setCreatedAt(1L).setIssueChangeCreationDate(50L)), db.issues().insertChange(issue1, t -> t.setChangeType(TYPE_FIELD_CHANGE).setCreatedAt(2L).setIssueChangeCreationDate(20L)), db.issues().insertChange(issue1, t -> t.setChangeType(TYPE_FIELD_CHANGE).setCreatedAt(3L).setIssueChangeCreationDate(30L)), db.issues().insertChange(issue1, t -> t.setChangeType(TYPE_FIELD_CHANGE).setCreatedAt(4L).setIssueChangeCreationDate(80L)), db.issues().insertChange(issue1, t -> t.setChangeType(TYPE_FIELD_CHANGE).setCreatedAt(5L).setIssueChangeCreationDate(10L)), }; RecordingIssueChangeDtoResultHandler recordingHandler = new RecordingIssueChangeDtoResultHandler(); underTest.scrollDiffChangesOfIssues(db.getSession(), of(issue1.getKee()), recordingHandler.clear()); assertThat(recordingHandler.getDtoKeys()).containsExactly( diffChanges[3].getKey(), diffChanges[0].getKey(), diffChanges[2].getKey(), diffChanges[1].getKey(), diffChanges[4].getKey()); }
CommentData(DbSession dbSession, String commentKey) { this.issueChangeDto = dbClient.issueChangeDao().selectCommentByKey(dbSession, commentKey) .orElseThrow(() -> new NotFoundException(format("Comment with key '%s' does not exist", commentKey))); // Load issue now to quickly fail if user hasn't permission to see it this.issueDto = issueFinder.getByKey(dbSession, issueChangeDto.getIssueKey()); checkArgument(Objects.equals(issueChangeDto.getUserUuid(), userSession.getUuid()), "You can only delete your own comments"); }
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 edit_comment() { IssueDto issueDto = issueDbTester.insertIssue(); UserDto user = dbTester.users().insertUser(); IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it"); loginWithBrowsePermission(user, USER, issueDto); call(commentDto.getKey(), "please have a look"); verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); verifyContentOfPreloadedSearchResponseData(issueDto); IssueChangeDto issueComment = dbClient.issueChangeDao().selectCommentByKey(dbTester.getSession(), commentDto.getKey()).get(); assertThat(issueComment.getChangeData()).isEqualTo("please have a look"); assertThat(issueComment.getUpdatedAt()).isEqualTo(NOW); }