Search in sources :

Example 16 with Attachment

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

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

Attachment (com.epam.pipeline.entity.issue.Attachment)17 Transactional (org.springframework.transaction.annotation.Transactional)9 Issue (com.epam.pipeline.entity.issue.Issue)7 IssueComment (com.epam.pipeline.entity.issue.IssueComment)7 Date (java.util.Date)7 Test (org.junit.Test)7 EntityVO (com.epam.pipeline.controller.vo.EntityVO)6 AuthManager (com.epam.pipeline.manager.security.AuthManager)6 List (java.util.List)6 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)5 AclClass (com.epam.pipeline.entity.security.acl.AclClass)5 Collections (java.util.Collections)5 Collectors (java.util.stream.Collectors)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Propagation (org.springframework.transaction.annotation.Propagation)5 IssueCommentVO (com.epam.pipeline.controller.vo.IssueCommentVO)4 IssueVO (com.epam.pipeline.controller.vo.IssueVO)4 AttachmentDao (com.epam.pipeline.dao.issue.AttachmentDao)4 IssueStatus (com.epam.pipeline.entity.issue.IssueStatus)4 Folder (com.epam.pipeline.entity.pipeline.Folder)4