DownloaderController extends DataBridgeController { private void logLocalDirectoryContents(File directory) { Collection<File> files = HerdFileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); LOGGER.info(String.format("Found %d files in \"%s\" target local directory:", files.size(), directory.getPath())); for (File file : files) { LOGGER.info(String.format(" %s", file.getPath())); } }  @SuppressFBWarnings(value = {"BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"}, justification = "manifestReader.readJsonManifest will always return an DownloaderInputManifestDto object. targetLocalDirectory.list().length will not" + " return a NullPointerException.") void performDownload(RegServerAccessParamsDto regServerAccessParamsDto, File manifestPath,
        S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto);  }
@Test public void testLogLocalDirectoryContents() throws Exception { String appenderName = "TestWriterAppender"; StringWriter stringWriter = addLoggingWriterAppender(appenderName); LogLevel originalLevel = getLogLevel(DownloaderController.class); setLogLevel(DownloaderController.class, LogLevel.INFO); DownloaderWebClient mockDownloaderWebClient = mock(DownloaderWebClient.class); DownloaderWebClient originalDownloaderWebClient = (DownloaderWebClient) ReflectionTestUtils.getField(downloaderController, "downloaderWebClient"); ReflectionTestUtils.setField(downloaderController, "downloaderWebClient", mockDownloaderWebClient); DownloaderManifestReader mockDownloaderManifestReader = mock(DownloaderManifestReader.class); DownloaderManifestReader originalDownloaderManifestReader = (DownloaderManifestReader) ReflectionTestUtils.getField(downloaderController, "manifestReader"); ReflectionTestUtils.setField(downloaderController, "manifestReader", mockDownloaderManifestReader); BusinessObjectDataHelper mockBusinessObjectDataHelper = mock(BusinessObjectDataHelper.class); BusinessObjectDataHelper originalBusinessObjectDataHelper = (BusinessObjectDataHelper) ReflectionTestUtils.getField(downloaderController, "businessObjectDataHelper"); ReflectionTestUtils.setField(downloaderController, "businessObjectDataHelper", mockBusinessObjectDataHelper); S3Service mockS3Service = mock(S3Service.class); S3Service originalS3Service = (S3Service) ReflectionTestUtils.getField(downloaderController, "s3Service"); ReflectionTestUtils.setField(downloaderController, "s3Service", mockS3Service); StorageFileHelper mockStorageFileHelper = mock(StorageFileHelper.class); StorageFileHelper originalStorageFileHelper = (StorageFileHelper) ReflectionTestUtils.getField(downloaderController, "storageFileHelper"); ReflectionTestUtils.setField(downloaderController, "storageFileHelper", mockStorageFileHelper); StorageHelper mockStorageHelper = mock(StorageHelper.class); StorageHelper originalStorageHelper = (StorageHelper) ReflectionTestUtils.getField(downloaderController, "storageHelper"); ReflectionTestUtils.setField(downloaderController, "storageHelper", mockStorageHelper); Path localPath = Files.createTempDirectory(null); try { String s3KeyPrefix = "s3KeyPrefix"; String storageName = "S3_MANAGED"; Path targetDirectoryPath = localPath.resolve(s3KeyPrefix); Path targetFilePath = targetDirectoryPath.resolve("file"); DownloaderInputManifestDto downloaderInputManifestDto = new DownloaderInputManifestDto(); BusinessObjectData businessObjectData = new BusinessObjectData(); StorageUnit storageUnit = new StorageUnit(new Storage(storageName, null, null), null, null, StorageUnitStatusEntity.ENABLED, null, null, null); S3KeyPrefixInformation s3KeyPrefixInformation = new S3KeyPrefixInformation(); s3KeyPrefixInformation.setS3KeyPrefix(s3KeyPrefix); when(mockDownloaderManifestReader.readJsonManifest(any())).thenReturn(downloaderInputManifestDto); when(mockDownloaderWebClient.getBusinessObjectData(any())).thenReturn(businessObjectData); when(mockBusinessObjectDataHelper.getStorageUnitByStorageName(any(), any())).thenReturn(storageUnit); when(mockDownloaderWebClient.getS3KeyPrefix(any())).thenReturn(s3KeyPrefixInformation); when(mockS3Service.downloadDirectory(any())).then(new Answer<S3FileTransferResultsDto>() { @Override public S3FileTransferResultsDto answer(InvocationOnMock invocation) throws Throwable { Files.createFile(targetFilePath); return null; } }); RegServerAccessParamsDto regServerAccessParamsDto = null; File manifestPath = null; S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto(); s3FileTransferRequestParamsDto.setLocalPath(localPath.toString()); s3FileTransferRequestParamsDto.setMaxThreads(1); downloaderController.performDownload(regServerAccessParamsDto, manifestPath, s3FileTransferRequestParamsDto); verify(mockDownloaderManifestReader).readJsonManifest(manifestPath); verify(mockDownloaderWebClient).getBusinessObjectData(downloaderInputManifestDto); verify(mockBusinessObjectDataHelper).getStorageUnitByStorageName(businessObjectData, storageName); verify(mockDownloaderWebClient).getS3KeyPrefix(businessObjectData); verify(mockS3Service).downloadDirectory(s3FileTransferRequestParamsDto); } finally { setLogLevel(DownloaderController.class, originalLevel); removeLoggingAppender(appenderName); ReflectionTestUtils.setField(downloaderController, "downloaderWebClient", originalDownloaderWebClient); ReflectionTestUtils.setField(downloaderController, "manifestReader", originalDownloaderManifestReader); ReflectionTestUtils.setField(downloaderController, "businessObjectDataHelper", originalBusinessObjectDataHelper); ReflectionTestUtils.setField(downloaderController, "s3Service", originalS3Service); ReflectionTestUtils.setField(downloaderController, "storageFileHelper", originalStorageFileHelper); ReflectionTestUtils.setField(downloaderController, "storageHelper", originalStorageHelper); FileUtils.deleteDirectory(localPath.toFile()); } }