Search in sources :

Example 31 with Issue

use of com.epam.pipeline.entity.issue.Issue 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 32 with Issue

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

the class IssueManagerTest method testLoadAndDeleteIssuesForEntity.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testLoadAndDeleteIssuesForEntity() {
    when(authManager.getAuthorizedUser()).thenReturn(AUTHOR);
    IssueVO issueVO = getIssueVO(ISSUE_NAME, ISSUE_TEXT, entityVO);
    issueVO.setAttachments(Collections.singletonList(testAttachment));
    Issue issue = issueManager.createIssue(issueVO);
    Issue issue2 = issueManager.createIssue(getIssueVO(ISSUE_NAME2, ISSUE_TEXT, entityVO));
    // load
    List<Issue> actualIssues = issueManager.loadIssuesForEntity(entityVO);
    assertEquals(2, actualIssues.size());
    List<Issue> expectedIssues = Stream.of(issue, issue2).collect(Collectors.toList());
    Map<Long, Issue> expectedMap = expectedIssues.stream().collect(Collectors.toMap(Issue::getId, Function.identity()));
    actualIssues.forEach(i -> compareIssues(expectedMap.get(i.getId()), i));
    // delete
    issueManager.deleteIssuesForEntity(entityVO);
    actualIssues = issueManager.loadIssuesForEntity(entityVO);
    assertEquals(0, actualIssues.size());
}
Also used : Issue(com.epam.pipeline.entity.issue.Issue) IssueVO(com.epam.pipeline.controller.vo.IssueVO) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with Issue

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

the class IssueManagerTest method testDeleteIssuesWhenEntityWasDeleted.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testDeleteIssuesWhenEntityWasDeleted() {
    when(authManager.getAuthorizedUser()).thenReturn(AUTHOR);
    Folder folder = new Folder();
    folder.setName(FOLDER_NAME_2);
    folder.setOwner(AUTHOR);
    folderDao.createFolder(folder);
    EntityVO entityVO = new EntityVO(folder.getId(), AclClass.FOLDER);
    IssueVO issueVO = getIssueVO(ISSUE_NAME, ISSUE_TEXT, entityVO);
    issueManager.createIssue(issueVO);
    folderManager.delete(folder.getId());
    List<Issue> issues = issueManager.loadIssuesForEntity(entityVO);
    assertTrue(CollectionUtils.isEmpty(issues));
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) Issue(com.epam.pipeline.entity.issue.Issue) Folder(com.epam.pipeline.entity.pipeline.Folder) IssueVO(com.epam.pipeline.controller.vo.IssueVO) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with Issue

use of com.epam.pipeline.entity.issue.Issue 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 35 with Issue

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

the class IssueManagerTest method creatingCommentWithEmptyTextShouldThrowException.

@Test(expected = IllegalArgumentException.class)
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void creatingCommentWithEmptyTextShouldThrowException() {
    Issue issue = registerIssue();
    Long issueId = issue.getId();
    IssueCommentVO commentVO = getCommentVO("");
    issueManager.createComment(issueId, commentVO);
}
Also used : IssueCommentVO(com.epam.pipeline.controller.vo.IssueCommentVO) Issue(com.epam.pipeline.entity.issue.Issue) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Issue (com.epam.pipeline.entity.issue.Issue)44 Transactional (org.springframework.transaction.annotation.Transactional)30 Test (org.junit.Test)25 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)21 IssueComment (com.epam.pipeline.entity.issue.IssueComment)17 EntityVO (com.epam.pipeline.controller.vo.EntityVO)16 IssueCommentVO (com.epam.pipeline.controller.vo.IssueCommentVO)13 IssueVO (com.epam.pipeline.controller.vo.IssueVO)11 List (java.util.List)9 Attachment (com.epam.pipeline.entity.issue.Attachment)7 Map (java.util.Map)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 Propagation (org.springframework.transaction.annotation.Propagation)7 AclClass (com.epam.pipeline.entity.security.acl.AclClass)6 Collections (java.util.Collections)6 IssueStatus (com.epam.pipeline.entity.issue.IssueStatus)5 Collectors (java.util.stream.Collectors)5 AttachmentDao (com.epam.pipeline.dao.issue.AttachmentDao)4 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)4 Folder (com.epam.pipeline.entity.pipeline.Folder)4