Search in sources :

Example 11 with IssueComment

use of com.epam.pipeline.entity.issue.IssueComment in project cloud-pipeline by epam.

the class IssueCommentDaoTest method testCRUD.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testCRUD() {
    Issue issue = createIssue(ISSUE_NAME);
    IssueComment comment = getComment(issue, COMMENT_TEXT);
    // create
    commentDao.createComment(comment);
    Long commentId = comment.getId();
    // load
    Optional<IssueComment> loaded = commentDao.loadComment(commentId);
    assertTrue(loaded.isPresent());
    verifyComment(comment, loaded.get());
    IssueComment comment2 = getComment(issue, COMMENT_TEXT2);
    commentDao.createComment(comment2);
    assertEquals(2, commentDao.loadCommentsForIssue(issue.getId()).size());
    // Load by multiple issue IDs
    Map<Long, List<IssueComment>> commentMap = commentDao.loadCommentsForIssues(Collections.singleton(issue.getId()));
    assertEquals(1, commentMap.size());
    assertEquals(2, commentMap.get(issue.getId()).size());
    // update
    comment.setText(COMMENT_TEXT3);
    commentDao.updateComment(comment);
    Optional<IssueComment> updated = commentDao.loadComment(commentId);
    assertTrue(updated.isPresent());
    assertEquals(COMMENT_TEXT3, updated.get().getText());
    // delete
    commentDao.deleteComment(comment.getId());
    Optional<IssueComment> deleted = commentDao.loadComment(commentId);
    assertFalse(deleted.isPresent());
}
Also used : Issue(com.epam.pipeline.entity.issue.Issue) IssueComment(com.epam.pipeline.entity.issue.IssueComment) List(java.util.List) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with IssueComment

use of com.epam.pipeline.entity.issue.IssueComment in project cloud-pipeline by epam.

the class IssueCommentDaoTest method getComment.

public static IssueComment getComment(Issue issue, String commentText) {
    IssueComment comment = new IssueComment();
    comment.setIssueId(issue.getId());
    comment.setAuthor(COMMENT_AUTHOR);
    comment.setText(commentText);
    return comment;
}
Also used : IssueComment(com.epam.pipeline.entity.issue.IssueComment)

Example 13 with IssueComment

use of com.epam.pipeline.entity.issue.IssueComment in project cloud-pipeline by epam.

the class IssueManagerTest method testCreateComment.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testCreateComment() {
    Issue issue = registerIssue();
    Long issueId = issue.getId();
    IssueCommentVO commentVO = getCommentVO(COMMENT_TEXT);
    IssueComment comment = issueManager.createComment(issueId, commentVO);
    IssueComment loaded = issueManager.loadComment(issueId, comment.getId());
    compareComments(comment, loaded);
    ArgumentCaptor<IssueComment> captor = ArgumentCaptor.forClass(IssueComment.class);
    ArgumentCaptor<String> htmlTextCaptor = ArgumentCaptor.forClass(String.class);
    verify(notificationManager).notifyIssueComment(captor.capture(), any(), htmlTextCaptor.capture());
    assertEquals(COMMENT_TEXT, captor.getValue().getText());
    assertEquals(COMMENT_TEXT, htmlTextCaptor.getValue());
}
Also used : IssueCommentVO(com.epam.pipeline.controller.vo.IssueCommentVO) Issue(com.epam.pipeline.entity.issue.Issue) IssueComment(com.epam.pipeline.entity.issue.IssueComment) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with IssueComment

use of com.epam.pipeline.entity.issue.IssueComment in project cloud-pipeline by epam.

