Assert.hasText(manifestFile.getFileName(), "Manifest file can not have a blank filename."); manifestFile.setFileName(manifestFile.getFileName().trim()); if (manifestFile.getRowCount() != null) Assert.isTrue(manifestFile.getRowCount() >= 0, "Manifest file \"" + manifestFile.getFileName() + "\" can not have a negative row count.");
/** * Gets a list of manifest files from a list of file names. * * @param fileNames the list of file names. * @param fileSizeBytes the file size in bytes for each manifest file. * * @return the list of manifest files. */ protected List<ManifestFile> getManifestFilesFromFileNames(List<String> fileNames, long fileSizeBytes) { List<ManifestFile> manifestFiles = new ArrayList<>(); for (int i = 0; i < fileNames.size(); i++) { String fileName = fileNames.get(i); ManifestFile manifestFile = new ManifestFile(); manifestFiles.add(manifestFile); manifestFile.setFileName(fileName); manifestFile.setRowCount((long) i); manifestFile.setFileSizeBytes(fileSizeBytes); } return manifestFiles; }
/** * Creates local test data files in LOCAL_TEMP_PATH_INPUT directory. * * @param localPath the local path relative to which the test data files will be created * @param manifestFiles the list of the test data files */ protected void createTestDataFiles(Path localPath, List<ManifestFile> manifestFiles) throws Exception { // Create local test files. for (ManifestFile manifestFile : manifestFiles) { createLocalFile(localPath.toString(), manifestFile.getFileName(), manifestFile.getFileSizeBytes()); } }
for (String fileName : files) ManifestFile manifestFile = new ManifestFile(); returnManifestFiles.add(manifestFile); manifestFile.setFileName(fileName.trim());
storageFiles.add(storageFile); storageFile.setFilePath((s3KeyPrefix + manifestFile.getFileName()).replaceAll("\\\\", "/")); storageFile.setFileSizeBytes(Paths.get(localPath, manifestFile.getFileName()).toFile().length()); storageFile.setRowCount(manifestFile.getRowCount());
String realFullPathFileName = Paths.get(basedir, manifestFile.getFileName()).toFile().getPath(); realFullPathFileName = realFullPathFileName.replaceAll("\\\\", "/"); File realFile = new File(realFullPathFileName);
@Test public void testReadJsonManifestNoRowCount() throws IOException { // Get an instance of uploader input manifest object. UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); // Make all the row counts null. for (ManifestFile manifestFile : uploaderInputManifestDto.getManifestFiles()) { manifestFile.setRowCount(null); } // Create and read a uploaderInputManifestDto file. UploaderInputManifestDto resultManifest = uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); // Validate the results. assertUploaderManifest(uploaderInputManifestDto, resultManifest); }
storageFiles.add(storageFile); storageFile.setFilePath((s3KeyPrefix + manifestFile.getFileName()).replaceAll("\\\\", "/")); storageFile.setFileSizeBytes(Paths.get(localPath, manifestFile.getFileName()).toFile().length()); storageFile.setRowCount(manifestFile.getRowCount());
@Test(expected = IllegalArgumentException.class) public void testPerformUploadManifestContainsDuplicateFileNames() throws Exception { List<ManifestFile> duplicateTestDataFiles = new ArrayList<>(); duplicateTestDataFiles.addAll(testManifestFiles); duplicateTestDataFiles.add(testManifestFiles.get(0)); // Create local data files in LOCAL_TEMP_PATH_INPUT directory for (ManifestFile manifestFile : testManifestFiles) { createLocalFile(LOCAL_TEMP_PATH_INPUT.toString(), manifestFile.getFileName(), FILE_SIZE_1_KB); } // Create uploader input manifest file in LOCAL_TEMP_PATH_INPUT directory UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); uploaderInputManifestDto.setManifestFiles(duplicateTestDataFiles); File manifestFile = createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto); Assert.assertTrue(manifestFile.isFile()); // Try to upload business object data having duplicate file names. RegServerAccessParamsDto regServerAccessParamsDto = RegServerAccessParamsDto.builder().withRegServerHost(WEB_SERVICE_HOSTNAME).withRegServerPort(WEB_SERVICE_HTTPS_PORT).withUseSsl(true) .withUsername(WEB_SERVICE_HTTPS_USERNAME).withPassword(WEB_SERVICE_HTTPS_PASSWORD).build(); uploaderController.performUpload(regServerAccessParamsDto, manifestFile, getTestS3FileTransferRequestParamsDto(), false, false, TEST_RETRY_ATTEMPTS, TEST_RETRY_DELAY_SECS); }
List<ManifestFile> manifestFiles = new ArrayList<>(); ManifestFile manifestFile = new ManifestFile(); manifestFile.setFileName("testFileName"); manifestFile.setFileSizeBytes(1l); manifestFile.setRowCount(2l); manifestFiles.add(manifestFile);
@Test(expected = IllegalArgumentException.class) public void testPerformUploadManifestFileNameDoesNotMatchActualFileName() throws Exception { List<ManifestFile> declaredManifestFiles = getManifestFilesFromFileNames(Arrays.asList("test-data-1.txt", "test-data-2.txt"), FILE_SIZE_1_KB); List<ManifestFile> actualManifestFiles = getManifestFilesFromFileNames(Arrays.asList("test-data-1.txt", "TEST-DATA-2.TXT"), FILE_SIZE_1_KB); // Create local data files in LOCAL_TEMP_PATH_INPUT directory for (ManifestFile manifestFile : actualManifestFiles) { createLocalFile(LOCAL_TEMP_PATH_INPUT.toString(), manifestFile.getFileName(), FILE_SIZE_1_KB); } // Create uploader input manifest file in LOCAL_TEMP_PATH_INPUT directory. UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); uploaderInputManifestDto.setManifestFiles(declaredManifestFiles); File manifestFile = createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto); Assert.assertTrue(manifestFile.isFile()); // Try to upload business object data with one of the file having name that does not match to incorrect name specified. RegServerAccessParamsDto regServerAccessParamsDto = RegServerAccessParamsDto.builder().withRegServerHost(WEB_SERVICE_HOSTNAME).withRegServerPort(WEB_SERVICE_HTTPS_PORT).withUseSsl(true) .withUsername(WEB_SERVICE_HTTPS_USERNAME).withPassword(WEB_SERVICE_HTTPS_PASSWORD).build(); uploaderController.performUpload(regServerAccessParamsDto, manifestFile, getTestS3FileTransferRequestParamsDto(), false, false, TEST_RETRY_ATTEMPTS, TEST_RETRY_DELAY_SECS); }
ManifestFile manifestFile = new ManifestFile(); manifestFiles.add(manifestFile); manifestFile.setFileName(storageFile.getFilePath().replace(s3KeyPrefix, "")); manifestFile.setFileSizeBytes(storageFile.getFileSizeBytes()); manifestFile.setRowCount(storageFile.getRowCount());
createLocalFile(LOCAL_TEMP_PATH_INPUT.toString(), manifestFile.getFileName(), FILE_SIZE_1_KB);