Search in sources :

Example 16 with IssueComment

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

the class IssueManagerTest method testUpdateComment.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testUpdateComment() {
    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);
    Long commentId = comment.getId();
    issueManager.updateComment(issueId, comment.getId(), updated);
    assertEquals(COMMENT_TEXT2, issueManager.loadComment(issueId, commentId).getText());
}
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 17 with IssueComment

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

the class IssueApiServiceTest method testIssueOwnerCRUD.

@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
@WithMockUser(username = USER_OWNER)
@Test
public void testIssueOwnerCRUD() {
    Issue issue = issueApiService.createIssue(getIssueVO(ISSUE_NAME, ISSUE_TEXT, entityVO));
    Issue loaded = issueApiService.loadIssue(issue.getId());
    Assert.assertNotNull(loaded);
    List<Issue> loadedIssues = issueApiService.loadIssuesForEntity(entityVO);
    Assert.assertNotNull(loadedIssues);
    issueApiService.updateIssue(issue.getId(), getIssueVO(ISSUE_NAME, ISSUE_TEXT + "!", entityVO));
    IssueCommentVO issueCommentVO = new IssueCommentVO();
    issueCommentVO.setText(COMMENT_TEXT);
    IssueComment comment = issueApiService.createComment(issue.getId(), issueCommentVO);
    IssueComment loadedComment = issueApiService.loadComment(issue.getId(), comment.getId());
    Assert.assertNotNull(loadedComment);
    issueCommentVO.setText(COMMENT_TEXT + "!");
    issueApiService.updateComment(issue.getId(), comment.getId(), issueCommentVO);
    issueApiService.deleteComment(issue.getId(), comment.getId());
    issueApiService.deleteIssue(issue.getId());
}
Also used : IssueCommentVO(com.epam.pipeline.controller.vo.IssueCommentVO) Issue(com.epam.pipeline.entity.issue.Issue) IssueComment(com.epam.pipeline.entity.issue.IssueComment) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with IssueComment

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

the class IssueApiServiceTest method testLoadCommentForNotOwner.

@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
@WithMockUser(username = CAN_READ_USER)
@Test
public void testLoadCommentForNotOwner() {
    IssueComment loadedComment = issueApiService.loadComment(createdIssue.getId(), createdIssueComment.getId());
    Assert.assertNotNull(loadedComment);
}
Also used : IssueComment(com.epam.pipeline.entity.issue.IssueComment) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with IssueComment

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

the class IssueApiServiceTest method setUp.

