Package org.sonar.api.issue.internal

Examples of org.sonar.api.issue.internal.DefaultIssueComment


    List<DefaultIssueComment> comments = dao.selectCommentsByIssues(session, Arrays.asList("1000"));
    MyBatis.closeQuietly(session);
    assertThat(comments).hasSize(2);

    // chronological order
    DefaultIssueComment first = comments.get(0);
    assertThat(first.markdownText()).isEqualTo("old comment");


    DefaultIssueComment second = comments.get(1);
    assertThat(second.userLogin()).isEqualTo("arthur");
    assertThat(second.key()).isEqualTo("FGHIJ");
    assertThat(second.markdownText()).isEqualTo("recent comment");
  }
View Full Code Here


  @Test
  public void select_comment_by_key() {
    setupData("shared");

    DefaultIssueComment comment = dao.selectCommentByKey("FGHIJ");
    assertThat(comment).isNotNull();
    assertThat(comment.key()).isEqualTo("FGHIJ");
    assertThat(comment.key()).isEqualTo("FGHIJ");
    assertThat(comment.userLogin()).isEqualTo("arthur");

    assertThat(dao.selectCommentByKey("UNKNOWN")).isNull();
  }
View Full Code Here

    DefaultIssue issue = createStandardIssue();
    when(issueService.getByKey(issue.key())).thenReturn(issue);

    when(commentService.findComments(issue.key())).thenReturn(newArrayList(
      new DefaultIssueComment()
        .setKey("COMMENT-ABCD")
        .setMarkdownText("*My comment*")
        .setUserLogin("john")
        .setCreatedAt(date1),
      new DefaultIssueComment()
        .setKey("COMMENT-ABCE")
        .setMarkdownText("Another comment")
        .setUserLogin("arthur")
        .setCreatedAt(date2)
      ));
View Full Code Here

      session.close();
    }
  }

  public IssueComment deleteComment(String commentKey, UserSession userSession) {
    DefaultIssueComment comment = changeDao.selectCommentByKey(commentKey);
    if (comment == null) {
      throw new NotFoundException("Comment not found: " + commentKey);
    }
    if (Strings.isNullOrEmpty(comment.userLogin()) || !Objects.equal(comment.userLogin(), userSession.login())) {
      throw new ForbiddenException("You can only delete your own comments");
    }

    // check authorization
    issueService.getByKey(comment.issueKey());

    changeDao.delete(commentKey);
    return comment;
  }
View Full Code Here

    changeDao.delete(commentKey);
    return comment;
  }

  public IssueComment editComment(String commentKey, String text, UserSession userSession) {
    DefaultIssueComment comment = changeDao.selectCommentByKey(commentKey);
    if (StringUtils.isBlank(text)) {
      throw new BadRequestException("Cannot add empty comments to an issue");
    }
    if (comment == null) {
      throw new NotFoundException("Comment not found: " + commentKey);
    }
    if (Strings.isNullOrEmpty(comment.userLogin()) || !Objects.equal(comment.userLogin(), userSession.login())) {
      throw new ForbiddenException("You can only edit your own comments");
    }

    // check authorization
    issueService.getByKey(comment.issueKey());

    IssueChangeDto dto = IssueChangeDto.of(comment);
    dto.setUpdatedAt(new Date());
    dto.setChangeData(text);
    changeDao.update(dto);
View Full Code Here

  @Test
  public void should_add_comment() throws Exception {
    IssueDto issueDto = IssueTesting.newDto(RuleTesting.newXooX1().setId(500), ComponentTesting.newFileDto(ComponentTesting.newProjectDto()), ComponentTesting.newProjectDto());
    when(issueService.getByKeyForUpdate(session, "ABCD")).thenReturn(issueDto);
    when(issueCommentService.findComments(session, "ABCD")).thenReturn(newArrayList(new DefaultIssueComment()));

    issueCommentService.addComment("ABCD", "my comment", MockUserSession.get());

    verify(updater).addComment(eq(issueDto.toDefaultIssue()), eq("my comment"), any(IssueChangeContext.class));
    verify(issueService).saveIssue(eq(session), eq(issueDto.toDefaultIssue()), any(IssueChangeContext.class), eq("my comment"));
View Full Code Here

    }
  }

  @Test
  public void should_delete_comment() throws Exception {
    when(changeDao.selectCommentByKey("ABCD")).thenReturn(new DefaultIssueComment().setUserLogin("admin").setIssueKey("EFGH"));

    issueCommentService.deleteComment("ABCD", MockUserSession.get());

    verify(changeDao).delete("ABCD");
    verify(issueService).getByKey("EFGH");
View Full Code Here

  @Test
  public void should_prevent_delete_others_comment() throws Exception {
    throwable.expect(ForbiddenException.class);

    when(changeDao.selectCommentByKey("ABCD")).thenReturn(new DefaultIssueComment().setUserLogin("julien"));

    issueCommentService.deleteComment("ABCD", MockUserSession.get());

    verify(changeDao, never()).delete(anyString());
  }
View Full Code Here

    verify(changeDao, never()).delete(anyString());
  }

  @Test
  public void should_update_comment() throws Exception {
    when(changeDao.selectCommentByKey("ABCD")).thenReturn(new DefaultIssueComment().setIssueKey("EFGH").setUserLogin("admin"));

    issueCommentService.editComment("ABCD", "updated comment", MockUserSession.get());

    verify(changeDao).update(any(IssueChangeDto.class));
    verify(issueService).getByKey("EFGH");
View Full Code Here

  @Test
  public void should_prevent_updating_others_comment() throws Exception {
    throwable.expect(ForbiddenException.class);

    when(changeDao.selectCommentByKey("ABCD")).thenReturn(new DefaultIssueComment().setUserLogin("julien"));

    issueCommentService.editComment("ABCD", "updated comment", MockUserSession.get());

    verify(changeDao, never()).update(any(IssueChangeDto.class));
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.issue.internal.DefaultIssueComment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.