Search in sources :

Example 1 with MessageHelper

use of com.epam.pipeline.common.MessageHelper 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)

Aggregations

MessageHelper (com.epam.pipeline.common.MessageHelper)1 DataStorageFile (com.epam.pipeline.entity.datastorage.DataStorageFile)1 DataStorageStreamingContent (com.epam.pipeline.entity.datastorage.DataStorageStreamingContent)1 S3bucketDataStorage (com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)1 Attachment (com.epam.pipeline.entity.issue.Attachment)1 Preference (com.epam.pipeline.entity.preference.Preference)1 DataStorageManager (com.epam.pipeline.manager.datastorage.DataStorageManager)1 PreferenceManager (com.epam.pipeline.manager.preference.PreferenceManager)1 SystemPreferences (com.epam.pipeline.manager.preference.SystemPreferences)1 AuthManager (com.epam.pipeline.manager.security.AuthManager)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 Matchers.eq (org.mockito.Matchers.eq)1 Mock (org.mockito.Mock)1 Mockito (org.mockito.Mockito)1 Mockito.verify (org.mockito.Mockito.verify)1