the class IssueManagerTest method updateCommentWithAttachments.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void updateCommentWithAttachments() throws InterruptedException {
    Attachment newAttachment = new Attachment();
    newAttachment.setPath("///");
    newAttachment.setName("newTestAttachment");
    newAttachment.setCreatedDate(new Date());
    newAttachment.setOwner(AUTHOR);
    attachmentDao.createAttachment(newAttachment);
    Issue issue = registerIssue();
    Long issueId = issue.getId();
    IssueCommentVO commentVO = getCommentVO(COMMENT_TEXT);
    IssueComment comment = issueManager.createComment(issueId, commentVO);
    IssueCommentVO updated = new IssueCommentVO();
    updated.setText(COMMENT_TEXT2);
    updated.setAttachments(Collections.singletonList(newAttachment));
    Long commentId = comment.getId();
    issueManager.updateComment(issueId, comment.getId(), updated);
    IssueComment loaded = issueManager.loadComment(issueId, commentId);
    assertEquals(1, loaded.getAttachments().size());
    assertTrue(loaded.getAttachments().stream().allMatch(a -> a.getName().equals(newAttachment.getName())));
    issueManager.deleteComment(issueId, commentId);
    assertFalse(attachmentDao.load(newAttachment.getId()).isPresent());
    Thread.sleep(TIMEOUT);
    verify(dataStorageManager, Mockito.times(2)).deleteDataStorageItems(Mockito.eq(testSystemDataStorage.getId()), Mockito.anyList(), Mockito.anyBoolean());
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) IssueVO(com.epam.pipeline.controller.vo.IssueVO) AttachmentDao(com.epam.pipeline.dao.issue.AttachmentDao) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Function(java.util.function.Function) Folder(com.epam.pipeline.entity.pipeline.Folder) ArgumentCaptor(org.mockito.ArgumentCaptor) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Map(java.util.Map) FolderDao(com.epam.pipeline.dao.pipeline.FolderDao) IssueComment(com.epam.pipeline.entity.issue.IssueComment) Before(org.junit.Before) MockBean(org.springframework.boot.test.mock.mockito.MockBean) IssueCommentVO(com.epam.pipeline.controller.vo.IssueCommentVO) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) SpyBean(org.springframework.boot.test.mock.mockito.SpyBean) FolderManager(com.epam.pipeline.manager.pipeline.FolderManager) Assert.assertTrue(org.junit.Assert.assertTrue) IssueStatus(com.epam.pipeline.entity.issue.IssueStatus) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Attachment(com.epam.pipeline.entity.issue.Attachment) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) IssueMapper(com.epam.pipeline.mapper.IssueMapper) Assert.assertFalse(org.junit.Assert.assertFalse) Preference(com.epam.pipeline.entity.preference.Preference) AclClass(com.epam.pipeline.entity.security.acl.AclClass) NotificationManager(com.epam.pipeline.manager.notification.NotificationManager) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) AuthManager(com.epam.pipeline.manager.security.AuthManager) Issue(com.epam.pipeline.entity.issue.Issue) Collections(java.util.Collections) DataStorageManager(com.epam.pipeline.manager.datastorage.DataStorageManager) Assert.assertEquals(org.junit.Assert.assertEquals) EntityVO(com.epam.pipeline.controller.vo.EntityVO) Transactional(org.springframework.transaction.annotation.Transactional) IssueCommentVO(com.epam.pipeline.controller.vo.IssueCommentVO) Issue(com.epam.pipeline.entity.issue.Issue) IssueComment(com.epam.pipeline.entity.issue.IssueComment) Attachment(com.epam.pipeline.entity.issue.Attachment) Date(java.util.Date) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with IssueComment

use of com.epam.pipeline.entity.issue.IssueComment in project cloud-pipeline by epam.

the class IssueManagerTest method testDeleteComment.

@Test(expected = IllegalArgumentException.class)
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testDeleteComment() {
    IssueComment comment = registerComment();
    Long issueId = comment.getIssueId();
    Long commentId = comment.getId();
    issueManager.deleteComment(issueId, commentId);
    issueManager.loadComment(issueId, commentId);
}
Also used : IssueComment(com.epam.pipeline.entity.issue.IssueComment) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IssueComment (com.epam.pipeline.entity.issue.IssueComment)20 Issue (com.epam.pipeline.entity.issue.Issue)14 Transactional (org.springframework.transaction.annotation.Transactional)12 Test (org.junit.Test)9 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)6 IssueCommentVO (com.epam.pipeline.controller.vo.IssueCommentVO)6 List (java.util.List)6 Attachment (com.epam.pipeline.entity.issue.Attachment)5 EntityVO (com.epam.pipeline.controller.vo.EntityVO)4 Map (java.util.Map)4 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)3 AclClass (com.epam.pipeline.entity.security.acl.AclClass)3 Collections (java.util.Collections)3 IssueVO (com.epam.pipeline.controller.vo.IssueVO)2 AttachmentDao (com.epam.pipeline.dao.issue.AttachmentDao)2 IssueDao (com.epam.pipeline.dao.issue.IssueDao)2 IssueStatus (com.epam.pipeline.entity.issue.IssueStatus)2 NotificationMessage (com.epam.pipeline.entity.notification.NotificationMessage)2 NotificationSettings (com.epam.pipeline.entity.notification.NotificationSettings)2 NotificationTemplate (com.epam.pipeline.entity.notification.NotificationTemplate)2