Search in sources :

Example 1 with DataStorageManager

use of com.epam.pipeline.manager.datastorage.DataStorageManager in project cloud-pipeline by epam.

the class AttachmentFileManagerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    attachmentFileManager = new AttachmentFileManager(dataStorageManager, preferenceManager, attachmentManager, messageHelper, authManager);
    Preference systemDataStorage = SystemPreferences.DATA_STORAGE_SYSTEM_DATA_STORAGE_NAME.toPreference();
    systemDataStorage.setName(TEST_SYSTEM_DATA_STORAGE);
    when(preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_SYSTEM_DATA_STORAGE_NAME)).thenReturn(TEST_SYSTEM_DATA_STORAGE);
    when(dataStorageManager.loadByNameOrId(TEST_SYSTEM_DATA_STORAGE)).thenReturn(testSystemDataStorage);
    when(dataStorageManager.createDataStorageFile(Mockito.eq(1L), Mockito.anyString(), Mockito.anyString(), Mockito.any(InputStream.class))).then((Answer<DataStorageFile>) invocation -> {
        String path = invocation.getArgumentAt(1, String.class);
        String name = invocation.getArgumentAt(2, String.class);
        DataStorageFile file = new DataStorageFile();
        file.setPath(path + "/" + name);
        return file;
    });
    when(attachmentManager.load(Mockito.anyLong())).thenAnswer(invocation -> {
        Attachment attachment = new Attachment();
        attachment.setId(invocation.getArgumentAt(0, Long.class));
        attachment.setName(TEST_ATTACHMENT_NAME);
        attachment.setPath(TEST_ATTACHMENT_PATH);
        return attachment;
    });
    DataStorageStreamingContent content = new DataStorageStreamingContent(new ByteArrayInputStream(new byte[] { 1 }), TEST_ATTACHMENT_NAME);
    when(dataStorageManager.getStreamingContent(testSystemDataStorage.getId(), TEST_ATTACHMENT_PATH, null)).thenReturn(content);
    when(authManager.getAuthorizedUser()).thenReturn(TEST_USER);
}
Also used : PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Mock(org.mockito.Mock) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Attachment(com.epam.pipeline.entity.issue.Attachment) Mockito.verify(org.mockito.Mockito.verify) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) Mockito(org.mockito.Mockito) MockitoAnnotations(org.mockito.MockitoAnnotations) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageHelper(com.epam.pipeline.common.MessageHelper) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) Matchers.eq(org.mockito.Matchers.eq) Preference(com.epam.pipeline.entity.preference.Preference) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) AuthManager(com.epam.pipeline.manager.security.AuthManager) Assert(org.junit.Assert) DataStorageManager(com.epam.pipeline.manager.datastorage.DataStorageManager) InputStream(java.io.InputStream) Before(org.junit.Before) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) Preference(com.epam.pipeline.entity.preference.Preference) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Attachment(com.epam.pipeline.entity.issue.Attachment) Before(org.junit.Before)

Example 2 with DataStorageManager

use of com.epam.pipeline.manager.datastorage.DataStorageManager 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)

Aggregations

S3bucketDataStorage (com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)2 Attachment (com.epam.pipeline.entity.issue.Attachment)2 Preference (com.epam.pipeline.entity.preference.Preference)2 DataStorageManager (com.epam.pipeline.manager.datastorage.DataStorageManager)2 PreferenceManager (com.epam.pipeline.manager.preference.PreferenceManager)2 SystemPreferences (com.epam.pipeline.manager.preference.SystemPreferences)2 AuthManager (com.epam.pipeline.manager.security.AuthManager)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 Mockito (org.mockito.Mockito)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)1 MessageHelper (com.epam.pipeline.common.MessageHelper)1 EntityVO (com.epam.pipeline.controller.vo.EntityVO)1 IssueCommentVO (com.epam.pipeline.controller.vo.IssueCommentVO)1 IssueVO (com.epam.pipeline.controller.vo.IssueVO)1 AttachmentDao (com.epam.pipeline.dao.issue.AttachmentDao)1 FolderDao (com.epam.pipeline.dao.pipeline.FolderDao)1