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);
}
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());
}
Aggregations