@Before
public void setUp() {
    Folder folder = new Folder();
    folder.setName(TEST_FOLDER_NAME);
    folder.setOwner(USER_OWNER);
    folderDao.createFolder(folder);
    // Mock ACL
    AclTestDao.AclSid testUserSid = new AclTestDao.AclSid(true, USER_OWNER);
    aclTestDao.createAclSid(testUserSid);
    AclTestDao.AclClass folderAclClass = new AclTestDao.AclClass(Folder.class.getCanonicalName());
    aclTestDao.createAclClassIfNotPresent(folderAclClass);
    AclTestDao.AclObjectIdentity objectIdentity = new AclTestDao.AclObjectIdentity(testUserSid, folder.getId(), folderAclClass.getId(), null, true);
    aclTestDao.createObjectIdentity(objectIdentity);
    AclTestDao.AclEntry aclEntry = new AclTestDao.AclEntry(objectIdentity, 1, testUserSid, AclPermission.READ.getMask(), true);
    aclTestDao.createAclEntry(aclEntry);
    AclTestDao.AclSid noPermissionUserSid = new AclTestDao.AclSid(true, NO_PERMISSION_USER);
    aclTestDao.createAclSid(noPermissionUserSid);
    entityVO = new EntityVO(folder.getId(), AclClass.FOLDER);
    createdIssue = new Issue();
    createdIssue.setName(ISSUE_NAME);
    createdIssue.setText(ISSUE_TEXT);
    createdIssue.setAuthor(USER_OWNER);
    createdIssue.setEntity(entityVO);
    createdIssue.setStatus(IssueStatus.OPEN);
    issueDao.createIssue(createdIssue);
    createdIssueComment = new IssueComment();
    createdIssueComment.setIssueId(createdIssue.getId());
    createdIssueComment.setAuthor(USER_OWNER);
    createdIssueComment.setText(COMMENT_TEXT);
    issueCommentDao.createComment(createdIssueComment);
    AclTestDao.AclSid canReadUserSid = new AclTestDao.AclSid(true, CAN_READ_USER);
    aclTestDao.createAclSid(canReadUserSid);
    aclEntry = new AclTestDao.AclEntry(objectIdentity, 2, canReadUserSid, AclPermission.READ.getMask(), true);
    aclTestDao.createAclEntry(aclEntry);
    verify(notificationManager, Mockito.never()).notifyIssue(any(), any(), any());
    Mockito.doNothing().when(attachmentFileManager).deleteAttachments(Mockito.anyListOf(Attachment.class));
    attachment = new Attachment();
    attachment.setName("testAttachment");
    attachment.setCreatedDate(new Date());
    attachment.setPath("///");
    attachment.setOwner(TEST_USER);
    attachmentDao.createAttachment(attachment);
    Mockito.doNothing().when(attachmentFileManager).deleteAttachments(Mockito.anyListOf(Attachment.class));
}
Also used : Issue(com.epam.pipeline.entity.issue.Issue) Attachment(com.epam.pipeline.entity.issue.Attachment) Folder(com.epam.pipeline.entity.pipeline.Folder) AclClass(com.epam.pipeline.entity.security.acl.AclClass) Date(java.util.Date) EntityVO(com.epam.pipeline.controller.vo.EntityVO) IssueComment(com.epam.pipeline.entity.issue.IssueComment) AclTestDao(com.epam.pipeline.dao.util.AclTestDao) Before(org.junit.Before)

Example 20 with IssueComment

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

the class IssueMapperTest method shouldMapIssue.

@Test
void shouldMapIssue() throws IOException {
    IssueMapper mapper = new IssueMapper();
    Attachment attachment = new Attachment();
    attachment.setPath(TEST_PATH);
    attachment.setOwner(USER_NAME);
    IssueComment comment = IssueComment.builder().author(USER_NAME).text(TEST_DESCRIPTION).build();
    EntityVO entity = new EntityVO(1L, AclClass.TOOL);
    Issue issue = Issue.builder().id(1L).name(TEST_NAME).text(TEST_DESCRIPTION).status(IssueStatus.OPEN).labels(Collections.singletonList(TEST_LABEL)).attachments(Collections.singletonList(attachment)).comments(Collections.singletonList(comment)).entity(entity).build();
    EntityContainer<Issue> container = EntityContainer.<Issue>builder().entity(issue).owner(USER).permissions(PERMISSIONS_CONTAINER).build();
    XContentBuilder contentBuilder = mapper.map(container);
    verifyIssue(issue, contentBuilder);
    verifyAttachments(Collections.singletonList(attachment.getPath()), contentBuilder);
    verifyComments(Collections.singletonList(comment.getAuthor() + " : " + comment.getText()), contentBuilder);
    verifyPipelineUser(USER, contentBuilder);
    verifyPermissions(PERMISSIONS_CONTAINER, contentBuilder);
}
Also used : EntityVO(com.epam.pipeline.vo.EntityVO) MapperVerificationUtils.verifyIssue(com.epam.pipeline.elasticsearchagent.MapperVerificationUtils.verifyIssue) Issue(com.epam.pipeline.entity.issue.Issue) IssueComment(com.epam.pipeline.entity.issue.IssueComment) Attachment(com.epam.pipeline.entity.issue.Attachment) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.jupiter.api.Test)

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