diff --git a/extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/photos/BackblazePhotosImporter.java b/extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/photos/BackblazePhotosImporter.java index 4a141abc6..38f8de402 100644 --- a/extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/photos/BackblazePhotosImporter.java +++ b/extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/photos/BackblazePhotosImporter.java @@ -22,6 +22,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.UUID; +import java.util.concurrent.atomic.LongAdder; + import org.datatransferproject.api.launcher.Monitor; import org.datatransferproject.datatransfer.backblaze.common.BackblazeDataTransferClient; import org.datatransferproject.datatransfer.backblaze.common.BackblazeDataTransferClientFactory; @@ -80,14 +82,23 @@ public ImportResult importItem( } } + final LongAdder totalImportedFilesSizes = new LongAdder(); if (data.getPhotos() != null && data.getPhotos().size() > 0) { for (PhotoModel photo : data.getPhotos()) { idempotentExecutor.importAndSwallowIOExceptions( - photo, p -> importSinglePhoto(idempotentExecutor, b2Client, jobId, p)); + photo, + p -> { + ItemImportResult fileImportResult = + importSinglePhoto(idempotentExecutor, b2Client, jobId, p); + if (fileImportResult.hasBytes()) { + totalImportedFilesSizes.add(fileImportResult.getBytes()); + } + return fileImportResult; + }); } } - return ImportResult.OK; + return ImportResult.OK.copyWithBytes(totalImportedFilesSizes.longValue()); } private ItemImportResult importSinglePhoto( @@ -115,8 +126,11 @@ private ItemImportResult importSinglePhoto( } catch (Exception e) { // Swallow the exception caused by Remove data so that existing flows continue monitor.info( - () -> format("Exception swallowed while removing data for jobId %s, localPath %s", - jobId, photo.getFetchableUrl()), e); + () -> + format( + "Exception swallowed while removing data for jobId %s, localPath %s", + jobId, photo.getFetchableUrl()), + e); } return ItemImportResult.success(response, size); diff --git a/extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/videos/BackblazeVideosImporter.java b/extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/videos/BackblazeVideosImporter.java index 1a08bcdba..3c196ed8d 100644 --- a/extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/videos/BackblazeVideosImporter.java +++ b/extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/videos/BackblazeVideosImporter.java @@ -21,6 +21,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.UUID; +import java.util.concurrent.atomic.LongAdder; + import org.datatransferproject.api.launcher.Monitor; import org.datatransferproject.datatransfer.backblaze.common.BackblazeDataTransferClient; import org.datatransferproject.datatransfer.backblaze.common.BackblazeDataTransferClientFactory; @@ -69,29 +71,32 @@ public ImportResult importItem( BackblazeDataTransferClient b2Client = b2ClientFactory.getOrCreateB2Client(jobId, authData); + final LongAdder totalImportedFilesSizes = new LongAdder(); if (data.getVideos() != null && data.getVideos().size() > 0) { for (VideoModel video : data.getVideos()) { idempotentExecutor.importAndSwallowIOExceptions( video, - v -> importSingleVideo(jobId, b2Client, v)); + v -> { + ItemImportResult fileImportResult = importSingleVideo(jobId, b2Client, v); + if (fileImportResult.hasBytes()) { + totalImportedFilesSizes.add(fileImportResult.getBytes()); + } + return fileImportResult; + }); } } - return ImportResult.OK; + return ImportResult.OK.copyWithBytes(totalImportedFilesSizes.longValue()); } private ItemImportResult importSingleVideo( - UUID jobId, - BackblazeDataTransferClient b2Client, - VideoModel video) - throws IOException { + UUID jobId, BackblazeDataTransferClient b2Client, VideoModel video) throws IOException { try (InputStream videoFileStream = connectionProvider.getInputStreamForItem(jobId, video).getStream()) { - File file = jobStore - .getTempFileFromInputStream(videoFileStream, video.getDataId(), ".mp4"); - String res = b2Client.uploadFile( - String.format("%s/%s.mp4", VIDEO_TRANSFER_MAIN_FOLDER, video.getDataId()), - file); + File file = jobStore.getTempFileFromInputStream(videoFileStream, video.getDataId(), ".mp4"); + String res = + b2Client.uploadFile( + String.format("%s/%s.mp4", VIDEO_TRANSFER_MAIN_FOLDER, video.getDataId()), file); return ItemImportResult.success(res, file.length()); } catch (FileNotFoundException e) { monitor.info( diff --git a/extensions/data-transfer/portability-data-transfer-backblaze/src/test/java/org/datatransferproject/datatransfer/backblaze/photos/BackblazePhotosImporterTest.java b/extensions/data-transfer/portability-data-transfer-backblaze/src/test/java/org/datatransferproject/datatransfer/backblaze/photos/BackblazePhotosImporterTest.java index 733abf523..5c04bb9b0 100644 --- a/extensions/data-transfer/portability-data-transfer-backblaze/src/test/java/org/datatransferproject/datatransfer/backblaze/photos/BackblazePhotosImporterTest.java +++ b/extensions/data-transfer/portability-data-transfer-backblaze/src/test/java/org/datatransferproject/datatransfer/backblaze/photos/BackblazePhotosImporterTest.java @@ -49,13 +49,13 @@ import org.mockito.ArgumentCaptor; public class BackblazePhotosImporterTest { - Monitor monitor; - TemporaryPerJobDataStore dataStore; - ConnectionProvider streamProvider; - BackblazeDataTransferClientFactory clientFactory; - IdempotentImportExecutor executor; - TokenSecretAuthData authData; - BackblazeDataTransferClient client; + Monitor monitor; + TemporaryPerJobDataStore dataStore; + ConnectionProvider streamProvider; + BackblazeDataTransferClientFactory clientFactory; + IdempotentImportExecutor executor; + TokenSecretAuthData authData; + BackblazeDataTransferClient client; @BeforeEach public void setUp() { @@ -68,8 +68,7 @@ public void setUp() { client = mock(BackblazeDataTransferClient.class); } - @TempDir - public Path folder; + @TempDir public Path folder; @Test public void testNullData() throws Exception { @@ -88,7 +87,7 @@ public void testNullPhotosAndAlbums() throws Exception { BackblazePhotosImporter sut = new BackblazePhotosImporter(monitor, dataStore, streamProvider, clientFactory); ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, data); - assertEquals(ImportResult.OK, result); + assertEquals(ImportResult.ResultType.OK, result.getType()); } @Test @@ -100,7 +99,7 @@ public void testEmptyPhotosAndAlbums() throws Exception { BackblazePhotosImporter sut = new BackblazePhotosImporter(monitor, dataStore, streamProvider, clientFactory); ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, data); - assertEquals(ImportResult.OK, result); + assertEquals(ImportResult.ResultType.OK, result.getType()); } @Test @@ -113,8 +112,8 @@ public void testImportPhoto() throws Exception { String response = "response"; UUID jobId = UUID.randomUUID(); PhotoModel photoModel = new PhotoModel(title, photoUrl, "", "", dataId, albumId, false); - PhotosContainerResource data = new PhotosContainerResource(Collections.emptyList(), - Collections.singletonList(photoModel)); + PhotosContainerResource data = + new PhotosContainerResource(Collections.emptyList(), Collections.singletonList(photoModel)); when(executor.getCachedValue(albumId)).thenReturn(albumName); @@ -131,8 +130,8 @@ public void testImportPhoto() throws Exception { new BackblazePhotosImporter(monitor, dataStore, streamProvider, clientFactory); sut.importItem(jobId, executor, authData, data); - ArgumentCaptor> importCapture = ArgumentCaptor.forClass( - ImportFunction.class); + ArgumentCaptor> importCapture = + ArgumentCaptor.forClass(ImportFunction.class); verify(executor, times(1)) .importAndSwallowIOExceptions(eq(photoModel), importCapture.capture()); diff --git a/extensions/data-transfer/portability-data-transfer-backblaze/src/test/java/org/datatransferproject/datatransfer/backblaze/videos/BackblazeVideosImporterTest.java b/extensions/data-transfer/portability-data-transfer-backblaze/src/test/java/org/datatransferproject/datatransfer/backblaze/videos/BackblazeVideosImporterTest.java index 90d0ac634..def53b674 100644 --- a/extensions/data-transfer/portability-data-transfer-backblaze/src/test/java/org/datatransferproject/datatransfer/backblaze/videos/BackblazeVideosImporterTest.java +++ b/extensions/data-transfer/portability-data-transfer-backblaze/src/test/java/org/datatransferproject/datatransfer/backblaze/videos/BackblazeVideosImporterTest.java @@ -54,8 +54,7 @@ public class BackblazeVideosImporterTest { IdempotentImportExecutor executor; TokenSecretAuthData authData; BackblazeDataTransferClient client; - @TempDir - public Path folder; + @TempDir public Path folder; @BeforeEach public void setUp() { @@ -84,7 +83,7 @@ public void testNullVideos() throws Exception { BackblazeVideosImporter sut = new BackblazeVideosImporter(monitor, dataStore, streamProvider, clientFactory); ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, data); - assertEquals(ImportResult.OK, result); + assertEquals(ImportResult.ResultType.OK, result.getType()); } @Test @@ -95,7 +94,7 @@ public void testEmptyVideos() throws Exception { BackblazeVideosImporter sut = new BackblazeVideosImporter(monitor, dataStore, streamProvider, clientFactory); ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, data); - assertEquals(ImportResult.OK, result); + assertEquals(ImportResult.ResultType.OK, result.getType()); } @Test @@ -130,8 +129,8 @@ public void testImportVideo() throws Exception { new BackblazeVideosImporter(monitor, dataStore, streamProvider, clientFactory); sut.importItem(jobId, executor, authData, data); - ArgumentCaptor> importCapture = ArgumentCaptor.forClass( - ImportFunction.class); + ArgumentCaptor> importCapture = + ArgumentCaptor.forClass(ImportFunction.class); verify(executor, times(1)) .importAndSwallowIOExceptions(eq(videoObject), importCapture.capture()); diff --git a/extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/photos/KoofrPhotosImporter.java b/extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/photos/KoofrPhotosImporter.java index abc887f75..dcfab5e50 100644 --- a/extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/photos/KoofrPhotosImporter.java +++ b/extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/photos/KoofrPhotosImporter.java @@ -15,16 +15,16 @@ */ package org.datatransferproject.transfer.koofr.photos; -import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.HttpURLConnection; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.TimeZone; import java.util.UUID; +import java.util.concurrent.atomic.LongAdder; + import org.apache.commons.imaging.Imaging; import org.apache.commons.imaging.common.ImageMetadata; import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata; @@ -34,7 +34,9 @@ import org.datatransferproject.api.launcher.Monitor; import org.datatransferproject.spi.cloud.connection.ConnectionProvider; import org.datatransferproject.spi.cloud.storage.JobStore; +import org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper; import org.datatransferproject.spi.transfer.idempotentexecutor.IdempotentImportExecutor; +import org.datatransferproject.spi.transfer.idempotentexecutor.ItemImportResult; import org.datatransferproject.spi.transfer.provider.ImportResult; import org.datatransferproject.spi.transfer.provider.Importer; import org.datatransferproject.spi.transfer.types.DestinationMemoryFullException; @@ -103,13 +105,20 @@ public ImportResult importItem( album.getId(), album.getName(), () -> createAlbumFolder(album, koofrClient)); } + final LongAdder totalImportedFilesSizes = new LongAdder(); for (PhotoModel photoModel : resource.getPhotos()) { - idempotentImportExecutor.executeAndSwallowIOExceptions( - photoModel.getIdempotentId(), - photoModel.getTitle(), - () -> importSinglePhoto(photoModel, jobId, idempotentImportExecutor, koofrClient)); + idempotentImportExecutor.importAndSwallowIOExceptions( + photoModel, + photo -> { + ItemImportResult fileImportResult = + importSinglePhoto(photoModel, jobId, idempotentImportExecutor, koofrClient); + if (fileImportResult != null && fileImportResult.hasBytes()) { + totalImportedFilesSizes.add(fileImportResult.getBytes()); + } + return fileImportResult; + }); } - return ImportResult.OK; + return ImportResult.OK.copyWithBytes(totalImportedFilesSizes.longValue()); } private String createAlbumFolder(PhotoAlbum album, KoofrClient koofrClient) @@ -132,61 +141,89 @@ private String createAlbumFolder(PhotoAlbum album, KoofrClient koofrClient) return fullPath; } - private String importSinglePhoto( + private ItemImportResult importSinglePhoto( PhotoModel photo, UUID jobId, IdempotentImportExecutor idempotentImportExecutor, KoofrClient koofrClient) throws IOException, InvalidTokenException, DestinationMemoryFullException { monitor.debug(() -> String.format("Import single photo %s", photo.getTitle())); + Long size = null; + try { + InputStreamWrapper inputStreamWrapper = + connectionProvider.getInputStreamForItem(jobId, photo); + ItemImportResult response; - try (InputStream inputStream = - connectionProvider.getInputStreamForItem(jobId, photo).getStream()) { - final byte[] bytes = IOUtils.toByteArray(inputStream); - - Date dateCreated = getDateCreated(photo, bytes); - - String title = buildPhotoTitle(jobId, photo.getTitle(), dateCreated); - String description = KoofrClient.trimDescription(photo.getDescription()); - - String parentPath = idempotentImportExecutor.getCachedValue(photo.getAlbumId()); - String fullPath = parentPath + "/" + title; + try (InputStream inputStream = inputStreamWrapper.getStream()) { + final byte[] bytes = IOUtils.toByteArray(inputStream); - if (koofrClient.fileExists(fullPath)) { - monitor.debug(() -> String.format("Photo already exists %s", photo.getTitle())); + Date dateCreated = getDateCreated(photo, bytes); - return fullPath; - } + String title = buildPhotoTitle(jobId, photo.getTitle(), dateCreated); + String description = KoofrClient.trimDescription(photo.getDescription()); - final ByteArrayInputStream inMemoryInputStream = new ByteArrayInputStream(bytes); + String parentPath = idempotentImportExecutor.getCachedValue(photo.getAlbumId()); + String fullPath = parentPath + "/" + title; - String response; + if (koofrClient.fileExists(fullPath)) { + monitor.debug(() -> String.format("Photo already exists %s", photo.getTitle())); - try { - response = koofrClient.uploadFile( - parentPath, title, inMemoryInputStream, photo.getMediaType(), dateCreated, description); - } catch (KoofrClientIOException e) { - if (e.getCode() == 404) { - monitor.info(() -> String.format("Can't find album during importSingleItem for id: %s", photo.getDataId()), e); - response = "skipped-"+photo.getDataId(); + return ItemImportResult.success(fullPath); } - else { - throw e; + + final ByteArrayInputStream inMemoryInputStream = new ByteArrayInputStream(bytes); + + try { + long inputStreamBytes = inputStreamWrapper.getBytes(); + String stringResult = + koofrClient.uploadFile( + parentPath, + title, + inMemoryInputStream, + photo.getMediaType(), + dateCreated, + description); + if (stringResult != null && !stringResult.isEmpty()) { + response = ItemImportResult.success(stringResult, inputStreamBytes); + } else { + response = + ItemImportResult.success( + String.format(SKIPPED_FILE_RESULT_FORMAT, photo.getDataId())); + } + size = inputStreamBytes; + } catch (KoofrClientIOException exception) { + if (exception.getCode() == 404) { + monitor.info( + () -> + String.format( + "Can't find album during importSingleItem for id: %s", photo.getDataId()), + exception); + response = + ItemImportResult.success( + String.format(SKIPPED_FILE_RESULT_FORMAT, photo.getDataId())); + } else { + return ItemImportResult.error(exception, size); + } } - } - try { - if (photo.isInTempStore()) { - jobStore.removeData(jobId, photo.getFetchableUrl()); + try { + if (photo.isInTempStore()) { + jobStore.removeData(jobId, photo.getFetchableUrl()); + } + } catch (Exception e) { + // Swallow the exception caused by Remove data so that existing flows continue + monitor.info( + () -> + format( + "Exception swallowed while removing data for jobId %s, localPath %s", + jobId, photo.getFetchableUrl()), + e); } - } catch (Exception e) { - // Swallow the exception caused by Remove data so that existing flows continue - monitor.info( - () -> format("Exception swallowed while removing data for jobId %s, localPath %s", - jobId, photo.getFetchableUrl()), e); } return response; + } catch (KoofrClientIOException exception) { + return ItemImportResult.error(exception, size); } } diff --git a/extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/videos/KoofrVideosImporter.java b/extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/videos/KoofrVideosImporter.java index 3d0c44ad9..ba0236465 100644 --- a/extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/videos/KoofrVideosImporter.java +++ b/extensions/data-transfer/portability-data-transfer-koofr/src/main/java/org/datatransferproject/transfer/koofr/videos/KoofrVideosImporter.java @@ -19,10 +19,14 @@ import java.io.IOException; import java.io.InputStream; import java.util.UUID; +import java.util.concurrent.atomic.LongAdder; + import org.datatransferproject.api.launcher.Monitor; import org.datatransferproject.spi.cloud.connection.ConnectionProvider; import org.datatransferproject.spi.cloud.storage.JobStore; +import org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper; import org.datatransferproject.spi.transfer.idempotentexecutor.IdempotentImportExecutor; +import org.datatransferproject.spi.transfer.idempotentexecutor.ItemImportResult; import org.datatransferproject.spi.transfer.provider.ImportResult; import org.datatransferproject.spi.transfer.provider.Importer; import org.datatransferproject.spi.transfer.types.DestinationMemoryFullException; @@ -35,9 +39,7 @@ import org.datatransferproject.types.common.models.videos.VideosContainerResource; import org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData; -/** - * Imports videos and their albums to Koofr. - */ +/** Imports videos and their albums to Koofr. */ public class KoofrVideosImporter implements Importer { @@ -47,8 +49,8 @@ public class KoofrVideosImporter private final ConnectionProvider connectionProvider; private final Monitor monitor; - public KoofrVideosImporter(KoofrClientFactory koofrClientFactory, Monitor monitor, - JobStore jobStore) { + public KoofrVideosImporter( + KoofrClientFactory koofrClientFactory, Monitor monitor, JobStore jobStore) { this.koofrClientFactory = koofrClientFactory; this.connectionProvider = new ConnectionProvider(jobStore); this.monitor = monitor; @@ -77,19 +79,20 @@ public ImportResult importItem( album.getId(), album.getName(), () -> createAlbumFolder(album, koofrClient)); } + final LongAdder totalImportedFilesSizes = new LongAdder(); for (VideoModel videoModel : resource.getVideos()) { - String id; - if (videoModel.getAlbumId() == null) { - id = videoModel.getDataId(); - } else { - id = videoModel.getAlbumId() + "-" + videoModel.getDataId(); - } - idempotentImportExecutor.executeAndSwallowIOExceptions( - id, - videoModel.getName(), - () -> importSingleVideo(videoModel, jobId, idempotentImportExecutor, koofrClient)); + idempotentImportExecutor.importAndSwallowIOExceptions( + videoModel, + video -> { + ItemImportResult fileImportResult = + importSingleVideo(videoModel, jobId, idempotentImportExecutor, koofrClient); + if (fileImportResult != null && fileImportResult.hasBytes()) { + totalImportedFilesSizes.add(fileImportResult.getBytes()); + } + return fileImportResult; + }); } - return ImportResult.OK; + return ImportResult.OK.copyWithBytes(totalImportedFilesSizes.longValue()); } private String createAlbumFolder(VideoAlbum album, KoofrClient koofrClient) @@ -112,7 +115,7 @@ private String createAlbumFolder(VideoAlbum album, KoofrClient koofrClient) return fullPath; } - private String importSingleVideo( + private ItemImportResult importSingleVideo( VideoModel video, UUID jobId, IdempotentImportExecutor idempotentImportExecutor, @@ -120,37 +123,51 @@ private String importSingleVideo( throws IOException, InvalidTokenException, DestinationMemoryFullException { monitor.debug(() -> String.format("Import single video %s", video.getName())); - try (InputStream inputStream = - connectionProvider.getInputStreamForItem(jobId, video).getStream()) { - String parentPath; - if (video.getAlbumId() == null) { - parentPath = koofrClient.ensureVideosFolder(); - } else { - parentPath = idempotentImportExecutor.getCachedValue(video.getAlbumId()); - } - - String name = video.getName(); - String description = KoofrClient.trimDescription(video.getDescription()); - - String fullPath = parentPath + "/" + name; - - if (koofrClient.fileExists(fullPath)) { - monitor.debug(() -> String.format("Video already exists %s", video.getName())); - - return fullPath; + try { + InputStreamWrapper inputStreamWrapper = + connectionProvider.getInputStreamForItem(jobId, video); + ItemImportResult response; + try (InputStream inputStream = inputStreamWrapper.getStream()) { + String parentPath; + if (video.getAlbumId() == null) { + parentPath = koofrClient.ensureVideosFolder(); + } else { + parentPath = idempotentImportExecutor.getCachedValue(video.getAlbumId()); + } + + String name = video.getName(); + String description = KoofrClient.trimDescription(video.getDescription()); + + String fullPath = parentPath + "/" + name; + + if (koofrClient.fileExists(fullPath)) { + monitor.debug(() -> String.format("Video already exists %s", video.getName())); + + return ItemImportResult.success(fullPath); + } + + long inputStreamBytes = inputStreamWrapper.getBytes(); + String responseResult = + koofrClient.uploadFile( + parentPath, + name, + inputStream, + video.getEncodingFormat(), + video.getUploadedTime(), + description); + if (responseResult != null && !responseResult.isEmpty()) { + response = ItemImportResult.success(responseResult, inputStreamBytes); + } else { + response = + ItemImportResult.success( + String.format(SKIPPED_FILE_RESULT_FORMAT, video.getDataId())); + } } - - return koofrClient.uploadFile( - parentPath, - name, - inputStream, - video.getEncodingFormat(), - video.getUploadedTime(), - description); + return response; } catch (FileNotFoundException e) { monitor.info( - () -> String.format("Video resource was missing for id: %s", video.getDataId()), e); - return String.format(SKIPPED_FILE_RESULT_FORMAT, video.getDataId()); + () -> String.format("Video resource was missing for id: %s", video.getDataId()), e); + return ItemImportResult.success(String.format(SKIPPED_FILE_RESULT_FORMAT, video.getDataId())); } } } diff --git a/extensions/data-transfer/portability-data-transfer-koofr/src/test/java/org/datatransferproject/transfer/koofr/photos/KoofrPhotosImporterTest.java b/extensions/data-transfer/portability-data-transfer-koofr/src/test/java/org/datatransferproject/transfer/koofr/photos/KoofrPhotosImporterTest.java index bd5615ea8..7c26fc776 100644 --- a/extensions/data-transfer/portability-data-transfer-koofr/src/test/java/org/datatransferproject/transfer/koofr/photos/KoofrPhotosImporterTest.java +++ b/extensions/data-transfer/portability-data-transfer-koofr/src/test/java/org/datatransferproject/transfer/koofr/photos/KoofrPhotosImporterTest.java @@ -18,7 +18,6 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collection; -import java.util.Date; import java.util.TimeZone; import java.util.UUID; import java.util.concurrent.Callable; @@ -85,10 +84,11 @@ public void setUp() throws Exception { .then( (InvocationOnMock invocation) -> { Callable callable = invocation.getArgument(2); - String result = callable.call(); + var result = callable.call(); capturedResult.set(result); return result; }); + when(executor.importAndSwallowIOExceptions(any(), any())).thenCallRealMethod(); authData = new TokensAndUrlAuthData("acc", "refresh", ""); } @@ -382,13 +382,7 @@ public void testSkipNotFoundAlbum() throws Exception { Collection photos = ImmutableList.of( new PhotoModel( - "pic1.jpg", - "http://fake.com/1.jpg", - "A pic", - "image/jpeg", - "p1", - "id1", - true)); + "pic1.jpg", "http://fake.com/1.jpg", "A pic", "image/jpeg", "p1", "id1", true)); PhotosContainerResource resource = spy(new PhotosContainerResource(albums, photos)); importer.importItem(jobId, executor, authData, resource); diff --git a/extensions/data-transfer/portability-data-transfer-koofr/src/test/java/org/datatransferproject/transfer/koofr/videos/KoofrVideosImporterTest.java b/extensions/data-transfer/portability-data-transfer-koofr/src/test/java/org/datatransferproject/transfer/koofr/videos/KoofrVideosImporterTest.java index a03ee6f1f..5d2c0edc2 100644 --- a/extensions/data-transfer/portability-data-transfer-koofr/src/test/java/org/datatransferproject/transfer/koofr/videos/KoofrVideosImporterTest.java +++ b/extensions/data-transfer/portability-data-transfer-koofr/src/test/java/org/datatransferproject/transfer/koofr/videos/KoofrVideosImporterTest.java @@ -37,14 +37,10 @@ @ExtendWith(MockitoExtension.class) public class KoofrVideosImporterTest { - @Mock - private KoofrClientFactory clientFactory; - @Mock - private KoofrClient client; - @Mock - private Monitor monitor; - @Mock - private IdempotentImportExecutor executor; + @Mock private KoofrClientFactory clientFactory; + @Mock private KoofrClient client; + @Mock private Monitor monitor; + @Mock private IdempotentImportExecutor executor; private KoofrVideosImporter importer; private TokensAndUrlAuthData authData; private MockWebServer server; @@ -68,6 +64,7 @@ public void setUp() throws Exception { capturedResult.set(result); return result; }); + when(executor.importAndSwallowIOExceptions(any(), any())).thenCallRealMethod(); authData = new TokensAndUrlAuthData("acc", "refresh", ""); } @@ -234,16 +231,16 @@ public void testSkipNotFoundVideo() throws Exception { Collection albums = ImmutableList.of(); Collection videos = - ImmutableList.of( - new VideoModel( - "not_found_video_1.mp4", - server.url("/not_found.mp4").toString(), - "Video not founded in CDN", - "video/mp4", - "not_found_video_1", - null, - false, - null)); + ImmutableList.of( + new VideoModel( + "not_found_video_1.mp4", + server.url("/not_found.mp4").toString(), + "Video not founded in CDN", + "video/mp4", + "not_found_video_1", + null, + false, + null)); VideosContainerResource resource = spy(new VideosContainerResource(albums, videos));